我怎么剪一个圆圈?

时间:2015-09-19 12:52:50

标签: libgdx

如何使用libGDX剪辑圆圈?剪切矩形很容易Gdx.gl.glScissor(int x,int y,int width,int height)。是否有任何方法来剪辑圆圈或我需要一些算法?

1 个答案:

答案 0 :(得分:1)

可以使用深度缓冲区剪辑圆圈:

    //clear screen

    Gdx.gl.glClear(GL10.GL_COLOR_BUFFER_BIT);

    //clear depth buffer with 1.0 : 

    Gdx.gl.glClear(GL10.GL_DEPTH_BUFFER_BIT);

    //set the function to LESS

    Gdx.gl.glDepthFunc(GL20.GL_LESS);

    //enable depth writing

    Gdx.gl.glEnable(GL20.GL_DEPTH_TEST);

    //Enable depth mask and disable RGBA color writing

    Gdx.gl.glDepthMask(true);

   Gdx.gl.glColorMask(false, false, false, false);

    //rendering(Circle ect..) primitive shapes

    shapeRenderer.begin();
    shapeRenderer.circle(x, y, radius);
    shapeRenderer.end();

    batch.begin();

     //Enable RGBA color writing

    Gdx.gl.glColorMask(true, true, true, true);

    //Enable testing

    Gdx.gl.glEnable(GL10.GL_DEPTH_TEST);

    //Discards pixels outside masked shapes

    Gdx.gl.glDepthFunc(GL10.GL_EQUAL);

    batch.draw(...);

    batch.end();