Jump to content
  • Advertisement
Sign in to follow this  
Oculus_Malus

OpenGL Depth buffer texture

This topic is 4618 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi, I've been looking for a way to get the depth buffer data as a texture to display. It seem that it isn't covered in my version of the red book neither on the opengl.org website. So far I have gathered lots of exemples from various applications and that's what I came up with. Texture initialization :
  glGenTextures(1, @T);
  glBindTexture(GL_TEXTURE_2D, T);
  glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT, 256, 256, 0, GL_DEPTH_COMPONENT, GL_UNSIGNED_BYTE, nil);
  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER,GL_NEAREST);
  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER,GL_NEAREST);
  glTexParameteri(GL_TEXTURE_2D, GL_DEPTH_TEXTURE_MODE, GL_LUMINANCE);
  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_MODE, GL_NONE);

After the actual scene is rendered (and before the gui) :
  glfinish;
  glBindTexture(GL_TEXTURE_2D, T);
  glCopyTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT, 0, 0, 256, 256, 0);

Unfortunatly, it dosen't work. The texture is filled with white. Is there some specific extensions that I need to enable before using it ? or an extra twist of code that I missed somewhere? Thank you.

Share this post


Link to post
Share on other sites
Advertisement
it should work
A/ is the texture a depth texture to begin with, eg youre not trying to write into a RGBA texture
B/ make the near clip plane high eg near=100, far=500 + try it again

depth values are typically very high thus 0.99 will look like white

Share this post


Link to post
Share on other sites
I have never done it, but have you tried to change the read buffer? the glCopyTexImage function uses the currently enabled GL read buffer, which is the COLOR buffer by default...maybe you need to change it the DEPTH buffer before trying to read depth components. That would make sense

Can't remember the exact function names to get/set the current read buffer, but google is always there for us (hopefully :)

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!