Mon*_*der 7 java android opengl-es stencil-buffer
使用opengl-es for Android中的模板缓冲区,我只是试图屏蔽绘制部分屏幕.我认为我设置正确,但它没有掩盖非模板部分.下面是我正在做的代码的提取.
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);
Run Code Online (Sandbox Code Playgroud)
有人发现这有什么不对吗?它的作用基本上是绘制一个框,比如屏幕的一半(如果我启用了颜色,这可以工作),它将模板缓冲区设置为该区域的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);
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
6947 次 |
| 最近记录: |