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

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

Introduction

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

Prototype

public void dispose() 

Source Link

Document

Releases all resources associated with the FrameBuffer.

Usage

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();//  w  w  w  . java2 s. co  m
    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.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  va  2  s . com
        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:org.illarion.engine.backend.gdx.GdxScene.java

License:Open Source License

/**
 * Check if a frame buffer is fitting the requirements.
 *
 * @param width    the width the image needs to have
 * @param height   the height the image needs to have
 * @param original the original image, if this is {@code null} a new image will be created
 * @return the image fitting the requirements
 *///  w  w  w .  j a  v a2s.c o m
@Nonnull
private static FrameBuffer validateFrameBuffer(final int width, final int height,
        @Nullable final FrameBuffer original) {
    if (original == null) {
        return new FrameBuffer(Pixmap.Format.RGBA8888, width, height, false);
    }
    if ((original.getHeight() == height) && (original.getWidth() == width)) {
        return original;
    }
    original.dispose();
    return new FrameBuffer(Pixmap.Format.RGBA8888, width, height, false);
}