问题描述
通过在OpenGL-ES模板缓存为Android,我只是想屏蔽掉绘制屏幕的一部分。我想我有它树立正确的,但它不是掩盖了非钢印的部分。下面是我在做什么的提取code。
With the stencil buffer in opengl-es for Android, I'm simply trying to mask out drawing part of the screen. I think I have it set up right, but it is not masking out the non-stenciled parts. Below is an extraction of code for what I'm doing.
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的区域。并在结束时,我画到整个屏幕。我希望它画到只有上半部分,但它吸引了一切。
Anyone spot anything wrong with this? What it does basically is draw a box for say, half the screen (this works if I had colour enabled) which is setting the stencil buffer to 1 for that area. And at the end I draw to the whole screen. I want it to draw to the top half only, but it draws everything.
在此先感谢。
推荐答案
原因结束了,我没有把我的EGLConfig正确支持模板缓存。
The reason ended up being that I had not set my EGLConfig properly to support stencil buffer.
这篇关于获得了OpenGL-ES模板缓冲区工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!