Search code examples
opengl-esvertex-bufferopengl-es-1.1

Does glBindBuffer invalidate previous gl*Pointer calls?


I would like to work my code like this:

glVertexPointer( 3, GL_FLOAT, sizeof( Vertex ), (GLvoid*)offsetof( Vertex, Position ) );
glColorPointer( 4, GL_UNSIGNED_BYTE, sizeof( Vertex ), (GLvoid*)offsetof( Vertex, Color ) );

for ( /* each buffer */ )
{
    glBindBuffer( GL_VERTEX_ARRAY, buffer );
    glDrawArrays( GL_TRIANGLE_STRIP, 0, buffer_size );
}

Would this work?

Or do I need to call gl*Pointer for each buffer?


Solution

  • You must call glBindBuffer before calling glXYZPointer calls.

    OpenGL is a state machine. When you call glVertexPointer (or other gl..Pointer) it sets vertex pointer into currently bound buffer. glBindBuffer after Pointer call will do nothing (except it will influence next pointer calls).