Hi dudes, i’d like to understand a little bit more of stencil buffer and decaling.
I’m trying to create a decal on a 3d-world and i’ve read a bit on stencil to create some functi«ons for the decal.
void setStencil()
{
glEnable(GL_STENCIL_TEST);
glStencilFunc(GL_ALWAYS,1,1);
glStencilOp(GL_KEEP, GL_ZERO, GL_REPLACE);
}
draw wall
void setDecal()
{
glStencilFunc(GL_EQUAL, 1, 1);
glStencilMask(GL_FALSE);
glDisable(GL_DEPTH_TEST);
}
make decal(a simple square)
void disableStencil()
{
glEnable(GL_DEPTH_TEST);
glStencilMask(GL_TRUE);
glStencilFunc(GL_ALWAYS,1,1);
glStencilOp(GL_KEEP,GL_KEEP,GL_KEEP);
glDisable(GL_STENCIL_TEST);
}
The question is: the decal is ALWAYS visible, even when i put a object in front of it…Can anyone help me on this one?