0
\$\begingroup\$


I try to draw severeal Sprites to a FrameBuffer. The Sprites are PNGs with transparency. When I draw them directly to the screen it's fine. But when I draw on the FrameBuffer and then draw the resulting texture on the screen the transparent parts are cut out and the glBackground shines through. Any idea how to solve this?

Here is how I do it:

FrameBuffer fbo = new FrameBuffer(Format.RGBA8888, width, height, false);
Sprite fboTexture = new Sprite(frameBufferObject.getColorBufferTexture());
fboTexture.flip(false, true);

fbo.begin();
batch.begin();
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
batch.draw(sprite1, 0,0);
batch.draw(sprite2, 0,0);
batch.draw(sprite3, 0,0);
batch.end();
fbo.end();

batch.begin();
batch.draw(fboTexture, 0,0);
batch.end();
\$\endgroup\$
0
\$\begingroup\$

You may need to enable blending in the batch

batch.enableBlending();
\$\endgroup\$
  • \$\begingroup\$ Blending is enabled by default and I never disabled it. \$\endgroup\$ – mrdlink Jul 24 '17 at 14:42
0
\$\begingroup\$

Ok I fixed it myself. I simply change the blend function before drawing the FrameBuffer.I change it to batch.setBlendFunction(GL20.GL_ONE_MINUS_DST_ALPHA, GL20.GL_SRC_ALPHA) and then change it back to batch.setBlendFunction(GL20.GL_SRC_ALPHA, GL20.GL_ONE_MINUS_SRC_ALPHA).

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.