Archived

This topic is now archived and is closed to further replies.

Stencil buffer

This topic is 5379 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. I just read the stencil buffer tutorial, but I can''t quite understand why the depth buffer must be disabled before drawing the floor into the stencil buffer. Why ?

Share this post


Link to post
Share on other sites
The depthbuffer is disabled because otherwise the "real" floor won''t be drawn.

The floor is drawn twice: The first time only the stencil buffer should be updated, so the depthbuffer and the colorbuffer are disabled.
If depthtest had been enabled the first time, nothing would be drawn the second time because the z-buffer test would fail.

It is perhaps clearer if you replace the calls to glDisable/Enable(GL_DEPTH_TEST) with:
glDepthMask(false); // do not update zbuffer
DrawFloor();
glDepthMask(true);

I guess glDisable(GL_DEPTH_TEST) is used in the tutorial because the floor is the first thing to be drawn so there is no need to do any zbuffer tests at all.

Share this post


Link to post
Share on other sites