Java 在FBO中进行遮罩时背景不可见
我试图在LibGDX中将前景纹理遮罩到背景纹理上。在屏幕上绘制时效果很好,但在FBO中绘制时背景消失 以下是如何绘制遮罩:Java 在FBO中进行遮罩时背景不可见,java,opengl,libgdx,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
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();
我在将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();