Advertisement

Help with Stencil Test

Started by January 29, 2019 05:22 PM
0 comments, last by alx119 5 years, 7 months ago

Hi guys,

I'm following the stencil tutorials from learnopengl.com and I tried something and I can't explain why is not working. I might not understood very good the stencil test.
So I have a floor and 2 containers and I want to draw a border around containers, like in the tutorial. The code will be:

//Before the rendering loop:
glEnable(GL_DEPTH_TEST);
glEnable(GL_STENCIL_TEST);
glStencilFunc(GL_NOTEQUAL, 1, 0xFF);
glStencilOp(GL_KEEP, GL_KEEP, GL_REPLACE);

In the rendering loop:
//Draw the floor but don't write to stencil buffer
glStencilMask(0x00);
DrawFloor();

//Draw the 2 containers
glStencilFunc(GL_ALWAYS, 1, 0xFF);
glStencilMask(0xFF);
DrawTwoContainers()

//Scale containers for the borders
glStencilFunc(GL_NOTEQUAL, 1, 0xFF);
glStencilMask(0x00);
glDisable(GL_DEPTH_TEST);
DrawTheTwoScaledContainers()

glStencilMask(0xFF);
glEnable(GL_DEPTH_TEST);

Well everything is working fine, but at the code where I scale the containers, if I change the GL_NOTEQUAL, with GL_LESS, it draws only the normal containers, but not the borders and not even the floor.The stencil values where the borders should be drawn are 0, so they are not equal and they are less than 1.  Why is this happening ?

Hope you can help me with an explanation and thanks in advance! :)

This topic is closed to new replies.

Advertisement