# Using the z-depth buffer when drawing from bgl draw callbacks?

I'm investigating making some simple widgets using bgl and finding it difficult to use the depth buffer without making a mess of the area I'm drawing in.

Enable depth testing:

glEnable(GL_DEPTH_TEST)


From here I've tried calls to glDepthRange(...) , glDepthFunc(...) , with varying degrees of success, but without a handle on writing above the view, ie when I do get an element to draw behind it ends up behind everything and can't be seen. (well at least I'm assuming that's the case)

Will keep editing the question as I get more o fay with bgl / opengl.

Ok I have found one way of doing this.

bgl.glEnable(bgl.GL_DEPTH_TEST)
bgl.glDepthRange (0.0, 0.9);

# Draw "Something" here

bgl.glDepthRange (0.1, 1.0)

# Anything drawn now will be below "Something" drawn above

# restore opengl defaults

bgl.glLineWidth(1)
bgl.glDisable(bgl.GL_DEPTH_TEST)
bgl.glDisable(bgl.GL_BLEND)