LibGDX多边形遮罩
在LibGDX中有没有办法创建多边形形状的遮罩?我知道如何使用正方形和圆形制作遮罩,但不会使用多边形。下面的代码可以使用矩形正确地渲染遮罩LibGDX多边形遮罩,libgdx,Libgdx,在LibGDX中有没有办法创建多边形形状的遮罩?我知道如何使用正方形和圆形制作遮罩,但不会使用多边形。下面的代码可以使用矩形正确地渲染遮罩 Gdx.gl.glClearColor(0, 0, 0, 1); Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT); Gdx.gl.glClearDepthf(1f); Gdx.gl.glClear(GL20.GL_DEPTH_BUFFER_BIT);
Gdx.gl.glClearColor(0, 0, 0, 1);
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
Gdx.gl.glClearDepthf(1f);
Gdx.gl.glClear(GL20.GL_DEPTH_BUFFER_BIT);
Gdx.gl.glDepthFunc(GL20.GL_LESS);
Gdx.gl.glEnable(GL20.GL_DEPTH_TEST);
Gdx.gl.glDepthMask(true);
Gdx.gl.glColorMask(false, false, false, false);
// Renders the rectangle
shapes.begin(ShapeRenderer.ShapeType.Filled);
shapes.setColor(1, 1, 1, 1);
shapes.rect(Gdx.graphics.getWidth() / 2, gdx.graphics.getHeight() / 2, 200f, 200);
shapes.end();
batch.begin();
Gdx.gl.glColorMask(true, true, true, true);
Gdx.gl.glEnable(GL20.GL_DEPTH_TEST);
Gdx.gl.glDepthFunc(GL20.GL_EQUAL);
bg.draw(batch);
batch.end();
Gdx.gl.glDisable(GL20.GL_DEPTH_TEST);
但是,下面的代码不起作用,只是呈现一个黑屏
Gdx.gl.glClearColor(0, 0, 0, 1);
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
Gdx.gl.glClearDepthf(1f);
Gdx.gl.glClear(GL20.GL_DEPTH_BUFFER_BIT);
Gdx.gl.glDepthFunc(GL20.GL_LESS);
Gdx.gl.glEnable(GL20.GL_DEPTH_TEST);
Gdx.gl.glDepthMask(true);
Gdx.gl.glColorMask(false, false, false, false);
// This should be the polygon being rendered as a mask here
polyBatch.begin();
polygonSprite.draw(polyBatch);
polyBatch.end();
batch.begin();
Gdx.gl.glColorMask(true, true, true, true);
Gdx.gl.glEnable(GL20.GL_DEPTH_TEST);
Gdx.gl.glDepthFunc(GL20.GL_EQUAL);
bg.draw(batch);
batch.end();
Gdx.gl.glDisable(GL20.GL_DEPTH_TEST);
但是,下面的代码将多边形渲染得很好,并使用与上一个示例相同的坐标
Gdx.gl.glClearColor(0, 0, 0, 1);
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
// This polygon uses the same coordinates as the last example
// however it now displays the polygon.
polyBatch.begin();
polygonSprite.draw(polyBatch);
polyBatch.end();
尝试移动批处理.begin()第三段中的code>向下,这样它就不会包含
Gdx.gl
函数,如下所示:
//batch.begin();
//from here
Gdx.gl.glColorMask(true, true, true, true);
Gdx.gl.glEnable(GL20.GL_DEPTH_TEST);
Gdx.gl.glDepthFunc(GL20.GL_EQUAL);
//to here
batch.begin();
bg.draw(batch);
batch.end();
Gdx.gl.glDisable(GL20.GL_DEPTH_TEST);
谢谢你的帮助,但不幸的是它没有起作用。我甚至试着一行一行地把不同的行混合在一起,然后把它们放在batch.begin()方法之前,但没有任何效果。