Search in sources :

Example 1 with FrameBuffer

use of com.badlogic.gdx.graphics.glutils.FrameBuffer in project Entitas-Java by Rubentxu.

the class RenderTransition method loadResources.

@Override
public void loadResources() {
    int w = Gdx.graphics.getWidth();
    int h = Gdx.graphics.getHeight();
    nextFbo = new FrameBuffer(Pixmap.Format.RGBA8888, w, h, true);
    currFbo = new FrameBuffer(Pixmap.Format.RGBA8888, w, h, true);
}
Also used : FrameBuffer(com.badlogic.gdx.graphics.glutils.FrameBuffer)

Example 2 with FrameBuffer

use of com.badlogic.gdx.graphics.glutils.FrameBuffer in project libgdx by libgdx.

the class EdgeDetectionTest method create.

public void create() {
    ShaderProgram.pedantic = false;
    /*
		 * shader = new ShaderProgram(Gdx.files.internal("data/shaders/default.vert").readString(), Gdx.files.internal(
		 * "data/shaders/depthtocolor.frag").readString()); if (!shader.isCompiled()) { Gdx.app.log("EdgeDetectionTest",
		 * "couldn't compile scene shader: " + shader.getLog()); }
		 */
    batchShader = new ShaderProgram(Gdx.files.internal("data/shaders/batch.vert").readString(), Gdx.files.internal("data/shaders/convolution.frag").readString());
    if (!batchShader.isCompiled()) {
        Gdx.app.log("EdgeDetectionTest", "couldn't compile post-processing shader: " + batchShader.getLog());
    }
    ObjLoader objLoader = new ObjLoader();
    scene = objLoader.loadModel(Gdx.files.internal("data/scene.obj"));
    sceneInstance = new ModelInstance(scene);
    modelBatch = new ModelBatch();
    fbo = new FrameBuffer(Format.RGB565, Gdx.graphics.getWidth(), Gdx.graphics.getHeight(), true);
    cam = new PerspectiveCamera(67, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
    cam.position.set(0, 0, 10);
    cam.lookAt(0, 0, 0);
    cam.far = 30;
    batch = new SpriteBatch();
    batch.setShader(batchShader);
    fboRegion = new TextureRegion(fbo.getColorBufferTexture());
    fboRegion.flip(false, true);
    logger = new FPSLogger();
    calculateOffsets();
}
Also used : ModelInstance(com.badlogic.gdx.graphics.g3d.ModelInstance) TextureRegion(com.badlogic.gdx.graphics.g2d.TextureRegion) ShaderProgram(com.badlogic.gdx.graphics.glutils.ShaderProgram) ModelBatch(com.badlogic.gdx.graphics.g3d.ModelBatch) ObjLoader(com.badlogic.gdx.graphics.g3d.loader.ObjLoader) PerspectiveCamera(com.badlogic.gdx.graphics.PerspectiveCamera) FrameBuffer(com.badlogic.gdx.graphics.glutils.FrameBuffer) SpriteBatch(com.badlogic.gdx.graphics.g2d.SpriteBatch) FPSLogger(com.badlogic.gdx.graphics.FPSLogger)

Example 3 with FrameBuffer

use of com.badlogic.gdx.graphics.glutils.FrameBuffer in project libgdx by libgdx.

the class FrameBufferTest method create.

@Override
public void create() {
    mesh = new Mesh(true, 3, 0, new VertexAttribute(Usage.Position, 3, "a_Position"), new VertexAttribute(Usage.ColorPacked, 4, "a_Color"), new VertexAttribute(Usage.TextureCoordinates, 2, "a_texCoords"));
    float c1 = Color.toFloatBits(255, 0, 0, 255);
    float c2 = Color.toFloatBits(255, 0, 0, 255);
    float c3 = Color.toFloatBits(0, 0, 255, 255);
    mesh.setVertices(new float[] { -0.5f, -0.5f, 0, c1, 0, 0, 0.5f, -0.5f, 0, c2, 1, 0, 0, 0.5f, 0, c3, 0.5f, 1 });
    stencilMesh = new Mesh(true, 3, 0, new VertexAttribute(Usage.Position, 3, "a_Position"), new VertexAttribute(Usage.ColorPacked, 4, "a_Color"), new VertexAttribute(Usage.TextureCoordinates, 2, "a_texCoords"));
    stencilMesh.setVertices(new float[] { -0.5f, 0.5f, 0, c1, 0, 0, 0.5f, 0.5f, 0, c2, 1, 0, 0, -0.5f, 0, c3, 0.5f, 1 });
    texture = new Texture(Gdx.files.internal("data/badlogic.jpg"));
    spriteBatch = new SpriteBatch();
    frameBuffer = new FrameBuffer(Format.RGB565, 128, 128, false);
    stencilFrameBuffer = new FrameBuffer(Format.RGB565, 128, 128, false, true);
    createShader(Gdx.graphics);
}
Also used : VertexAttribute(com.badlogic.gdx.graphics.VertexAttribute) Mesh(com.badlogic.gdx.graphics.Mesh) FrameBuffer(com.badlogic.gdx.graphics.glutils.FrameBuffer) Texture(com.badlogic.gdx.graphics.Texture) SpriteBatch(com.badlogic.gdx.graphics.g2d.SpriteBatch)

Example 4 with FrameBuffer

use of com.badlogic.gdx.graphics.glutils.FrameBuffer in project libgdx by libgdx.

the class FloatTextureTest method create.

@Override
public void create() {
    fb = new FrameBuffer(Format.RGBA8888, 200, 100, false);
    ffb = new FloatFrameBuffer(200, 100, false);
    // @off
    String vertexShader = "attribute vec4 a_position; " + "varying vec2 v_position; " + "void main(){ " + "    v_position = a_position.xy; " + "    gl_Position = vec4(a_position.x, a_position.y, 0.0, 1.0); " + "}";
    String fragmentShader = "#ifdef GL_ES\n" + "precision mediump float;\n" + "#endif\n" + "uniform vec3 u_color;" + "uniform vec2 u_viewport; " + "void main(void){ " + "    vec2 uv = gl_FragCoord.xy/u_viewport; " + // <--- // regular (non-float) texture loses precision here, res == 0 for every fragment
    "    float res = mix(0.0, 0.0001, uv.x); " + "    gl_FragColor = vec4(u_color, res); " + "}";
    fbshader = new ShaderProgram(vertexShader, fragmentShader);
    vertexShader = "attribute vec4 a_position; " + "attribute vec4 a_color; " + "attribute vec2 a_texCoords; " + "uniform mat4 u_worldView; " + "varying vec4 v_color; " + "varying vec2 v_texCoords; " + "void main() " + "{ " + "    v_color = a_color; " + "    v_texCoords = a_texCoords; " + "    gl_Position =  u_worldView * a_position; " + "}";
    fragmentShader = "#ifdef GL_ES\n" + "precision mediump float;\n" + "#endif\n" + "varying vec2 v_texCoords; " + "uniform sampler2D u_fbtex, u_ffbtex; " + "vec4 getValue(vec4 col) {" + "    if (col.a > 0.00005)" + "        return vec4(col.rgb, 1.0);" + "    else" + "        return vec4(0.0, 0.0, 0.0, 1.0);" + "}" + "void main() " + "{ " + "    if (v_texCoords.y < 0.45)" + "        gl_FragColor = getValue(texture2D(u_fbtex, v_texCoords)); " + "    else if (v_texCoords.y > 0.55)" + "        gl_FragColor = getValue(texture2D(u_ffbtex, v_texCoords)); " + "}";
    // @on
    shader = new ShaderProgram(vertexShader, fragmentShader);
    createQuad();
    screenCamera = new OrthographicCamera(Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
    createScreenQuad();
}
Also used : FloatFrameBuffer(com.badlogic.gdx.graphics.glutils.FloatFrameBuffer) ShaderProgram(com.badlogic.gdx.graphics.glutils.ShaderProgram) OrthographicCamera(com.badlogic.gdx.graphics.OrthographicCamera) FloatFrameBuffer(com.badlogic.gdx.graphics.glutils.FloatFrameBuffer) FrameBuffer(com.badlogic.gdx.graphics.glutils.FrameBuffer)

Example 5 with FrameBuffer

use of com.badlogic.gdx.graphics.glutils.FrameBuffer in project libgdx by libgdx.

the class ClassicalShadowSystem method init2.

protected void init2() {
    frameBuffers[SECOND_PASS] = new FrameBuffer(Pixmap.Format.RGBA8888, Gdx.graphics.getBackBufferWidth(), Gdx.graphics.getBackBufferHeight(), true);
    passShaderProviders[SECOND_PASS] = new Pass2ShaderProvider(new Pass2Shader.Config(this));
}
Also used : FrameBuffer(com.badlogic.gdx.graphics.glutils.FrameBuffer)

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