Game Development Community

OpenGL - some way to specify a Depth value for 2D calls ?

by Orion Elenzil · in Technical Issues · 07/14/2008 (12:08 pm) · 3 replies

This is weird, i know,
but is there some way to provide a depth value which will be used by 2D openGL calls ?

what i want to do is have some stuff in the GUI layer do depth-testing against the zBuffer,
with a depth value specified by me.

i wonder if glPolygonOffset() can be used.

#1
07/14/2008 (12:31 pm)
glPolygonOffset() is close,
but has some problems.
it's meant for tiny adjustments to the depth of pixels,
and uses an implementation-specific internal value which i don't see any way of retrieving.

i might have better luck futzing w/ the matrices down in dglDrawTextN().

(specifically, i'm trying to get the player name in GuiShapeNameHud to be occluded by world geometry)
#2
07/14/2008 (1:19 pm)
Shouldn't this be a matter of setting the correct GFX flags, like Z read enable? I guess that would only work if you also got your matrices set up to render in world space first, which is a little tricky from a gui, but GuiTSEditCtrl does it so, maybe thats one avenue to look into. Specifically GuiTSEditCtrl gets an onRender which is the usual GUI screen-space render callback and then a second renderScene call, in which you can render in worldSpace.

Alternatively if you render your player names inside shapeBase::renderObject it would already be setup correctly. I don't really know what I'm talking about. I'm still a noob when it comes to rendering, but thought I'd try to help some since you responded to me!
#3
07/14/2008 (1:29 pm)
Thanks for the response, James!

yes, you would also need to call glEnable(DEPTH_TEST) to enable reading the ZBuffer,
but that's pretty straight-forward.
the tricky part is getting a meaningful Z-value for the pixels which are drawn as part of the text,
and the text handling routines all use 2-dimensional points instead of 3.