glIndexPointer(GL_INT, 0, (GLvoid*)((char*)NULL));
Never call glIndexPointer
. It absolutely does not do what you think it does. That’s not your problem, but you shouldn’t be calling it.
In any case, your problem is that you’re not quite understanding how buffer objects work with vertex data.
This:
glGenBuffer(1, &vertexBufferID);
glBindBuffer(GL_ARRAY_BUFFER, vertexBufferID);
glBufferData(GL_ARRAY_BUFFER, numVertex * 3 * sizeof(float), vertexBuffer, GL_STREAM_DRAW);
is an example of how to create a buffer object (though unless you are actually streaming vertex data, which you aren’t, you shouldn’t be using GL_STREAM_DRAW. You should use GL_STATIC_DRAW). You create the buffer object, allocate a particular size, and copy some data into it. All well and good.
The problem is what you do next.
glVertexPointer(3, GL_FLOAT, 0, (GLvoid*)((char*)NULL));
glEnableClientState(GL_VERTEX_ARRAY);
This is the correct code, but it shouldn’t be here. This is not initialization-time code. This is code you use to draw with a particular buffer object.
See, because of legacy BS of the API, how you render with buffer objects is slightly convoluted. The buffer you bind to GL_ARRAY_BUFFER does not get used for rendering. To specify how to render data from a buffer object, you need two things: the buffer object itself, and the vertex format. The latter is provided by glVertexPointer
for position data, coupled with glEnableClientState(GL_VERTEX_ARRAY)
.
So, when it comes time to draw, you have to provide both the buffer object and its format. So the above code isn’t initialization code; it is rendering code:
glBindBuffer(GL_ARRAY_BUFFER, vertexBufferID);
glVertexPointer(3, GL_FLOAT, 0, (GLvoid*)((char*)NULL));
glEnableClientState(GL_VERTEX_ARRAY);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, indexBufferID);
glDrawElements(GL_TRIANGLE_STRIP, numIndexElements, GL_UNSIGNED_INT, (GLvoid*)((char*)NULL));