glDrawElements crash (OpenGL 3.2 / Windows 7)

后端 未结 2 681
小鲜肉
小鲜肉 2021-01-03 07:26

I\'m trying to draw a simple quad in OpenGL 3.2 however the application crashes with \"Access violation reading location 0x00000000\" when I call \"glDrawElements\".

2条回答
  •  独厮守ぢ
    2021-01-03 07:57

    You are not allocating enough space for your vertices in your call to glBufferData. You pass sizeof(TexColorVertex) which allocates space for 1 vertex. If you want to draw a quad then you need to allocate space for 4 vertices so you should change your call to glBuffer Data as follows:

    glBufferData(GL_ARRAY_BUFFER, 4*sizeof(TexColorVertex), NULL, GL_DYNAMIC_DRAW);
    

    That way when you make your subsequent calls to glBufferSubData you will not be attempting to access GPU memory that is out of range.

提交回复
热议问题