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!