java - 让 OpenGL-ES 模板缓冲区工作

标签 java android opengl-es stencil-buffer

使用 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/

相关文章:

AppWidgetManager.updateAppWidget 中的 android.os.TransactionTooLargeException

android - 权限映射问题

java - 在 Android OpenGL ES 应用程序中加载纹理

java - 自定义 Java XMLBuilder 与基于标准类的对比

java - 两个 Shape 对象似乎在错误的位置相交?

java - 为什么不能将String类型添加到List<?>?

android - 特 pull 维斯 VS CircleCi VS Jenkins

java - 与 Android 中的 GLThread 同步

Android:将 AdMob 与 OpenGL 应用程序结合使用

java - 扫描仪在使用 next() 或 nextFoo() 后跳过 nextLine()?