tags:

views:

45

answers:

1

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
+3  A: 

You're almost there, you just need first to call glGenLists() to generate a contiguous set of empty display lists.

GLuint listID;
listID = glGenLists( 1 ); // generate 1 display list
glNewList( listID, GL_COMPILE );
// whatever you want in the display list
glEndList();

// call the display list
glCallList( listID );

You should also do some error checking to make sure glGenLists() returned a valid display list.

jay.lee
glGenLists is an optional call. You can arbitrarily create names yourself (one of the "interesting" features of the initial GL object model). It's up to you to make sure you don't overuse it though. That said, since we don't see what the value skybox is, it's still a relevant comment.
Bahbar
I forgot to include the glGenList call in my question, but I made that call globally. I edited my post to include the exact line of code. Still getting the same result (haven't changed anything).
prelic
@Bahbar I did not know that. So when `glGenLists()` is called, is it basically just saying "here are some IDs that are guaranteed not to be in use" ?
jay.lee
Yep, exactly. There are a number of the glGen* methods that are specified like that. Oh, and I would not recommend relying on this feature either, because it forces the GL implementation to change its allocation scheme for the handle->object mapping.
Bahbar