使用适用于 Android 的 opengl-es 中的模板缓冲区,我只是试图掩盖屏幕的绘图部分。我想我的设置是正确的,但它并没有掩盖非模板部分。下面是我正在做的代码的提取。
gl.glEnable(GL10.GL_STENCIL_TEST);
gl.glClearStencil(0);
gl.glClear(GL10.GL_STENCIL_BUFFER_BIT);
gl.glColorMask(false, false, false, false);
gl.glDepthMask(false);
gl.glStencilFunc(GL10.GL_ALWAYS, 1, 1);
gl.glStencilOp(GL10.GL_REPLACE, GL10.GL_REPLACE, GL10.GL_REPLACE);
drawMask(); //I have confirmed this draws to the correct location by allowing colour to show. Trust that this draws the mask to the correct location.
gl.glColorMask(true, true, true, true);
gl.glDepthMask(true);
gl.glStencilFunc(GL10.GL_EQUAL, 1, 1);
gl.glStencilOp(GL10.GL_KEEP, GL10.GL_KEEP, GL10.GL_KEEP);
drawItems(); //Draw everything. Only items inside the masked area should be drawn. But everything is drawn with this code...
gl.glDisable(GL10.GL_STENCIL_TEST);
有人发现这有什么问题吗?它所做的基本上是画一个框,说是屏幕的一半(如果我启用了颜色,这将起作用),它将该区域的模板缓冲区设置为 1。最后我绘制到整个屏幕。我希望它只绘制到上半部分,但它会绘制所有内容。
提前致谢。