Drawing VBO with glDrawArrays works in OpenGL 2.1, but not in OpenGL 3.x

Code core (displaying a red rectangle):

//bind program, set uniforms, bind vbo glEnableVertexAttribArray(0); glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0,0); glDrawArrays(GL_TRIANGLES, 0, 6); glDisableVertexAttribArray(0); //unbind vbo, unbind program 

When I switch the context to OpenGL 3.x, this code stops working (I see only the background color), but when I initialize VAO in the same way as the code above, and then I bind VAO and call glDrawArrays, then it works.

What could be the problem? How can I draw a VBO without using a VAO?

(shaders are really simple, vs only mulitplies matrices and ps outputs are red)

+8
opengl opengl-3 vbo
source share
1 answer

Let's look at the OpenGL-3-core specification:

Section 2.10

First paragraph:

Buffer objects to be used at the vertex stage GL assembled together to form a vertex array object. All state associated with the definition of the data used by the vertex is the processor is encapsulated in the vertex of the array object.

The last paragraph:

INVALID OPERATION error if any of the * command pointers determine the location and organization of the vertex array data while zero is associated with the ARRAY BUFFER point buffer binding, and the pointer argument is not NULL³.

And in the footnote:

This error makes it impossible to create a vertex array object containing pointers to the client array, while at the same time allowing to free buffer objects.

Or in other words: in OpenGL-3-core you should use VAO

+7
source share

All Articles