Sign in to follow this  
Gazoo101

Depth Buffer not being updated?

Recommended Posts

Hey GameDev,

I've been dealing a hand at using the stencil buffer to perform some simple Constructive Solid Geometry, and I almost have my first basic algorithm working, but I've run into some issues with the depth buffer. I'm not sure if I am doing anything wrong or what exactly is happening. Basically, it seems like the depth buffer isn't being updated properly in between drawing a few simple boxes.

My code looks as follows:
[code]

/***
* First we fill the depth buffer with the CONVEX proxy geometry!
*/
glEnable ( GL_DEPTH_TEST );
glEnable(GL_CULL_FACE);
glCullFace(GL_BACK);

renderProxyGeometry();

for (iter = cutGeometry.begin(); iter != cutGeometry.end(); iter++) {
/***
* Keep Culling front-faces as we fill the stencil buffer with potential intersecting geometry
*/

glCullFace(GL_BACK);
glDepthMask(GL_FALSE);
glDepthFunc(GL_LESS);
glEnable(GL_STENCIL_TEST);
glStencilFunc(GL_ALWAYS, 0, 0);
glStencilOp(GL_KEEP, GL_KEEP, GL_INCR);
glColorMask(0, 0, 0, 0);

glColor3f(0.0, 0.0, 1.0);
iter->render();

/***
* Switch to Culling Back-faces and write only where we've established a potential intersection
*/
glDepthMask(GL_TRUE);
glCullFace(GL_FRONT);
glDepthFunc(GL_GREATER);
glStencilFunc(GL_EQUAL, 1, 1);
glStencilOp(GL_KEEP, GL_KEEP, GL_KEEP);
glColorMask(1, 1, 1, 1);

glColor3f(0.0, 0.0, 1.0);
iter->render();

glClear( GL_STENCIL_BUFFER_BIT );
}
[/code]


The important part to note is the last part of the for-loop where I render the backface of a few boxes with values greater than any already placed in the Z-Buffer. The first box properly draws over the the initial box (drawn via the renderProxyGeometry), but in the next iteration of the for-loop, it seems as if the z-buffer has not been updated properly from the last iteration as I get an unexpected result. I have a debugging function which reads the depthbuffer using glReadPixels - I tried splicing this into the for-loop hoping to get an image per new drawn update, but all I get is the same depth picture with only the initial box and the first intersecting box rendered in the for loop.

I have a sneaking suspicion that I can't exactly trust the values I'm reading from the z-buffer during rendering. Does anyone have any experience regarding this?

Regards,
Gazoo

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this