use of com.badlogic.gdx.graphics.glutils.FrameBuffer in project bladecoder-adventure-engine by bladecoder.
the class SceneList method createBgIcon.
private TextureRegion createBgIcon(String atlas, String region) {
TextureAtlas a = new TextureAtlas(Gdx.files.absolute(Ctx.project.getAssetPath() + Project.ATLASES_PATH + "/1/" + atlas + ".atlas"));
AtlasRegion r = a.findRegion(region);
if (r == null) {
a.dispose();
return null;
}
GLFrameBuffer.FrameBufferBuilder frameBufferBuilder = new GLFrameBuffer.FrameBufferBuilder(200, (int) (r.getRegionHeight() * 200f / r.getRegionWidth()));
frameBufferBuilder.addColorTextureAttachment(GL30.GL_RGBA8, GL30.GL_RGBA, GL30.GL_UNSIGNED_BYTE);
FrameBuffer fbo = frameBufferBuilder.build();
SpriteBatch fboBatch = new SpriteBatch();
fboBatch.setColor(Color.WHITE);
OrthographicCamera camera = new OrthographicCamera();
camera.setToOrtho(false, fbo.getWidth(), fbo.getHeight());
fboBatch.setProjectionMatrix(camera.combined);
Gdx.gl.glDisable(GL20.GL_SCISSOR_TEST);
fbo.begin();
fboBatch.begin();
fboBatch.draw(r, 0, 0, fbo.getWidth(), fbo.getHeight());
fboBatch.end();
TextureRegion tex = ScreenUtils.getFrameBufferTexture(0, 0, fbo.getWidth(), fbo.getHeight());
// tex.flip(false, true);
fbo.end();
Gdx.gl.glEnable(GL20.GL_SCISSOR_TEST);
fbo.dispose();
a.dispose();
fboBatch.dispose();
return tex;
}
use of com.badlogic.gdx.graphics.glutils.FrameBuffer in project bladecoder-adventure-engine by bladecoder.
the class World method takeScreenshot.
public void takeScreenshot(String filename, int w) {
int h = (int) (w * getSceneCamera().viewportHeight / getSceneCamera().viewportWidth);
FrameBuffer fbo = new FrameBuffer(Format.RGB565, w, h, false);
fbo.begin();
Gdx.gl.glClearColor(0, 0, 0, 1);
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
draw();
Pixmap pixmap = ScreenUtils.getFrameBufferPixmap(0, 0, w, h);
fbo.end();
// Flip the pixmap upside down
ByteBuffer pixels = pixmap.getPixels();
int numBytes = w * h * 4;
byte[] lines = new byte[numBytes];
int numBytesPerLine = w * 4;
for (int i = 0; i < h; i++) {
pixels.position((h - i - 1) * numBytesPerLine);
pixels.get(lines, i * numBytesPerLine, numBytesPerLine);
}
pixels.clear();
pixels.put(lines);
PixmapIO.writePNG(EngineAssetManager.getInstance().getUserFile(filename), pixmap);
fbo.dispose();
}
Aggregations