在FBO中屏蔽时背景不可见

时间:2017-02-09 18:52:15

标签: java opengl libgdx

我试图将前景纹理蒙版到LibGDX中的背景纹理上。它在绘制到屏幕时工作正常,但在FBO中绘图时背景消失。

以下是绘制蒙版的方法:

batch.draw(background, x, y);
batch.flush();

Gdx.gl.glColorMask(false, false, false, true);
batch.setBlendFunction(GL20.GL_ONE, GL20.GL_ZERO);
batch.draw(mask, x, y);
batch.flush();

Gdx.gl.glColorMask(true, true, true, true);
batch.setBlendFunction(GL20.GL_DST_ALPHA, GL20.GL_ONE_MINUS_DST_ALPHA);
batch.draw(foreground, x, y);
batch.flush();

batch.setBlendFunction(GL20.GL_SRC_ALPHA, GL20.GL_ONE_MINUS_SRC_ALPHA);

以下是我如何绘制常规版本和FBO版本:

batch.begin();
batch.enableBlending();
batch.setProjectionMatrix(camera.combined);

drawFull(32, 600 - (64 * 4) - 32);

batch.end();

FBO

// draw the FB mask

fb.begin();
batch.begin();
batch.setProjectionMatrix(fbcamera.combined);
batch.enableBlending();

Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);

drawFull(0, 0);

batch.end();
fb.end();

// draw the FB mask to the main batch

batch.begin();
batch.enableBlending();
batch.setProjectionMatrix(camera.combined);

batch.draw(fb.getColorBufferTexture(), 32, 600 - (64 * 7) - 32);

batch.end();

GitHub上提供完整的SSCCE。

1 个答案:

答案 0 :(得分:0)

我设法通过在将FBO绘制到屏幕时禁用混合来解决此问题。这样做的缺点是我们无法用不透明度绘制FBO。

// draw the FB mask to the main batch

batch.begin();
batch.disableBlending();
batch.setProjectionMatrix(camera.combined);

batch.draw(fb.getColorBufferTexture(), 32, 600 - (64 * 7) - 32);

batch.end();