PDA

View Full Version : Display List Confusion



ToddAtWSU
05-13-2006, 01:00 PM
I am having some problems with display lists. I have used them before with no problem, but now I am having some problems. I am trying to draw an object in a wireframe form with GL_LINE_STRIPS. Here is my different code snippets.

In init( )

wireframe = glGenLists( 1 );
glNewList( wireframe, GL_COMPILE );
drawWireFrame( );
glEndList( ); drawWireFrame( )

void drawWireFrame( )
{
float v[3][3];
float normal[3];
int x;
int y;

for( y = 0 ; y < ( nr - 1 ) ; y++ )
{
for( x = 0 ; x < ( nc - 1 ) ; x++ )
{
v[0][0] = x - 1;
v[0][1] = y - 1;
v[0][2] = image[y * nc + x];
v[1][0] = x - 1;
v[1][1] = y + 1 - 1;
v[1][2] = image[( y + 1 ) * nc + x];
v[2][0] = x + 1 - 1;
v[2][1] = y - 1;
v[2][2] = image[y * nc + ( x + 1 )];

calcNormal( v, normal );
glBegin( GL_LINE_STRIP );
glNormal3fv( normal );
glVertex3fv( v[0] );
glVertex3fv( v[1] );
glVertex3fv( v[2] );
glVertex3fv( v[0] );
glEnd( );

v[0][0] = x - 1;
v[0][1] = y + 1 - 1;
v[0][2] = image[( y + 1 ) * nc + x];
v[1][0] = x + 1 - 1;
v[1][1] = y - 1;
v[1][2] = image[y * nc + ( x + 1 )];
v[2][0] = x + 1 - 1;
v[2][1] = y + 1 - 1;
v[2][2] = image[( y + 1 ) * nc + ( x + 1 )];

calcNormal( v, normal );
glBegin( GL_LINE_STRIP );
glNormal3fv( normal );
glVertex3fv( v[0] );
glVertex3fv( v[1] );
glVertex3fv( v[2] );
glVertex3fv( v[0] );
glEnd( );
}
}
} In display( )

void display( )
{
glPushMatrix( );
//glRotated(alpha,0.0,1.0,0.0);
//glScaled(scale, scale, scale);
glCallList( wireframe );
glPopMatrix( );

glutSwapBuffers( );
} I plan to implement the rotation and scaling later, but right now I cannot get my object to draw. However, if I replace the code inside drawWireFrame and place it directly into the display function, it will draw correctly for me. Why will directly accessing the code display the image, but calling the display list will not work? Am I not compiling it correctly or something? Thanks!

Joe the Programmer
05-13-2006, 08:54 PM
Are you using any other display lists in your code? If so, that would likely be the problem. If the drawing code works like you said when not in display list form, that is most likely the problem. For example, if you make another display list beforehand, then the next display list = previous+1.

ToddAtWSU
05-13-2006, 09:22 PM
This is the only display list so far. I wanted to make a second one to hold my image as polygons instead of LINE_SEGMENTS, but wanted to get one working before trying another. I want to use display lists since it would be more efficient but am confused why they will not work. Thanks again!

memfr0b
05-14-2006, 02:11 AM
Are you, by any chance, calling init before glutCreateWindow? Do nr and nc already contain the correct values in init?

ToddAtWSU
05-14-2006, 07:59 AM
I am calling init before glutCreateWindow, but nr and nc are being calculated before I create my display list. Does creating the window after the list have anything to do with it even though nr and nc are valid? Thanks!

ToddAtWSU
05-14-2006, 08:02 AM
I just messed with it a little and it dies appear that putting init after the window creation fixed it. Why is this? Thanks again!

memfr0b
05-14-2006, 10:43 AM
Because you're not allowed to use any OpenGL functions without a valid OpenGL context. GLUT creates this context alongside the window in glutCreateWindow.