draw a depth map

Hello,

in shadow mapping tutorials, you often see pictures of depth maps, these black/white images. How can such an image of a depth map be renderd? I suppose the depth values are simply interpreted as colors, but how is this done?

I need this for debugging purposes, my shadow map implementation does not work at all and I want to check everything, and checking that at least a valid depth map texture ist generated seems very important.

Thanks
Jan

I suspect I have missed something subtle here. If you have an n*m byte-deep depthmap, and you want to render it (this could mean many different things, btw), wouldn’t it be as simple as uploading it as a texture with either just one of R, G or B, or just GL_LUMINANCE, and then slapping it on a quad?

AFAIK you could even DrawPixels (again, pay attention to format) and forget about the texture.

Could it be that you have attempted to used an n*n byte-deep image as e.g. RGB?

You can use glRead/glDrawpixels or glCopyText(Sub)Image. This is what I use usually:

 
void CopyDepthToColor(float px, float py, float xscale,float yscale, bool copy_texture=false)
{
	GLint x,y,w,h;
	// state sichern
	glPushAttrib(	GL_COLOR_BUFFER_BIT|
					GL_CURRENT_BIT|
					GL_DEPTH_BUFFER_BIT|
					GL_ENABLE_BIT|
					GL_LIGHTING_BIT|
					GL_PIXEL_MODE_BIT);

	glDisable(GL_LIGHTING);
	glDisable(GL_TEXTURE_2D);
	glDisable(GL_DEPTH_TEST);				// immer rendern
	glDepthMask(GL_FALSE);
    glDisable(GL_STENCIL_TEST);
	glDisable(GL_CULL_FACE);

	GLUI_Master.get_viewport_area( &x, &y, &w, &h );

	glMatrixMode(GL_PROJECTION);
		glPushMatrix();
			glLoadIdentity();
			gluOrtho2D(0,w,0,h);	// matrix so dass objektkoordinaten == fensterkoordinaten

	glMatrixMode(GL_MODELVIEW);
		glPushMatrix();
			glLoadIdentity();
			if ( copy_texture)
			{		  
				glTexEnvi(GL_TEXTURE_ENV,GL_TEXTURE_ENV_MODE,GL_REPLACE);
				
				glBindTexture(GL_TEXTURE_RECTANGLE_NV,depth_texture);
				glEnable(GL_TEXTURE_RECTANGLE_NV);
				
				// depthbuffer in Textur kopieren
				glRasterPos2f(px,py);
				glCopyTexImage2D(GL_TEXTURE_RECTANGLE_NV,0,GL_DEPTH_COMPONENT24_ARB,x,y,w,h,0);
				
				

				// Texturkoordinaten für TEXTURE_RECTANGLE Texturenm gehen von (0|0) bis (w|h) 
				// und nicht von (0|0) bis (1|1)
				
				glBegin(GL_QUADS);
            		glTexCoord2f(0.0f,0.0f);	glVertex2f(0.0f,			0.0f);
					glTexCoord2f(w,0.0f);		glVertex2f(float(w)*xscale,	0.0f);
					glTexCoord2f(w,h);			glVertex2f(float(w)*xscale,	float(h)*yscale);
					glTexCoord2f(0.0f,h);		glVertex2f(0.0f,			float(h)*yscale);
				glEnd();

				glTexEnvi(GL_TEXTURE_ENV,GL_TEXTURE_ENV_MODE,GL_MODULATE);
				glDisable(GL_TEXTURE_RECTANGLE_NV);

			}
			else
			{
				glPixelZoom(xscale,yscale);
				glRasterPos2f(px,py);
				if(live_use_copy_ext && ext_copy_depth_to_color)
				{
					glCopyPixels(x+px,y+py,w,h,GL_DEPTH_STENCIL_TO_RGBA_NV);
					CheckGLErrors();
				}
				else
				{
					glReadPixels(x,y,w,h,GL_DEPTH_COMPONENT ,GL_UNSIGNED_INT,depth_pixels);
					glDrawPixels(w,h,GL_LUMINANCE,GL_UNSIGNED_INT,depth_pixels);

				}
			}
		glPopMatrix();
	
	glMatrixMode(GL_PROJECTION);
		glPopMatrix();

	glMatrixMode(GL_MODELVIEW);

		
	glPopAttrib();			// state wiederherstellen
	

} 

When you render with DEPTH_COMPONENT textures with the comparison turned off, it behaves like an INTENSITY texture.

You shouldn’t need to ReadPixels()/TexImage() to debug.