使用 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。最后我绘制到整个屏幕。我希望它只绘制到上半部分,但它绘制了所有内容。
提前致谢。
最佳答案
您必须使用 setEGLConfigChooser 设置 stencilSize。请注意,不同的手机有不同的表面,可能支持也可能不支持。
例如:
// void android.opengl.GLSurfaceView.setEGLConfigChooser(int redSize, int greenSize, int blueSize, int alphaSize, int depthSize, int stencilSize)
mGLSurfaceView.setEGLConfigChooser(8, 8, 8, 8, 16, 8);
关于java - 让 OpenGL-ES 模板缓冲区工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3138724/