Each example I found to display array data is similar to the following code, in which in the drawing loop you first call glEnableClientState for what you will use, and when you finish, you call glDisableClientState:
void drawScene(void) { glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT); glEnableClientState(GL_VERTEX_ARRAY); glEnableClientState(GL_TEXTURE_COORD_ARRAY); glBindTexture(GL_TEXTURE_2D, texturePointerA); glTexCoordPointer(2, GL_FLOAT, 0,textureCoordA); glVertexPointer(3, GL_FLOAT, 0, verticesA); glDrawElements(GL_QUADS, numPointsDrawnA, GL_UNSIGNED_BYTE, drawIndicesA); glBindTexture(GL_TEXTURE_2D, texturePointerB); glTexCoordPointer(2, GL_FLOAT, 0,textureCoordB); glVertexPointer(3, GL_FLOAT, 0, verticesB); glDrawElements(GL_QUADS, numPointsDrawnB, GL_UNSIGNED_BYTE, drawIndicesB); glDisableClientState(GL_TEXTURE_COORD_ARRAY); glDisableClientState(GL_VERTEX_ARRAY); }
In my program, I always use texture coordinates and vertex arrays, so I thought it was pointless to keep turning them on and off in every frame. I moved glEnableClientState outside of the loop like this:
bool initGL(void) {
Everything seems to be fine. My question is:
I need to call gldisableClientState somewhere; perhaps when the program is closed?
Also, is it good to do so? Is there something that I am missing as everyone else allows and disables each frame?
source share