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\$

2 Answers 2

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\$
-1
\$\begingroup\$

You may need to enable blending in the batch

batch.enableBlending();
\$\endgroup\$
2
  • \$\begingroup\$ Blending is enabled by default and I never disabled it. \$\endgroup\$
    – mrdlink
    Commented Jul 24, 2017 at 14:42
  • \$\begingroup\$ This should've been a comment.. \$\endgroup\$
    – Hasen
    Commented Oct 15, 2022 at 23:25

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .