Writing to the depth buffer without testing depth in OpenGL (without a shader)

In OpenGL, is it possible to draw a sequence of polygons that do not check the depth (therefore, they will always be drawn in front of other polygons drawn in front of it, relative to their z position)

but also at the same time they still write to the depth buffer?

I guess this is doable using shaders, but right now I don't have access to this.

+7
opengl
source share
2 answers

Not strictly speaking (from the man page ):

depth buffer is not updated if depth check is disabled.

But ... you can enable depth checking, while the absence of any fragment does not complete the test:

glDepthFunc(GL_ALWAYS); glEnable(GL_DEPTH_TEST); 

Of course, you get the last Z written by this, but not the closest to the look.

+16
source share

You can achieve this in only two passes. First you need to fill the depth buffer only with a color mask:

 glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE); 

The second pass allows you to turn on the color recording again, disable the depth check and make the sequence of polygons in order.

+3
source share

All Articles