/** Creates a render target that renders to {@code texture}. */ public static RenderTarget create (Graphics gfx, final Texture tex) { GL20 gl = gfx.gl; final int fb = gl.glGenFramebuffer(); if (fb == 0) throw new RuntimeException("Failed to gen framebuffer: " + gl.glGetError()); gl.glBindFramebuffer(GL_FRAMEBUFFER, fb); gl.glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, tex.id, 0); gl.checkError("RenderTarget.create"); return new RenderTarget (gfx) { public int id () { return fb; } public int width () { return tex.pixelWidth; } public int height () { return tex.pixelHeight; } public float xscale () { return tex.pixelWidth / tex.displayWidth; } public float yscale () { return tex.pixelHeight / tex.displayHeight; } public boolean flip () { return false; } }; }
/** Creates a render target that renders to {@code texture}. */ public static RenderTarget create (Graphics gfx, final Texture tex) { GL20 gl = gfx.gl; final int fb = gl.glGenFramebuffer(); if (fb == 0) throw new RuntimeException("Failed to gen framebuffer: " + gl.glGetError()); gl.glBindFramebuffer(GL_FRAMEBUFFER, fb); gl.glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, tex.id, 0); gl.checkError("RenderTarget.create"); return new RenderTarget (gfx) { public int id () { return fb; } public int width () { return tex.pixelWidth; } public int height () { return tex.pixelHeight; } public float xscale () { return tex.pixelWidth / tex.displayWidth; } public float yscale () { return tex.pixelHeight / tex.displayHeight; } public boolean flip () { return false; } }; }
/** Binds the framebuffer. */ public void bind () { gfx.gl.glBindFramebuffer(GL_FRAMEBUFFER, id()); gfx.gl.glViewport(0, 0, width(), height()); }
/** Binds the framebuffer. */ public void bind () { gfx.gl.glBindFramebuffer(GL_FRAMEBUFFER, id()); gfx.gl.glViewport(0, 0, width(), height()); }