you have copied the depth val to r, g and b channels? Or rather is bob xy3 in size, i.e. a r, g and b channel or simpler still use a struct with r, g, b glubytes in it. malloc x*y of these. OpenGL still takes an array of these for drawpixels.
What depth-ranges do you get in the float bob? Try capturing the lowest anf highest values you get when reading the depth buffer.
Remember, if you use a perspecive projection, the read-back depth value is not linearly scaled. So if you have a lot of ‘very far’ values, they are all quite close to 1 --> a white image.
Yes Ive experimented with different settings for the near and far planes. I think the problem is something to do with the variable types. Like how do you convert a float to a GLubyte? I think data is being lost.
Why is this so hard to do? Youd think there would be some examples somewhere that show how to do this effectively.
Sorry for going on but Ive spent ages trying to do something that you’d expect to take 5 minutes. And yes ive searched previous postings and still no joy.
Don’t know if this will help but I found that I was getting A LOT of z buffer values VERY close to 1. That’s even for pixels where I knew the object was quite close to the ‘camera’. Turned out to be exactly how it should be due to the non-linear way in which the z buffer information is stored.
I used this to back calculate all the z values and know everything works fine.
EDIT: For quick reference this is taken from the above link:
for Near Clip = 10 and Far Clip = 10000,
zval =0.9 range = 99.1
zval =0.99 range = 909
zval = 0.999 range = 5002
So a ‘pixel’ at range 100 even with the far clip plane at 10000 would look white.
[This message has been edited by thelamberto (edited 07-30-2002).]
What I did was find the max and minimum depths first. I used this as a range. So a pixel with a minimum depth was set to white (ie. 255) and a pixel with a maxmimum depth was set to black (ie. 0). Inbetween were set to shades of grey.
One other thing. When getting maximum pixel depth check for zval == 1 (ie. value from the depth buffer). If zval == 1 then ignore it as regards calcuating maximum depth. As said before this can screw things up considerably.