View Full Version : ZBuffer problem?
10-01-2002, 12:58 PM
Hi, Iam having this weird problem:
I render a rotating quad, then switch to ortho mode, the draw a static quad. Should the rotating quad be behind the static quad, as I render the static quad last? I am very confused here.
Which quad is drawn ontop of which depends on depth function, if depth test is enabled at all, the distance into the screen which the quads are drawn, and on the near and far clip plane values used in the two types of projection.
10-01-2002, 02:26 PM
Bob, I am using a GL_LEQUAL method of depth testing. My depth buffer is enabled (16bit)
I am pretty sure it is a zbuffer problem. What might I be missing here?
There's more than just depth function and bit depth that matters. As I said, projection and depth values of the quads also matters.
Comparing depth values when using different projections can be very tricky. A quad closer to the viewpoint can be occluded by a quad drawn further away from the viewpoint if you change the projection before drawing the second quad.
If you want to have all your drawings from the ortho view in front of the drawings done in the perspective view do this:
1. clear screen (color and depth)
2. setup perspective view, draw stuff
3. clear screen (depth only)
4. setup ortho view draw stuff
5. swap buffers
As Bob already pointed out, it can be difficult if not impossible to correlate the depth values written by the perspective projection to the depth values written by the ortho projection. FYI: depth values are inverse-exponentially distributed between the near and far values for perspective views, and they are linearly distributed for ortho views
10-02-2002, 01:07 PM
Thank you for your fast and helpful replies. I tried everything you said, but I still have the same problem. I tried rendering only in perspective mode, using 2 quads with different value of z, but it seems that the ZBuffer isnt working at all. The last quad I draw it is always in front of the first one, regardless of the Z value. Uhh, any other ideas?
10-02-2002, 01:08 PM
Oh, one notice here, I use glPushMatrix() then render the quad and then popmatrix.
Could this be the problem?
10-02-2002, 01:17 PM
Do you have a depth buffer? One problem I ran into when I tried to port some things to Linux is that Linux didn't provide a depth buffer by default like Windows does. So using glut, for the glutInitDisplayMode you have to add GLUT_DEPTH to your bits.
(e.g. glutInitDisplayMode(GLUT_DEPTH | GLUT_DOUBLE | GLUT_RGB) http://www.opengl.org/discussion_boards/ubb/wink.gif
10-03-2002, 04:42 AM
Yes, I do provide a 16bit ZBuffer and clear my screen using GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT
10-03-2002, 04:59 AM
10-03-2002, 11:03 AM
Ohh it didnt work either.. Anyway, I will restart the project as it is very messy and if I still have ZBuffer problem I will post again http://www.opengl.org/discussion_boards/ubb/frown.gif Thanks a lot though
Powered by vBulletin® Version 4.2.3 Copyright © 2017 vBulletin Solutions, Inc. All rights reserved.