Example usage for com.badlogic.gdx.graphics.glutils FrameBuffer begin

List of usage examples for com.badlogic.gdx.graphics.glutils FrameBuffer begin

Introduction

In this page you can find the example usage for com.badlogic.gdx.graphics.glutils FrameBuffer begin.

Prototype

public void begin() 

Source Link

Document

Binds the frame buffer and sets the viewport accordingly, so everything gets drawn to it.

Usage

From source file:com.agateau.pixelwheels.tools.MapScreenshotGenerator.java

License:Apache License

private static Pixmap generateScreenshot(FileHandle tmxFile) {
    TiledMap map = new TmxMapLoader().load(tmxFile.path());
    TiledMapTileLayer layer = (TiledMapTileLayer) map.getLayers().get(0);
    int mapWidth = (int) (layer.getWidth() * layer.getTileWidth());
    int mapHeight = (int) (layer.getHeight() * layer.getTileHeight());

    FrameBuffer fbo = new FrameBuffer(Pixmap.Format.RGB888, mapWidth, mapHeight, false /* hasDepth */);
    OrthogonalTiledMapRenderer renderer = new OrthogonalTiledMapRenderer(map);

    OrthographicCamera camera = new OrthographicCamera();
    camera.setToOrtho(true /* yDown */, mapWidth, mapHeight);
    renderer.setView(camera);/* w  w  w .  ja v  a  2s  . c  om*/

    fbo.begin();
    renderer.render();

    return ScreenUtils.getFrameBufferPixmap(0, 0, mapWidth, mapHeight);
}

From source file:com.badlogic.gdx.tests.PremultiplyAlpha.java

private void gpuPremultiplyAlpha(String in, String out) {
    Texture texture = new Texture(Gdx.files.absolute(in));
    texture.setFilter(TextureFilter.Nearest, TextureFilter.Nearest);
    FrameBuffer buffer = new FrameBuffer(Format.RGBA8888, texture.getWidth(), texture.getHeight(), false);
    buffer.getColorBufferTexture().setFilter(TextureFilter.Nearest, TextureFilter.Nearest);
    ShaderProgram shader = new ShaderProgram(VERTEX_SHADER, FRAG_SHADER);
    Gdx.app.log("Log", shader.getLog());
    SpriteBatch batch = new SpriteBatch(10);
    batch.getProjectionMatrix().setToOrtho2D(0, 0, texture.getWidth(), texture.getHeight());
    batch.disableBlending();//  ww  w .  ja  v a  2  s. com
    batch.setShader(shader);

    //Premultiply
    buffer.begin();
    Gdx.gl.glClearColor(0, 0, 0, 0);
    Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
    batch.begin();
    batch.draw(texture, 0, 0);
    batch.end();
    Pixmap pixmap = ScreenUtils.getFrameBufferPixmap(0, 0, texture.getWidth(), texture.getHeight());
    buffer.end();

    //Save
    PixmapIO.writePNG(Gdx.files.absolute(out), pixmap);
    buffer.dispose();
    texture.dispose();
    pixmap.dispose();
    Gdx.app.exit();
}

From source file:com.bladecoder.engine.model.World.java

License:Apache License

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();
    draw();/* www  .  ja  v  a2s  .  c o m*/
    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);
}

From source file:com.bladecoder.engineeditor.ui.SceneList.java

License:Apache License

private TextureRegion createBgIcon(String atlas, String region) {
    TextureAtlas a = new TextureAtlas(Gdx.files
            .absolute(Ctx.project.getProjectPath() + "/" + Project.ATLASES_PATH + "/1/" + atlas + ".atlas"));
    AtlasRegion r = a.findRegion(region);

    if (r == null) {
        a.dispose();// w w  w  . j  a  v  a  2 s .  c  om
        return null;
    }

    FrameBuffer fbo = new FrameBuffer(Format.RGBA8888, 200,
            (int) (r.getRegionHeight() * 200f / r.getRegionWidth()), false);

    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;
}

From source file:com.github.skittishSloth.openSkies.maps.PlanetScreen.java

public PlanetScreen() {
    //        final ElevationParameters elevParams = ElevationParameters.buildEvenRanges();
    //        final ElevationParameters elevParams = ElevationParameters.buildByPercent(75, 5, 15, 5, 5);
    final ElevationParameters elevParams = ElevationParameters.buildByEnumValues();
    final LatitudeParameters latParams = LatitudeParameters.getEvenPercentages();
    final TerrainParameters terrainParams = new TerrainParameters(elevParams, latParams, 10, 9, 9);

    final MapGenerator mg = new MapGenerator(terrainParams);
    tileSize = 1;/*ww  w. ja  v a  2 s  .c o  m*/
    width = Gdx.graphics.getWidth() / tileSize;
    height = Gdx.graphics.getHeight() / tileSize;
    tiles = mg.generateTiles(width, height);
    elevationTexture = mg.generateElevationTexture(tiles, width, height, tileSize);
    rawElevationTexture = mg.generateRawElevationTexture(tiles, width, height, tileSize);
    temperatureTexture = mg.generateTemperatureTexture(tiles, width, height, tileSize);
    rainfallTexture = mg.generateRainfallTexture(tiles, width, height, tileSize);
    mineralTexture = mg.generateMineralsTexture(tiles, width, height, tileSize);
    elevationGrayScaleTexture = mg.generateElevationGrayscaleTexture(tiles, width, height, tileSize);

    batch = new SpriteBatch();

    final Texture latColorTexture = mg.generateLatitudeTexture(tiles, width, height, tileSize);
    final FrameBuffer frameBuffer = new FrameBuffer(Pixmap.Format.RGBA8888, width, height, false);
    final OrthographicCamera camera = new OrthographicCamera();
    camera.setToOrtho(true);
    final Matrix4 oldBatchMatrix = batch.getProjectionMatrix();
    batch.setProjectionMatrix(camera.combined);
    frameBuffer.begin();
    batch.begin();
    batch.draw(elevationTexture, 0, 0);
    final Sprite latColorSprite = new Sprite(latColorTexture);
    latColorSprite.setAlpha(0.5f);
    latColorSprite.draw(batch);
    batch.end();
    frameBuffer.end();

    batch.setProjectionMatrix(oldBatchMatrix);
    latitudeTexture = frameBuffer.getColorBufferTexture();
    currentTextureIdx = 0;

    textures.add(elevationTexture);
    textures.add(rawElevationTexture);
    textures.add(elevationGrayScaleTexture);
    textures.add(temperatureTexture);
    textures.add(rainfallTexture);
    textures.add(mineralTexture);
    textures.add(latitudeTexture);
    //        textures.add(zoomedElevationTexture);

    numTextures = textures.size();
}

From source file:com.lyeeedar.Roguelike3D.Game.Level.LevelGraphics.java

License:Open Source License

public void createMap(Tile[][] levelArray) {
    BitmapFont font = new BitmapFont();
    SpriteBatch sB = new SpriteBatch();
    FrameBuffer fB = new FrameBuffer(Format.RGBA4444, width * STEP, height * STEP, false);

    fB.begin();
    sB.begin();//w w  w. ja  v  a  2  s.com
    for (int x = 0; x < width; x++) {
        for (int y = 0; y < height; y++) {
            char c = levelArray[x][y].character;
            if (c == ' ')
                continue;
            font.setColor(colours.get(c));
            font.draw(sB, "" + c, x * STEP, y * STEP);

        }
    }
    sB.end();
    fB.end();

    map = fB.getColorBufferTexture();
}

From source file:com.lyeeedar.Roguelike3D.Graphics.TextureDrawer.java

License:Open Source License

public static Texture drawText(BitmapFont font, int xSpacing, int ySpacing, String... text) {
    int height = ySpacing * (text.length + 2);

    int width = 0;

    int temp;/*from   w  ww  . j  av  a 2s .co  m*/
    for (int i = 0; i < text.length; i++) {
        temp = xSpacing * (text[i].length() + 2);

        if (temp > width)
            width = temp;
    }

    FrameBuffer fB = new FrameBuffer(format, width, height, false);
    fB.begin();

    Gdx.graphics.getGL20().glClearColor(1.0f, 1.0f, 1.0f, 1.0f);
    Gdx.graphics.getGL20().glClear(GL20.GL_COLOR_BUFFER_BIT);

    font.setColor(Color.BLACK);

    sB.begin();
    for (int line = 0; line < text.length; line++) {
        for (int c = 0; c < text[line].length(); c++) {
            font.draw(sB, "" + text[line].charAt(c), c * xSpacing, (line - 1) * ySpacing);
        }
    }
    sB.end();

    fB.end();
    return fB.getColorBufferTexture();
}

From source file:com.lyeeedar.Roguelike3D.Graphics.TextureDrawer.java

License:Open Source License

public static Texture combineTextures(Texture texture1, Color colour1, Texture texture2, Color colour2) {
    int width = texture1.getWidth();
    int height = texture1.getHeight();

    FrameBuffer buffer = new FrameBuffer(format, width, height, false);
    buffer.begin();
    Gdx.graphics.getGL20().glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
    Gdx.graphics.getGL20().glClear(GL20.GL_COLOR_BUFFER_BIT);

    sB.begin();//from  w w  w .  j  a v  a  2s. c o  m
    sB.setColor(colour1);
    sB.draw(texture1, 0, 0, GameData.resolution[0], GameData.resolution[1]);
    sB.end();

    if (texture2 != null) {
        sB.begin();
        sB.setColor(colour2);
        sB.draw(texture2, 0, 0, GameData.resolution[0], GameData.resolution[1]);
        sB.end();
    }

    buffer.end();

    Texture merged = buffer.getColorBufferTexture();

    return merged;

}

From source file:com.mob.dao.objects.Map.java

License:Open Source License

/**
 * Renders a map layer to it's internal FrameBuffer Object
 *
 * @param layer/*  w ww.j a va2  s .c  o m*/
 * @return void
 */
public void renderLayerToBuffer(int layer) {

    int width = (int) (Map.MAX_MAP_SIZE_WIDTH * Map.TILE_PIXEL_WIDTH);
    int height = (int) (Map.MAX_MAP_SIZE_HEIGHT * Map.TILE_PIXEL_HEIGHT);

    OrthographicCamera camera = new OrthographicCamera(width, height);
    camera.setToOrtho(true, width, height);

    FrameBuffer fbo = new FrameBuffer(Pixmap.Format.RGBA8888, width, height, false);
    SpriteBatch sb = new SpriteBatch();
    sb.setProjectionMatrix(camera.combined);
    fbo.begin();

    sb.enableBlending();
    Gdx.gl.glBlendFuncSeparate(GL20.GL_SRC_ALPHA, GL20.GL_ONE_MINUS_SRC_ALPHA, GL20.GL_ONE,
            GL20.GL_ONE_MINUS_SRC_ALPHA);
    Gdx.gl.glViewport(0, 0, width, height);
    Gdx.gl.glClearColor(0, 0, 0, 0);
    Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);

    sb.begin();
    this.renderLayer(sb, layer);
    sb.end();

    fbo.end();
    this.bufferedLayer = fbo.getColorBufferTexture();
}

From source file:es.eucm.ead.editor.control.actions.editor.CreateSceneThumbnail.java

License:Open Source License

private FrameBuffer drawActor(Actor actor) {
    root.addActor(actor);//w  w  w .ja  va2  s  . co m

    int width = (int) (Gdx.graphics.getHeight() - Gdx.graphics.getDensity() * 56);
    int height = (int) (Gdx.graphics.getHeight() / 2.15f);

    FrameBuffer frameBuffer = new FrameBuffer(Format.RGB888, width, height, false);
    frameBuffer.begin();

    Gdx.gl.glClearColor(1f, 1f, 1f, 1f);
    Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
    batch.begin();
    root.draw(batch, 1.0f);
    batch.end();
    frameBuffer.end();
    batch.setColor(Color.WHITE);
    return frameBuffer;
}