Sign in to follow this  

Problems displaying the z-buffer

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

Hey, I tried to display the z-buffer using
glCopyPixels(0,0,SCREEN_W,SCREEN_H,GL_DEPTH);
I've set up the raster position and zoom factor correctly. All it did display is a white rectangle (even when I cleared the z-buffer with 0.0f beforehand). Apart from that, it was terribly slow: 8FPS on a RadeOn 9800 Pro! As far as I understand, glCopyPixels should transfer the stuff on the GPU only, so it should be rather fast. Then I replaced glCopyPixels by
glReadPixels(0,0,SCREEN_W,SCREEN_H, GL_DEPTH_COMPONENT, GL_UNSIGNED_BYTE, buffer);
glDrawPixels(SCREEN_W,SCREEN_H, GL_DEPTH_COMPONENT, GL_UNSIGNED_BYTE, buffer);
and it worked. It displayed the z-buffer contents correctly, but it was even slower (since it has to transfer stuff from GPU to CPU and back). Any ideas why glCopyPixels doesn't give the expected results? I haven't changed any other settings like glPixelTransfer or things like that. And I'm quite sure that I've set up the modelview/projection matrices and the raster position and pixel zoom correctly.

Share this post


Link to post
Share on other sites
Quote:
Original post by Lutz
I tried to display the z-buffer using

glCopyPixels(0,0,SCREEN_W,SCREEN_H,GL_DEPTH);

I've set up the raster position and zoom factor correctly. All it did display is a white rectangle (even when I cleared the z-buffer with 0.0f beforehand).

What you're doing is rendering a rectangle using the current raster color and depth values taken from the depth buffer. If the current raster color is white, then the whole rectangle will be white.
I don't know if you can do what you want with glCopyPixels (at least not without an extension.)
I tried getting it to work with fog, but didn't succeed.

Quote:
Apart from that, it was terribly slow: 8FPS on a RadeOn 9800 Pro! As far as I understand, glCopyPixels should transfer the stuff on the GPU only, so it should be rather fast.

glCopyPixels isn't exactly the fastest operation. Making sure that texturing, lighting etc. are disabled might make it a bit faster..

Quote:
Then I replaced glCopyPixels by

glReadPixels(0,0,SCREEN_W,SCREEN_H, GL_DEPTH_COMPONENT, GL_UNSIGNED_BYTE, buffer);
glDrawPixels(SCREEN_W,SCREEN_H, GL_DEPTH_COMPONENT, GL_UNSIGNED_BYTE, buffer);

and it worked. It displayed the z-buffer contents correctly, but it was even slower (since it has to transfer stuff from GPU to CPU and back).

Any ideas why glCopyPixels doesn't give the expected results?

Yes, but I don't understand why the above worked [smile]
It shouldn't, unless you're doing something clever elsewhere in the code. glReadPixels/glDrawPixels with GL_DEPTH_COMPONENT shouldn't produce any better results than glCopyPixels with GL_DEPTH.
Now, if the format for glDrawPixels was something like GL_RED, then I'd understand. [smile]

Share this post


Link to post
Share on other sites
TomasH:

Thanks for the explanation, I think I understand now what's wrong. Since I have the code at home and not here, I've probably made a mistake: I've probably used

glDrawPixels(SCREEN_W,SCREEN_H, GL_LUMINANCE, GL_UNSIGNED_BYTE, buffer);

instead of GL_DEPTH_COMPONENT.

_the_phantom_:
How?
Is there some fancy glCopyDepthToTexture?

Share this post


Link to post
Share on other sites
Quote:
Original post by Lutz
_the_phantom_:
How?
Is there some fancy glCopyDepthToTexture?


You can use glCopyTexImage2D with GL_DEPTH_COMPONENT as internalformat.The texture needs to be power of 2,though(I don't know if you can use the TEXTURE_RECTANGLE extension with DEPTH_COMPONENT).

Share this post


Link to post
Share on other sites
Are you sure? GL_DEPTH_COMPONENT is not listed among the possible interal formats (at least not in the descriptions of glCopyTexImage2D that google finds).

EDIT: Oh no, I just found some pages. It seems to be an extension. I'll try. Thanks all!

Share this post


Link to post
Share on other sites

This topic is 4855 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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this