Rendering problem

After rendering my scene i need to draw a coordinate system - also when other objects lying nearer to the eye position. I tried glDisable(GL_DEPTH_TEST). But this is the wrong way because the coordinate system has to be drawn by comparing the z values to be rendered correctly. What other alternatives there are? I hope this question is worth to be under ‘advanced’!

Best regards,

If it’s after you rendered your other scene and you don’t need the depth buffer anymore and don’t want to depth test against the other geometry, just do glClear(GL_DEPTH_BUFFER_BIT) before rendering your coordinate system.
If it’s that simple, then no, that’s not advanced. :wink:

When i am right, using glClear() is an expensive operation. So i don’t want to use it more than once per frame. Is there another alternative?

glClear() is an expensive operation
Hum, not really. calling it once or twice would not matter much. just try.

I tried it and it is like you said. Thank you!

im not really understanding why glDisable(GL_DEPTH_TEST) doesnt work but anyways

apart from clearing the depthbuffer
u could try

glDepthTest( GL_ALWAYS ); // i think thats the syntax



I think he’s talking about drawing an axis triplet in a kind of HUD layer. In which case you’ll need depth testing to draw the axis correctly, but the depth values from the scene-draw will mess it up, so glClear’ing the depth buffer is the way to go. But you don’t have to clear the whole framebuffer (if you’re running at a high resolution this will be a significant fill cost), use glScissor to only clear the screen rectangle the axis will use.

You could avoid the clear entirely by partitioning the depth buffer. That should be the fastest. For instance draw the scene in [0.1 … 1.0] range, and use [0, 0.1] for HUD items that needs depth testing.

… or you could render your HUD into a separate framebuffer and composite it with the background. This might not be optimal in terms of performance, but it might simplify things and add some flexibility to boot.

Check out glDepthMask() and glDepthRange(), they may be useful.

how? do share…

I’m not sure how DepthMask helps but DepthRange is a good suggestion; Humus describes it correctly.

If you cannot afford to lose depth precision then a scissored depth clear is the way to go.

Or, if its a simple enough coordinate system, disable DEPTH_TEST and use a painter’s algorithm.

Or, if its a simple enough coordinate system, disable DEPTH_TEST and use a painter’s algorithm.
that will work as theres not gonna be any polygon intersection.
just draw from back to front the 3 axises based on distance to camera the axises end points.