I\'m trying to take my code to the next level. Following some best practices from Apple, I\'m trying to implement Vertex Array Objects around my Vertex Buffer Objects (VBO).
Remove glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
from the end of your setup function.
Per the specification for OES_vertex_array_object, a vertex array object encapsulates all state except the array buffer binding1, so there is no element buffer bound at the time that you’re drawing, whereas you presumably wanted indexBuffer
to be bound. By leaving indexBuffer
bound at the time that you bind away from your vertex array object, you ensure that it’ll be rebound when you return to that vertex array object.
1 If you’re wondering why the array buffer binding isn’t tracked in vertex array objects, this is presumably because the currently-bound array buffer isn’t used directly when reading vertex data from arrays—rather, each vertex attribute has its own buffer binding, which is filled out by its respective gl*Pointer
function by looking at the array buffer binding when the function is called.