The core of code (displaying red rectangle):
//bind program, set uniforms, bind vbo
glEnableVertexAttribArray(0);
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0,0);
glDrawArrays(GL_TRIANGLES, 0, 6);
glDis开发者_如何学PythonableVertexAttribArray(0);
//unbind vbo, unbind program
When I switch context to OpenGL 3.x this code stops to work (I can see only color of background), but when I'm initializing VAO in the same way as the code above and then I'm binding VAO and calling glDrawArrays, then it works.
What could be the problem? How can I draw VBO without use of VAO?
(shaders are really simple, vs only mulitplies matrices and ps outputs red color)
Let's have a look in the OpenGL-3-core spec:
Section 2.10
First paragraph:
The buffer objects that are to be used by the vertex stage of the GL are collected together to form a vertex array object. All state related to the definition of data used by the vertex processor is encapsulated in a vertex array object.
Last paragraph:
An INVALID OPERATION error is generated if any of the *Pointer commands specifying the location and organization of vertex array data are called while zero is bound to the ARRAY BUFFER buffer object binding point, and the pointer argument is not NULL³.
And in the ³ footnote:
This error makes it impossible to create a vertex array object containing client array pointers, while still allowing buffer objects to be unbound.
Or in other words: In OpenGL-3-core you must use VAOs
精彩评论