Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Writing to depth buffer without depth testing in OpenGL (non shader)

Tags:

opengl

In OpenGL, is it possible, to draw a sequence of polygons that doesn't check for depth (so they will always be drawn in front of other polygons drawn before it, regarding of their z position)

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

I suppose this is doable using shaders, but right now I have no access to that.

like image 565
kamziro Avatar asked Dec 12 '10 11:12

kamziro


2 Answers

Not strictly speaking (from the man page):

the depth buffer is not updated if the depth test is disabled.

But... you can have the depth test enabled, while not having any fragment fail the test:

glDepthFunc(GL_ALWAYS);
glEnable(GL_DEPTH_TEST);

Of course, you get the last Z written by doing that, not the closest to the view.

like image 97
Bahbar Avatar answered Sep 22 '22 14:09

Bahbar


You can only achieve that using two passes. First one is to populate the depth buffer only using a color mask:

glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE);

Second pass you enable color writing again, disable depth test and render your sequence of polygons in order.

like image 24
Stringer Avatar answered Sep 21 '22 14:09

Stringer