Hello –
I want to render a pass, storing the the resulting color and depth to texture maps for subsequent compositing with things that are drawn in the framebuffer later. I’m using an NVidia QuadroFX 500 in Linux (latest driver, 44.96).
In short the problem I’m having is that when I read the depth texture the image is completely white. I’ve used glReadPixels to examine the contents of the depth buffer more closely and the result is the same - the values are all 1.0. At this point I’m trying to just store the depth as a texture and then rendering it as luminance so I can see what’s inside the depth buffer. Storing the color buffer doesn’t seem to be a problem.
Here’s what my code looks like:
unsigned int m_width = 1024, m_height = 768;
GLuint ztex,ctex;void init()
{
glGenTextures(1,&ztex);
glBindTexture(GL_TEXTURE_RECTANGLE_NV,ztex);
glTexImage2D(GL_TEXTURE_RECTANAGLE_NV,0,GL_DEPTH_COMPONENT,m_width,m_height,0,GL_DEPTH_COMPONENT,GL_UNSIGNED_INT,0);glGenTextures(1,&ctex);
glBindTexture(GL_TEXTURE_RECTANGLE_NV,ctex);
glTexImage2D(GL_TEXTURE_RECTANGLE_NV,0,GL_RGBA,m_width,m_height,0,GL_RGBA,GL_UNSIGNED_BYTE,0);
}void render_pass()
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
draw_scene();// store depth
glBindTexture(GL_TEXTURE_RECTANGLE_NV,ztex);
glCopyTexSubImage2D(GL_TEXTURE_RECTANGLE_NV,0, 0,0,0,0, m_width,m_height);// store color
glBindTexture(GL_TEXTURE_RECTANGLE_NV,ctex);
glCopyTexSubImage2d(GL_TEXTURE_RECTANGLE_NV,0, 0,0,0,0, m_width,m_height);glBindTexture(GL_TEXTURE_RECTANGLE_NV,0);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
}void composite()
{
setup_ortho_view();
glDisable(GL_DEPTH_TEST);glEnable(GL_TEXTURE_RECTANGLE_NV);
glBindTexture(GL_TEXTURE_RECTANGLE_NV,ztex);glBegin(GL_QUADS);
glTexCoord2f(0,0);
glVertex2f(0,0);glTexCoord2f(m_width,0);
glVertex2f(m_width,0);glTexCoord2f(m_width,m_height);
glVertex2f(m_width,m_height);glTexCoord2f(0,m_height);
glVertex2f(0,m_height);
glEnd();
}void frame_function()
{
render_pass();
composite();
}
I’m expecing at this point that the quad will display a greyscale depth map, but instead it’s all white. If I draw the color map texture on the quad, then I see the image that was created in render_pass() without any problem. It’s my intention to use a fragment program to compare the depth texture with the framebuffer depth to do the compositing.
I’ve used a program similar to this to do depth map shadows in the past and didn’t have any problems, so it seemed like in that cast the depth buffer was being read fine.
thanks for any help!
- Alex
[This message has been edited by abetts (edited 10-24-2003).]