PDA

View Full Version : Display order with/without depth buffer



09-15-2004, 02:10 PM
Hi!

I am developing a 3D board game, whose pieces are painted as spheres. For that the depth buffer has to be enabled ("glEnable(GL_DEPTH_TEST);"). And there are status informations displayed during the game, which must not be covered by any game element (p. e. spheres).
I tried to achieve this effect by disabling the depth buffer while painting the status informations. But the spheres still covered the informations display, no matter if painting them before or after painting the spheres.

Please help me solve this problem.

Thanks in advance
cndg

ZbuffeR
09-15-2004, 03:06 PM
Following method should work :
- enable depth test
- draw spheres
- disable depth test
- draw your status info, it should appear on top of everything previously drawn.

09-15-2004, 04:15 PM
But your suggestion describes exactly what I did and it doesn't work. The spheres still cover everything.

-NiCo-
09-15-2004, 05:15 PM
Did you initialize the window with a depth buffer?
eg. in glut specify GLUT_DEPTH in glutInitDisplayMode

Also, make sure your depthMask is correct in case you changed it somewhere. The initial value should work.

Nico

09-15-2004, 06:44 PM
hey cndg, what zbuffer's saying is that if you follow those steps, it will work. this is standard procedure for rendering game overlays (HUDs), nothing new. if you are following those steps, then there's a mistake somewhere in your code, not in the steps. as nico said, double check your code for innocent blunders :)

09-16-2004, 01:48 AM
@-NiCo-: I only use GLUT when painting the spheres. The rest of my program is "GLUT-free". But the spheres itselves are rendered as I expect - so the depth buffer seems to be working correctly.
Is "depthMask" the property with GL_ALWAYS, GL_LESS,...? If it is: I am not changing it.

@bonehead: It was my first idea to render it that way (enable depth test - draw spheres - disable depth test - draw my status info) but it didn't work as I told. It is so easy - what could I have done wrong? But nevertheless I am going to check my code...

09-16-2004, 12:55 PM
...and did not find a wrong line.

09-16-2004, 03:01 PM
I was able to solve the problem by using the stencil buffer (glStencilFunc and glStencilOp). First the stencil buffer has to be cleared with zeros. The status informations consist of letters. Where ever a letter depending to the status display is drawn the stencil buffer bits covered by the letter are replaced by ones. However the stencil test rules for spheres are a bit more restrictive. They forbid every sphere to change any bit in the stencil buffer. And they prescribe that no bit belonging to any sphere is painted where the stencil buffer bits contain ones. So the status display protects itself a hundred per cent.