代码之家  ›  专栏  ›  技术社区  ›  Moncader

使OpenGL ES模具缓冲区工作

  •  7
  • Moncader  · 技术社区  · 15 年前

    使用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);
    

    提前谢谢。

    4 回复  |  直到 11 年前
        1
  •  5
  •   Pete    14 年前

    必须使用setEGLConfigChooser设置模具大小。请注意,不同的手机有不同的表面,可能支持也可能不支持这一点。

    例如:

        // 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);
    
        2
  •  4
  •   Moncader    15 年前

        3
  •  2
  •   Gunther Piez    13 年前

    您需要使用 GLSurfaceView.setEGLConfigChooser :

    public class MyActivity extends Activity {
        GLSurfaceView view;
        ...
        onCreate(...
            view.setEGLConfigChooser(5,6,5,0,16,8);
            view.setRenderer(...
    

        4
  •  0
  •   Community Mohan Dere    9 年前

    此答案将从以下链接重新发布。这为我修复了一个示例中的opengles2.0错误。

    android opengl 2.0 stencil buffer not working