There's an entity of my LibGDX game I would like to render to a PNG. So I made a small tool that is a LibGDX app to display that entity and it takes a screenshot on F5. The goal of that app is only to generate the PNG.

camera.update(); Gdx.gl.glClearColor(0, 0, 0, 0); Gdx.gl.glClear(GL_COLOR_BUFFER_BIT); batch.setProjectionMatrix(camera.combined); batch.begin(); animation.update(Gdx.graphics.getDeltaTime() * 1000); animation.draw(batch); batch.end(); if(exporting) // export...

From that wiki page I found out how to make a screenshot and by removing the for loop, I was able to get a screenshot that doesn't replace transparent pixels by black pixels.

byte[] pixels = ScreenUtils.getFrameBufferPixels(0, 0, Gdx.graphics.getBackBufferWidth(), Gdx.graphics.getBackBufferHeight(), true); Pixmap pixmap = new Pixmap(Gdx.graphics.getBackBufferWidth(), Gdx.graphics.getBackBufferHeight(), Pixmap.Format.RGBA8888); BufferUtils.copy(pixels, 0, pixmap.getPixels(), pixels.length); PixmapIO.writePNG(Gdx.files.external("mypixmap.png"), pixmap); pixmap.dispose();

It works well for the edges of the entity but not for the multiple parts inside.

Edges: (perfect)

Inside: (should not be transparent)

So I started playing with blending to fix that. With

batch.enableBlending(); batch.setBlendFunction( exporting ? GL20.GL_ONE : GL20.GL_SRC_ALPHA, // exporting is set to true on the frame where the screenshot is taken GL20.GL_ONE_MINUS_SRC_ALPHA);

This improved it a bit:

But with images like glasses that are supposed to be transparent, it's opaque:

Instead of:

Any idea of what I should do to fix this? What I want is pretty standard, a transparent background with semi transparent images on top of it. I want it to behave just like a regular image software would with layers (like GIMP).