opengl stencil buffer - not quite got it working

房东的猫 提交于 2019-12-06 06:24:23

Problem one: When drawing the background either disable stencil test before, or switch the stencil function to GL_ALWAYS so that the fragments pass (I recomment turning it off). Then you're setting two different stencil modi afterwards, but neither will do, what you intend. So here's the change:

glDisable(GL_STENCIL_TEST);
glStencilMask(0x0);

draw_background();

glEnable(GL_STENCIL_TEST);
glStencilMask(0x1);
glStencilFunc(GL_ALWAYS, 0x1, 0x1);
glStencilOp(GL_KEEP, GL_KEEP, GL_REPLACE);
glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE);
glDepthMask(GL_FALSE);

draw_trangle();

glStencilFunc(GL_NOTEQUAL, 0x1, 0x1);
glStencilOp(GL_KEEP, GL_KEEP, GL_KEEP);
glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
glDepthMask(GL_TRUE);

draw_blue_square();
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!