Why is the sprite not rendering in OpenGL?

前端 未结 1 1649
夕颜
夕颜 2020-12-02 02:14

I am trying to render a 2D(Screen coordinated) sprite in OpenGL. Yet, when I compile it, it does not show up. I see that the code is fine (There are not even any shader comp

相关标签:
1条回答
  • 2020-12-02 02:59

    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
    
    0 讨论(0)
提交回复
热议问题