Creating a texture from the zbuffer

Hi, not sure whether to post this in the beginnners or advanced forum so thought I would start here.

I am trying to display the z buffer as a texture in the upper right corner of the screen. The following code seems to always give me a pure white texture. I should be getting a texture that shows the rendered scene in grayscale, kind of. I have a geforce 3. Anyone know what I am doing wrong? Is there a rendering state I need to change before displaying the texture or is there something I need to do before copying the z buffer to a texture?

Render(); //renders lots of objects

//texture has already been setup as
//GL_DEPTH_COMPONENT
//like this
//glCopyTexImage2D( GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT, 0, 0, 256, 256, 0 );
glBindTexture( GL_TEXTURE_2D, iTexture );
glCopyTexSubImage2D( GL_TEXTURE_2D, 0, 0, 0, 0, 0, 256, 256 );

glViewport( 640 - 256, 480 - 256, 256, 256 );

glMatrixMode( GL_PROJECTION );
glLoadIdentity();

glMatrixMode( GL_MODELVIEW );
glLoadIdentity();

glDisable( GL_LIGHTING );
glDisable( GL_CULL_FACE );
glEnable( GL_TEXTURE_2D );

glBegin( GL_QUADS );
glColor4f( 1.0f, 1.0f, 1.0f, 1.0f );

glTexCoord2f( 0.0f, 0.0f );
glVertex2f( -1.0f, -1.0f );

glTexCoord2f( 1.0f, 0.0f );
glVertex2f( 1.0f, -1.0f );

glTexCoord2f( 1.0f, 1.0f );
glVertex2f( 1.0f, 1.0f );

glTexCoord2f( 0.0f, 1.0f );
glVertex2f( -1.0f, 1.0f );
glEnd();

KC

Well, i didn’t look at your code precisely but you need to resample the data you get from the glReadPixel since the depth values are NOT rgb related. Here a snip from my own code (that works) to save a depth buffer bitmap :

  glReadPixels(0, 0, gameInfo.screenwidth, gameInfo.screenheight, _GL_FORMAT, _GL_TYPE, p_depth_in);

  // Resample depth values in order to use full [0.0 .. 1.0] range
  {
  	// Research min and max depth values
  	min_depth = 1.0f;
  	max_depth = 0.0f;
  	p_depth = p_depth_in;

  	for (i = 0 ; i < nb_pixels ; i++, p_depth++) {
  		if (min_depth > *p_depth) {
  			min_depth = *p_depth;
  		}
  		if (max_depth < *p_depth) {
  			max_depth = *p_depth;
  		}
  	}

  	// Resample factor : stretch
  	depth_factor = 1.0f / (max_depth - min_depth);
  	p_depth = p_depth_in;

  	// Resampling....
  	for (i = 0 ; i < nb_pixels ; i++, p_depth++) {
  		*p_depth -= min_depth;
  		*p_depth *= depth_factor;
  		*p_depth *= 255.0f;
  	}
  }