Display List Confusion

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!

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.

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!

Are you, by any chance, calling init before glutCreateWindow? Do nr and nc already contain the correct values in init?

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!

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!

Because you’re not allowed to use any OpenGL functions without a valid OpenGL context. GLUT creates this context alongside the window in glutCreateWindow.