List of usage examples for com.badlogic.gdx.graphics.glutils FrameBuffer getColorBufferTexture
public Texture getColorBufferTexture()
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 . j a v a2 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.bitfire.postprocessing.effects.Bloom.java
License:Apache License
@Override public void render(final FrameBuffer src, final FrameBuffer dest) { Texture texsrc = src.getColorBufferTexture(); boolean blendingWasEnabled = PostProcessor.isStateEnabled(GL20.GL_BLEND); Gdx.gl.glDisable(GL20.GL_BLEND);/* www . j av a 2 s .c o m*/ pingPongBuffer.begin(); { // threshold / high-pass filter // only areas with pixels >= threshold are blit to smaller fbo threshold.setInput(texsrc).setOutput(pingPongBuffer.getSourceBuffer()).render(); // blur pass blur.render(pingPongBuffer); } pingPongBuffer.end(); if (blending || blendingWasEnabled) { Gdx.gl.glEnable(GL20.GL_BLEND); } if (blending) { Gdx.gl.glBlendFunc(sfactor, dfactor); } // mix original scene and blurred threshold, modulate via // set(Base|Bloom)(Saturation|Intensity) combine.setOutput(dest).setInput(texsrc, pingPongBuffer.getResultTexture()).render(); }
From source file:com.bitfire.postprocessing.effects.CrtMonitor.java
License:Apache License
@Override public void render(FrameBuffer src, FrameBuffer dest) { // the original scene Texture in = src.getColorBufferTexture(); boolean blendingWasEnabled = PostProcessor.isStateEnabled(GL20.GL_BLEND); Gdx.gl.glDisable(GL10.GL_BLEND);/*from w ww . jav a 2 s .co m*/ Texture out = null; if (doblur) { pingPongBuffer.begin(); { // crt pass crt.setInput(in).setOutput(pingPongBuffer.getSourceBuffer()).render(); // blur pass blur.render(pingPongBuffer); } pingPongBuffer.end(); out = pingPongBuffer.getResultTexture(); } else { // crt pass crt.setInput(in).setOutput(buffer).render(); out = buffer.getColorBufferTexture(); } if (blending || blendingWasEnabled) { Gdx.gl.glEnable(GL20.GL_BLEND); } if (blending) { Gdx.gl.glBlendFunc(sfactor, dfactor); } // do combine pass combine.setOutput(dest).setInput(in, out).render(); }
From source file:com.bitfire.postprocessing.effects.LensFlare2.java
License:Apache License
@Override public void render(final FrameBuffer src, final FrameBuffer dest) { Texture texsrc = src.getColorBufferTexture(); boolean blendingWasEnabled = PostProcessor.isStateEnabled(GL20.GL_BLEND); Gdx.gl.glDisable(GL20.GL_BLEND);// www . jav a2 s.c om pingPongBuffer.begin(); { // apply bias bias.setInput(texsrc).setOutput(pingPongBuffer.getSourceBuffer()).render(); lens.setInput(pingPongBuffer.getSourceBuffer()).setOutput(pingPongBuffer.getResultBuffer()).render(); pingPongBuffer.set(pingPongBuffer.getResultBuffer(), pingPongBuffer.getSourceBuffer()); // blur pass blur.render(pingPongBuffer); } pingPongBuffer.end(); if (blending || blendingWasEnabled) { Gdx.gl.glEnable(GL20.GL_BLEND); } if (blending) { Gdx.gl.glBlendFunc(sfactor, dfactor); } restoreViewport(dest); // mix original scene and blurred threshold, modulate via combine.setOutput(dest).setInput(texsrc, pingPongBuffer.getResultTexture()).render(); }
From source file:com.bitfire.postprocessing.effects.LightGlow.java
License:Apache License
@Override public void render(final FrameBuffer src, final FrameBuffer dest) { Texture texsrc = src.getColorBufferTexture(); boolean blendingWasEnabled = PostProcessor.isStateEnabled(GL20.GL_BLEND); Gdx.gl.glDisable(GL20.GL_BLEND);/*from ww w.ja va 2 s. com*/ pingPongBuffer.begin(); { // apply bias bias.setInput(texsrc).setOutput(pingPongBuffer.getSourceBuffer()).render(); glow.setInput(pingPongBuffer.getSourceBuffer()).setOutput(pingPongBuffer.getResultBuffer()).render(); } pingPongBuffer.end(); if (blending || blendingWasEnabled) { Gdx.gl.glEnable(GL20.GL_BLEND); } if (blending) { Gdx.gl.glBlendFunc(sfactor, dfactor); } restoreViewport(dest); // mix original scene and blurred threshold, modulate via combine.setOutput(dest).setInput(texsrc, pingPongBuffer.getResultTexture()).render(); }
From source file:com.bitfire.postprocessing.effects.LightScattering.java
License:Apache License
@Override public void render(final FrameBuffer src, final FrameBuffer dest) { Texture texsrc = src.getColorBufferTexture(); boolean blendingWasEnabled = PostProcessor.isStateEnabled(GL20.GL_BLEND); Gdx.gl.glDisable(GL20.GL_BLEND);/* ww w .j a v a2 s. co m*/ pingPongBuffer.begin(); { // apply bias bias.setInput(texsrc).setOutput(pingPongBuffer.getSourceBuffer()).render(); scattering.setInput(pingPongBuffer.getSourceBuffer()).setOutput(pingPongBuffer.getResultBuffer()) .render(); pingPongBuffer.set(pingPongBuffer.getResultBuffer(), pingPongBuffer.getSourceBuffer()); // blur pass blur.render(pingPongBuffer); } pingPongBuffer.end(); if (blending || blendingWasEnabled) { Gdx.gl.glEnable(GL20.GL_BLEND); } if (blending) { Gdx.gl.glBlendFunc(sfactor, dfactor); } restoreViewport(dest); // mix original scene and blurred threshold, modulate via combine.setOutput(dest).setInput(texsrc, pingPongBuffer.getResultTexture()).render(); }
From source file:com.bitfire.postprocessing.filters.Combine.java
License:Apache License
public Combine setInput(FrameBuffer buffer1, FrameBuffer buffer2) { this.inputTexture = buffer1.getColorBufferTexture(); this.inputTexture2 = buffer2.getColorBufferTexture(); return this; }
From source file:com.bitfire.postprocessing.filters.CubemapEquirectangularFilter.java
License:Apache License
public void setSides(FrameBuffer xpositive, FrameBuffer xnegative, FrameBuffer ypositive, FrameBuffer ynegative, FrameBuffer zpositive, FrameBuffer znegative) { cubemapSides = new TextureData[6]; cubemapSides[0] = xpositive.getColorBufferTexture().getTextureData(); cubemapSides[1] = xnegative.getColorBufferTexture().getTextureData(); cubemapSides[2] = ypositive.getColorBufferTexture().getTextureData(); cubemapSides[3] = ynegative.getColorBufferTexture().getTextureData(); cubemapSides[4] = zpositive.getColorBufferTexture().getTextureData(); cubemapSides[5] = znegative.getColorBufferTexture().getTextureData(); FrameBuffer[] fbos = new FrameBuffer[6]; fbos[0] = xpositive;//from www .j av a 2 s.c o m fbos[1] = xnegative; fbos[2] = ypositive; fbos[3] = ynegative; fbos[4] = zpositive; fbos[5] = znegative; if (cmId < 0) cmId = Gdx.gl.glGenTexture(); // Make active Gdx.gl.glActiveTexture(GL20.GL_TEXTURE0 + u_texture1); Gdx.gl.glBindTexture(GL20.GL_TEXTURE_CUBE_MAP, cmId); // Call glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X + i) for all sides for (int i = 0; i < cubemapSides.length; i++) { if (cubemapSides[i].getType() == TextureData.TextureDataType.Custom) { cubemapSides[i].consumeCustomData(GL20.GL_TEXTURE_CUBE_MAP_POSITIVE_X + i); } } for (int i = 0; i < cubemapSides.length; i++) { fbos[i].begin(); Gdx.gl.glFramebufferTexture2D(GL20.GL_FRAMEBUFFER, GL20.GL_COLOR_ATTACHMENT0, GL20.GL_TEXTURE_CUBE_MAP_POSITIVE_X + i, cmId, 0); fbos[i].end(); } Gdx.gl.glTexParameteri(GL20.GL_TEXTURE_CUBE_MAP, GL20.GL_TEXTURE_MAG_FILTER, GL20.GL_LINEAR); Gdx.gl.glTexParameteri(GL20.GL_TEXTURE_CUBE_MAP, GL20.GL_TEXTURE_MIN_FILTER, GL20.GL_LINEAR); Gdx.gl.glTexParameteri(GL20.GL_TEXTURE_CUBE_MAP, GL20.GL_TEXTURE_WRAP_S, GL20.GL_CLAMP_TO_EDGE); Gdx.gl.glTexParameteri(GL20.GL_TEXTURE_CUBE_MAP, GL20.GL_TEXTURE_WRAP_T, GL20.GL_CLAMP_TO_EDGE); Gdx.gl.glBindTexture(GL20.GL_TEXTURE_CUBE_MAP, 0); setParam(Param.Cubemap, u_texture1); }
From source file:com.bitfire.postprocessing.filters.Filter.java
License:Apache License
public T setInput(FrameBuffer input) { return setInput(input.getColorBufferTexture()); }
From source file:com.blastedstudios.ledge.ui.postprocessing.effects.Bloom.java
License:Apache License
@Override public void render(final FrameBuffer src, final FrameBuffer dest) { Texture texsrc = src.getColorBufferTexture(); boolean blendingWasEnabled = PostProcessor.isStateEnabled(GL20.GL_BLEND); Gdx.gl.glDisable(GL20.GL_BLEND);//from w w w . j a v a 2 s . c o m pingPongBuffer.begin(); { // threshold / high-pass filter // only areas with pixels >= threshold are blit to smaller fbo threshold.setInput(texsrc).setOutput(pingPongBuffer.getSourceBuffer()).render(); // blur pass blur.render(pingPongBuffer); } pingPongBuffer.end(); if (blending || blendingWasEnabled) { Gdx.gl.glEnable(GL20.GL_BLEND); } if (blending) { // TODO support for Gdx.gl.glBlendFuncSeparate(sfactor, dfactor, GL20.GL_ONE, GL20.GL_ONE ); Gdx.gl.glBlendFunc(sfactor, dfactor); } restoreViewport(dest); // mix original scene and blurred threshold, modulate via // set(Base|Bloom)(Saturation|Intensity) combine.setOutput(dest).setInput(texsrc, pingPongBuffer.getResultTexture()).render(); }