Search in sources :

Example 6 with FrameBuffer

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;
}
Also used : TextureRegion(com.badlogic.gdx.graphics.g2d.TextureRegion) TextureAtlas(com.badlogic.gdx.graphics.g2d.TextureAtlas) OrthographicCamera(com.badlogic.gdx.graphics.OrthographicCamera) AtlasRegion(com.badlogic.gdx.graphics.g2d.TextureAtlas.AtlasRegion) FrameBuffer(com.badlogic.gdx.graphics.glutils.FrameBuffer) GLFrameBuffer(com.badlogic.gdx.graphics.glutils.GLFrameBuffer) GLFrameBuffer(com.badlogic.gdx.graphics.glutils.GLFrameBuffer) SpriteBatch(com.badlogic.gdx.graphics.g2d.SpriteBatch)

Example 7 with FrameBuffer

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();
}
Also used : FrameBuffer(com.badlogic.gdx.graphics.glutils.FrameBuffer) ByteBuffer(java.nio.ByteBuffer) Pixmap(com.badlogic.gdx.graphics.Pixmap)

Aggregations

FrameBuffer (com.badlogic.gdx.graphics.glutils.FrameBuffer)7 SpriteBatch (com.badlogic.gdx.graphics.g2d.SpriteBatch)3 OrthographicCamera (com.badlogic.gdx.graphics.OrthographicCamera)2 TextureRegion (com.badlogic.gdx.graphics.g2d.TextureRegion)2 ShaderProgram (com.badlogic.gdx.graphics.glutils.ShaderProgram)2 FPSLogger (com.badlogic.gdx.graphics.FPSLogger)1 Mesh (com.badlogic.gdx.graphics.Mesh)1 PerspectiveCamera (com.badlogic.gdx.graphics.PerspectiveCamera)1 Pixmap (com.badlogic.gdx.graphics.Pixmap)1 Texture (com.badlogic.gdx.graphics.Texture)1 VertexAttribute (com.badlogic.gdx.graphics.VertexAttribute)1 TextureAtlas (com.badlogic.gdx.graphics.g2d.TextureAtlas)1 AtlasRegion (com.badlogic.gdx.graphics.g2d.TextureAtlas.AtlasRegion)1 ModelBatch (com.badlogic.gdx.graphics.g3d.ModelBatch)1 ModelInstance (com.badlogic.gdx.graphics.g3d.ModelInstance)1 ObjLoader (com.badlogic.gdx.graphics.g3d.loader.ObjLoader)1 FloatFrameBuffer (com.badlogic.gdx.graphics.glutils.FloatFrameBuffer)1 GLFrameBuffer (com.badlogic.gdx.graphics.glutils.GLFrameBuffer)1 ByteBuffer (java.nio.ByteBuffer)1