Why is the sprite not rendering in OpenGL?

You have to initialize the model matrix variable glm::mat4 model.

The glm API documentation refers to The OpenGL Shading Language specification 4.20.

5.4.2 Vector and Matrix Constructors

If there is a single scalar parameter to a vector constructor, it is used to initialize all components of the constructed vector to that scalar’s value. If there is a single scalar parameter to a matrix constructor, it is used to initialize all the components on the matrix’s diagonal, with the remaining components initialized to 0.0.

This means, that an identity matrix can be initialized by the single parameter 1.0:

glm::mat4 model(1.0f);

Further your sprite is very small and it is out of the viewport (clip space) at the left side:

Change your code like this:

glm::vec2 position = glm::vec2(10.0f, 10.0f); // 10.0f instead of -10.0f

Leave a Comment