void init( void ) { . . . /* Do all your standard initialization stuff */ . . . /* Generate a texture to hold your depth map, when you copy it */ glGenTextures(1, &myDepthTexID); glBindTexture(GL_TEXTURE_2D, myDepthTexID); glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameteri( GL_TEXTURE_2D, GL_DEPTH_TEXTURE_MODE, GL_LUMINANCE ); glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT, windowWidth, windowHeight GL_DEPTH_COMPONENT, GL_FLOAT, NULL); } void display ( void ) { /* get ready to draw from the light */ glClear( GL_COLOR_BUFFER_BIT | GL_DEPHT_BUFFER_BIT ); glLoadIdentity(); gluLookAt( << the view from the light >> ); . . . /* put your code to draw your shadow map here */ . . . . /* copy your depth map into a texture */ glBindTexture( GL_TEXTURE_2D, myDepthTexID ); glCopyTexSubImage2D( GL_TEXTURE_2D, 0, 0, 0, 0, 0, windowWidth, windowHeight ); /* get ready to draw from the eye */ glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT ); glLoadIdentity(); gluLookAt( << the view from the eye >> ); . . . /* put your code to draw your scene from the eye's view here */ . . . /* draw shadow map in the lower right corner */ DrawTextureInLowerRightCorner( myDepthTexID ); /* finish your display routine here */ glutSwapBuffers(); } void DrawTextureInLowerRightCorner( GLuint textureID ) { /* code to draw a texture in the lower right corner of the screen */ glPushAttrib( GL_ALL_ATTRIB_BITS ); // Save OpenGL state on a stack glDisable( GL_DEPTH_TEST ); glMatrixMode(GL_PROJECTION); // we're setting up a new, 2D, projection matrix glPushMatrix(); glLoadIdentity(); gluOrtho2D( 0, 1, 0, 1 ); // Let the screen go from [0..1] in both x, y glMatrixMode(GL_MODELVIEW); glPushMatrix(); glLoadIdentity(); // No special modelview matrix for this part glDisable(GL_LIGHTING); // Don't want lighting on our corner display glEnable(GL_TEXTURE_2D); // But it *is* a texture glTexEnvi( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE ); // We just want to draw on the quad glBindTexture( GL_TEXTURE_2D, textureID ); // This is the texture we want to display glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_COMPARE_MODE, // Just draw it, nothing more complex. If using a GL_NONE ); // normal texture (not depth map), this isn't necessary glColor3f(1,1,1); glBegin(GL_QUADS); // Draw a texture in the lower right corner glTexCoord2f( 0, 0 ); glVertex2f( 0.8, 0 ); // ranging from (0.8,0.2) down to (1.0,0.0) glTexCoord2f( 1, 0 ); glVertex2f( 1.0, 0 ); glTexCoord2f( 1, 1 ); glVertex2f( 1.0, 0.2 ); glTexCoord2f( 0, 1 ); glVertex2f( 0.8, 0.2 ); glEnd(); glMatrixMode(GL_PROJECTION); // reset our matrices to how we found them glPopMatrix(); glMatrixMode(GL_MODELVIEW); glPopMatrix(); glPopAttrib( ); // reset (most of) the OpenGL state to how we found it }