Jump to content
  • Advertisement
Sign in to follow this  
Gazoo101

Depth Buffer not being updated?

This topic is 2603 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

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:


/***
* 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 );
}



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
Advertisement
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!