depth & texture

Hi, i would like to know how I could transform my depth texture in a rgba texture to render it in grayscale on screen. Here is a part of my code :

glGenTextures(1, &shadowMapTexture);
glBindTexture(GL_TEXTURE_2D, shadowMapTexture);
glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT, 512, 512, 0,GL_DEPTH_COMPONENT, GL_UNSIGNED_BYTE, NULL);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
...
DrawScene();
//get zbuffer in a texture
glBindTexture(GL_TEXTURE_2D, shadowMapTexture);
glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, 512, 512);
...
//Square to render the depth map in grayscale
glBegin(GL_QUADS);
glTexCoord2d(0.0,0.0);
glVertex2i(0,0);
glTexCoord2d(0.0,1.0);
glVertex2i(0,512);
glTexCoord2d(1.0,1.0);
glVertex2i(512,512);
glTexCoord2d(1.0,0.0);
glVertex2i(512,0);
glEnd();
...
 

thanks

Assuming you haven’t changed any state for the texture(specifically DEPTH_TEXTURE_MODE_ARB), its state should be LUMINANCE, which should yield a greyscale image.

see http://oss.sgi.com/projects/ogl-sample/registry/ARB/depth_texture.txt,
issue (3),
or the spec, sec.

thanks a lot, glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, 512, 512); was just at the wrong place in my code :wink: