android模具缓冲区很奇怪

时间:2013-11-28 04:44:05

标签: android opengl-es-2.0 stencil-buffer

我想使用openGL ES模板缓冲区在较大的矩形中屏蔽一个小三角形。

使用模板缓冲区绘制小三角形

    GLES20.glEnable(GLES20.GL_STENCIL_TEST);
    GLES20.glStencilFunc(GLES20.GL_ALWAYS, 0x1, 0x1);
    GLES20.glStencilOp(GLES20.GL_REPLACE, GLES20.GL_REPLACE, GLES20.GL_REPLACE);
    GLES20.glColorMask(false, false, false, false);
    GLES20.glDepthMask(false);

    GLES20.glUseProgram(FragmentHandle);
    GLES20.glVertexAttribPointer(0, 3, GLES20.GL_FLOAT, false, 0,floatBuffer);
    GLES20.glEnableVertexAttribArray(0);
    GLES20.glVertexAttrib4f(1, 0.0f, 1.0f, 0.0f, 1.0f);
    GLES20.glDrawArrays(GLES20.GL_TRIANGLES, 0, 3);

绘制全屏矩形。

GLES20.glColorMask(true, true, true, true);
    GLES20.glStencilOp(GLES20.GL_KEEP, GLES20.GL_KEEP, GLES20.GL_KEEP);

    // draw where the shape has NOT been drawn
    GLES20.glStencilFunc(GLES20.GL_NOTEQUAL, 0x1, 0x1);


    GLES20.glUseProgram(FragmentHandle);
    GLES20.glVertexAttribPointer(0, 3, GLES20.GL_FLOAT, false, 0, bigBuffer);
    GLES20.glEnableVertexAttribArray(0);
    GLES20.glVertexAttrib4f(1, 1.0f, 0.0f, 0.0f, 1.0f);

    /*mBatch.draw(texure, Gdx.ScreenWidth/2, Gdx.ScreenHeight/2, 100, 100);
    mBatch.flush();*/
    GLES20.glDrawArrays(GLES20.GL_TRIANGLES, 0, 6);

期待结果: Expect Result

但结果是: Result1

太奇怪了,任何人都可以帮助我!

0 个答案:

没有答案