Jump to content
  • Advertisement
Sign in to follow this  
thecoast47

Stencil Buffer Problem

This topic is 2522 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

Basically when geometry that is added to stencil buffer overlaps...it no longer "stencils" as shown here:
[media]
[/media]
all i did was use the stencil buffer to cut out a couple squares on a radial gradient.
When the Squares overlap, the gradient is displayed for some bizarre reason.
Can I get the Squares to keep cutting out the desired regions even if they overlap?



glEnable(GL_STENCIL_TEST);
glStencilFunc(GL_NEVER, 0x0, 0x0);
glStencilOp(GL_INCR, GL_INCR, GL_INCR);

DrawRect(MouseX,MouseY,100,100);
DrawRect(300,200,100,100);

glStencilFunc(GL_NOTEQUAL, 0x1, 0x1);
glStencilOp(GL_KEEP, GL_KEEP, GL_KEEP);

for(unsigned int K = 0; K < LightList.size();K++){
LightList[K]->RenderLight();//<-- radial gradients
}
glDisable(GL_STENCIL_TEST);



Doesn't anyone know whats going on here?

Share this post


Link to post
Share on other sites
Advertisement
When it drives two rectangles on same pixel, stencil is increased twice for that pixel. After that you check if stencil is 1 while you should have check if it is not equal to 0. try replacing second stencil function with

glStencilFunc(GL_EQUAL, 0x00, 0xFF);
glStencilOp(GL_KEEP, GL_KEEP, GL_KEEP);

or better while rendering the rects use this settings. it will replace stencil buffer with 1 instead of increasing it so even if you draw twice, it still will be 1.

glStencilFunc(GL_ALWAYS, 0x1, 0x1);
glStencilOp(GL_KEEP, GL_KEEP, GL_REPLACE);

and while rendering lights test if it is not 1

glStencilFunc(GL_NOTEQUAL, 0x1, 0x1);
glStencilOp(GL_KEEP, GL_KEEP, GL_KEEP);

Share this post


Link to post
Share on other sites
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!