Jump to content
  • Advertisement
Sign in to follow this  
MARS_999

FBO depth texture and glGetTexImage

This topic is 4415 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 trying to copy the depth texture from my FBO to a array and save the results to a .tga file. I can get the color textures to work but not my depth texture... Is this possible to save the depth results as a greyscale texture?
glPixelStoref(GL_UNPACK_ALIGNMENT, 1);
unsigned char *temp = new unsigned char[1024 * 1024];
waterFBO.BindDepthTexture();
glGetTexImage(GL_TEXTURE_2D, 0, GL_LUMINANCE, GL_UNSIGNED_BYTE, temp);
CTexture t = CTexture();
t.SaveTGATextureGreyScale("temp.tga", 1024, 1024, temp, 1024);
delete []temp;

Share this post


Link to post
Share on other sites
Advertisement
GL_LUMINANCE (I'm 99% sure) returns one value per texel. You might want to use GL_INTENSITY (even if only because I am 100% sure that it uses 1 value per texel [wink]!)

Since true color textures work, just repeat the values for the RGB channels, like this:

glGetTexImage(GL_TEXTURE_2D, 0, GL_LUMINANCE, GL_UNSIGNED_BYTE, temp); // from your code

GLubyte bgr_data[1024 * 1024 * 3];
for (int i = 0; i < 1024 * 1024; ++i)
{
bgr_data[(3*i) + 0] = temp;
bgr_data[(3*i) + 1] = temp;
bgr_data[(3*i) + 2] = temp;
}

save_tga_true_color("depth.tga", 1024, 1024, bgr_data); // or something

Share this post


Link to post
Share on other sites
If you have a depth texture FBO, then sure, it will work.
Also, you will lose precision if you read as ubyte. Read as uint or ushort. Save it as a DDS.

Share this post


Link to post
Share on other sites
No dice on the loop idea deavik.... And V-man I am using FBO's and they work correctly and the glGetTexImage works for the color textures of my FBO... Thanks for the help so far.

Share this post


Link to post
Share on other sites
Quote:
Original post by MARS_999
No dice on the loop idea deavik....

I was pretty sure that would have worked ... anyway when you say the save tga is "not working" with the dpeth texture, what is happening? I can predict of 2 things: a) around 1/3 of the pixel area of your saved image is filled with garbled data, and the rest is black (uninitialised), and b) the whole image is white (or maybe black).

If it is a) then the solution would be in my previous post. If b), then hte depth texture is actually blank (maybe due to lack of depth buffer precision). Have you tried binding the depth texture as a GL_INTENSITY texture and drawing a textured quad in-game to check?

Share this post


Link to post
Share on other sites
Its all black and I bet you now that I think about it that the values are 0 to 1 and thats floating point and when I save it as a unsigned char its trimmed to 0 loss of data... :) I will print the data out to a text file and see what is going on...

Share this post


Link to post
Share on other sites
Quote:
Original post by MARS_999
Its all black and I bet you now that I think about it that the values are 0 to 1 and thats floating point and when I save it as a unsigned char its trimmed to 0 loss of data... :) I will print the data out to a text file and see what is going on...

If you read back as GL_UNSIGNED_BYTE, it will give you values in the range [0, 255]. The problem in this case, is that the depth buffer does not have enough precision.

What are the near and far plane values in the pass right after which you are capturing the depth buffer? Try moving the near plane as far out as possible (and the far plane as near as possible) to get higher depth buffer precision. All depth values are clamped in a non linear range (most probably floating point (0, 1)), so you want to reduce the range of the depth buffer to get maximum precision where it is required.

Share this post


Link to post
Share on other sites
I am already ahead of you! :) near/far 3.0 and 75.0 :) Still no dice, all zeros. Oh well about to give up... Thanks for the help.

Share this post


Link to post
Share on other sites
Quote:
Original post by phantom
I'm assuming you've confirmed you do get databack into your array?


Yeah that's what I was doing with the printing the values to a text file and checking to see what I got... I set the array to zeros and then copied the data into the temp array from the glGetTexImage() and I get values like 40 and 60??? Got me whats wrong, like I said my color textures in my FBO work to print out but the depth texture is a no go...

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.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!