Jump to content
  • Advertisement
Sign in to follow this  
shirsoft

Saving a depth texture

This topic is 4028 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

I am having problems in reading from the depth texture using glGetTexImage. Iam using the following code. However glGetTexImage gives invalid operation error. The documentation suggests that this happens when glGetTexImage is called between glBegin and glEnd. But this is not happening in my case. I even put an extra glEnd before it but no luck.
glReadBuffer(GL_BACK);
glBindTexture(GL_TEXTURE_2D, iDepthTex);
glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, w, h);
glGetTexImage(GL_TEXTURE_2D,0,GL_RED,GL_INT,depthbuffer);

Please help

Share this post


Link to post
Share on other sites
Advertisement
im not to sure what u need for glGetTexImage with a depth texture (check the spec) but im pretty sure its not GL_RED.
though with what youre doing youre prolly best off using glReadPixels( .. GL_DEPTH_COMPONENT ... )

Share this post


Link to post
Share on other sites
You actual do need GL_DEPTH_COMPONENT instead of GL_RED else you get GL_INVALID_OPERATION according to the spec.

Share this post


Link to post
Share on other sites

The complete picture would look something like this:

// Prepare a texture object to hold depth values.
// Can be done once at an 'init' stage of the application
GLint l_DepthmapWidth = 512;
GLint l_DepthmapHeight = 512;
GLuint l_DepthMap = 0;
glGenTextures(1, &l_DepthMap);
glBindTexture(GL_TEXTURE_2D, l_ShadowMap);
glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT, l_DepthmapWidth, l_DepthmapWidth, 0, GL_DEPTH_COMPONENT, GL_UNSIGNED_INT, NULL);

...

// Render to the framebuffer. Issue your render call.
// If this is a special depth value generated stage and you're not
// interested in color values, you can do some optimizations like disabling
// writing colors with glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE);
// or disabling lighting etc..

...

// Retrieve depth values
glBindTexture(GL_TEXTURE_2D, l_DepthMap);
glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, l_DepthmapWidth, l_DepthmapHeight);

...

// Do what ever it is you want to do with the texture now containing depth values


Hope this helps.


Serge van Keulen

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!