Hey all,
First of all, as usual, thanks to all for the great support from the SO community.
So I wrote code to draw 6 gl_quads (to form a cube). Initially, this code was drawn immediately (explicitly made 24 vertex calls in the display function). I'd like to put these in a display list. I read a tutorial about display lists, and gave it a shot. Problem is, nothing is showing up, and I have a glulookat that definitely points in the direction of the cube (verified in immediate mode). So basically the code works perfectly when not using display lists, but doesn't when I try to use the list.
Ok, enough of that, let's have a look at the code:
2nd EDIT- Moved glGenLists call into initGl and it works fine. Thanks all
*EDIT-*The glGenList call is made globally:
GLuint skybox = glGenLists(1);
And I'm still getting the same result. Nothing is rendering to the screen.
Setup the list (in initgl function):
glViewport(0,0,WINDOW_WIDTH,WINDOW_HEIGHT);
glEnable(GL_DEPTH_TEST); // Enables Depth Testing
glDepthFunc(GL_LEQUAL);
glMatrixMode(GL_PROJECTION); //setup the projection matrix
glLoadIdentity();
gluPerspective(45, WINDOW_WIDTH/WINDOW_HEIGHT,.1,200.0);
glMatrixMode(GL_MODELVIEW); //switch to modelview
glLoadIdentity();
gluLookAt(-2,2,2,0,0,0,0,1,0);
glClearColor(0, 0, 0, 0);
glNewList(skybox, GL_COMPILE_AND_EXECUTE); //draw the list once to compile/store
drawEnv(); //draw 6 quads
glEndList(); //end list
display function (irrelevant code ommitted):
/* Clear buffers */
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
//-----Draw Skybox------
glEnable(GL_TEXTURE_2D);
glPushMatrix(); //save env settings (I've tried removing this push/pop pair with same results
glCallList(skybox);
glPopMatrix();
glDisable(GL_TEXTURE_2D);
And the drawEnv() function:
//---------------------------
//--------RIGHT WALL---------
//---------------------------
//This code draws correctly if I move this to the display function (immediate drawing)
glBindTexture(GL_TEXTURE_2D,rightTextureId);
glBegin(GL_QUADS);
glTexCoord2f(0.0, 0.0); glVertex3f( 1.0f, 1.0f, 1.0f); //V2
glTexCoord2f(0.0, 1.0); glVertex3f( 1.0f,-1.0f, 1.0f); //V1
glTexCoord2f(1.0, 1.0); glVertex3f( 1.0f,-1.0f,-1.0f); //V3
glTexCoord2f(1.0, 0.0); glVertex3f( 1.0f, 1.0f,-1.0f); //V4
glEnd();
//repeat 5 more times