Every example I've come across for rendering array data is similar to the following code, in which in your drawing loop you first call glEnableClientState for what you will be using and when you are done 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 am always using texture coordinates and vertex arrays, so I thought it was pointless to keep enabling and disabling them every frame. I moved the glEnableClientState outside of the loop like so:
bool initGL(void) {
//...
glEnableClientState(GL_VERTEX_ARRAY);
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
}
void drawScene(void) {
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
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);
}
It seems to work fine. My question is:
Do I need to call glDisableClientState somewhere; perhaps when the program is closed?.
Also, is it ok to do it like this? Is there something I'm missing since everyone else enables and disables each frame?