// internal use // finish writing to the buffers, mark as not pending anymore. private void endPending() { if (pending1) { buffer1.end(); pending1 = false; } if (pending2) { buffer2.end(); pending2 = false; } }
@Override public void render() { frameBuffer.begin(); Gdx.graphics.getGL20().glViewport(0, 0, frameBuffer.getWidth(), frameBuffer.getHeight()); Gdx.graphics.getGL20().glClearColor(0f, 1f, 0f, 1); Gdx.graphics.getGL20().glClear(GL20.GL_COLOR_BUFFER_BIT); Gdx.graphics.getGL20().glEnable(GL20.GL_TEXTURE_2D); texture.bind(); meshShader.begin(); meshShader.setUniformi("u_texture", 0); mesh.render(meshShader, GL20.GL_TRIANGLES); meshShader.end(); frameBuffer.end(); Gdx.graphics.getGL20().glViewport(0, 0, Gdx.graphics.getWidth(), Gdx.graphics.getHeight()); Gdx.graphics.getGL20().glClearColor(0.2f, 0.2f, 0.2f, 1); Gdx.graphics.getGL20().glClear(GL20.GL_COLOR_BUFFER_BIT); spriteBatch.begin(); spriteBatch.draw( frameBuffer.getColorBufferTexture(), 0, 0, 256, 256, 0, 0, frameBuffer.getColorBufferTexture().getWidth(), frameBuffer.getColorBufferTexture().getHeight(), false, true); spriteBatch.end(); }
protected void renderParticles() { particleFrameBuffer.begin(); batch.begin(); Color initialColor = batch.getColor(); Values<Entity> values = particleEntities.values(); while (values.hasNext()) { Entity entity = values.next(); ParticleComponent particle = entity.getComponent(ParticleComponent.class); ColorComponent color = entity.getComponent(ColorComponent.class); if (color != null) { batch.setColor(color.color); } particle.effect.draw(batch); batch.setColor(initialColor); } batch.end(); particleFrameBuffer.end(); batch.begin(); batch.draw(particleRegion, 0.0f, 0.0f); batch.end(); }
/** Call this after scene. Renders the bloomed scene. */ public void render() { if (capturing) { capturing = false; frameBuffer.end(); } Gdx.gl.glDisable(GL20.GL_BLEND); Gdx.gl.glDisable(GL20.GL_DEPTH_TEST); Gdx.gl.glDepthMask(false); gaussianBlur(); if (blending) { Gdx.gl.glEnable(GL20.GL_BLEND); Gdx.gl.glBlendFunc(GL20.GL_SRC_ALPHA, GL20.GL_ONE_MINUS_SRC_ALPHA); } pingPongTex1.bind(1); original.bind(0); bloomShader.begin(); { fullScreenQuad.render(bloomShader, GL20.GL_TRIANGLE_FAN); } bloomShader.end(); }
private void gaussianBlur() { // cut bright areas of the picture and blit to smaller fbo original.bind(0); pingPongBuffer1.begin(); { tresholdShader.begin(); { // tresholdShader.setUniformi("u_texture0", 0); fullScreenQuad.render(tresholdShader, GL20.GL_TRIANGLE_FAN, 0, 4); } tresholdShader.end(); } pingPongBuffer1.end(); for (int i = 0; i < blurPasses; i++) { pingPongTex1.bind(0); // horizontal pingPongBuffer2.begin(); { blurShader.begin(); { blurShader.setUniformf("dir", 1f, 0f); fullScreenQuad.render(blurShader, GL20.GL_TRIANGLE_FAN, 0, 4); } blurShader.end(); } pingPongBuffer2.end(); pingPongTex2.bind(0); // vertical pingPongBuffer1.begin(); { blurShader.begin(); { blurShader.setUniformf("dir", 0f, 1f); fullScreenQuad.render(blurShader, GL20.GL_TRIANGLE_FAN, 0, 4); } blurShader.end(); } pingPongBuffer1.end(); } }
public final void render() { if (outputBuffer != null) { outputBuffer.begin(); realRender(); outputBuffer.end(); } else { realRender(); } }
public void render(float delta) { updateOrbs(delta); blurTargetA.begin(); Gdx.gl.glClearColor(0.0f, 0.0f, 0.0f, 1f); Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT); batch.setShader(null); // resizeBatch(FBO_SIZE, FBO_SIZE); renderOrbs(OrbPart.Light); blurTargetA.end(); blurTargetB.begin(); Gdx.gl.glClearColor(0.0f, 0.0f, 0.0f, 1f); Gdx.gl.glClear(GL10.GL_COLOR_BUFFER_BIT); batch.setShader(blurShader); batch.begin(); blurShader.setUniformf("dir", 1f, 0f); fboRegion.setTexture(blurTargetA.getColorBufferTexture()); batch.draw(fboRegion, 0, 0); batch.flush(); blurTargetB.end(); generateBackground(delta); Gdx.gl.glClearColor(backgroundColor.r, backgroundColor.g, backgroundColor.b, 0f); Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT); // resizeBatch(Gdx.graphics.getWidth(), Gdx.graphics.getHeight()); batch.end(); // renderOrbs(OrbPart.Dark); batch.begin(); blurShader.setUniformf("dir", 0f, 1f); fboRegion.setTexture(blurTargetB.getColorBufferTexture()); batch.draw(fboRegion, 0, 0); batch.setShader(null); batch.end(); }
public void end() { newFrame.end(); FrameBuffer oldFrame = newFrame; newFrame = cleanFrame; oldFrame.getColorBufferTexture().bind(); { Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT | GL20.GL_DEPTH_BUFFER_BIT); mShaderProgram.begin(); { mScreenMesh.render(mShaderProgram, GL20.GL_TRIANGLE_FAN, 0, 4); } mShaderProgram.end(); } }
@Override public void draw() { // world_darkness.fill(darkness_color); FlxG.batch.end(); frame_buffer.begin(); FlxG.batch.begin(); frame_buffer_fill.draw(); player.drawGlow(); world.firefish_group.callAll("drawGlow"); FlxG.batch.end(); frame_buffer.end(); FlxG.batch.begin(); super.draw(); }
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); 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; }
@Override public void drawChildren(SpriteBatch batch, float parentAlpha) { previousScene.setVisible(true); nextScene.setVisible(false); super.drawChildren(batch, parentAlpha); batch.end(); nextSceneBuffer.begin(); batch.begin(); previousScene.setVisible(false); nextScene.setVisible(true); super.drawChildren(batch, parentAlpha); nextSceneBuffer.end(); batch.flush(); batch.setShader(maskShader); maskShader.setAttributef("a_offset", offset.x, offset.y, offset.z, 0); texture.bind(1); Gdx.gl.glActiveTexture(GL10.GL_TEXTURE0); Gdx.gl.glBindTexture(GL10.GL_TEXTURE_2D, 0); batch.draw(nextSceneBuffer.getColorBufferTexture(), 0, 0); batch.setShader(null); }
public void end() { fbo.end(); }
@Override public void draw(Batch batch, float parentAlpha) { oldPro.set(batch.getProjectionMatrix()); oldView.set(batch.getTransformMatrix()); Rectangle temp = null; if (useFbo) { batch.end(); try { // problem with libgdx, should'nt need try catch. temp = ScissorStack.popScissors(); } catch (IllegalStateException ignored) { } fbo.begin(); Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT); } // camera.setX(camera.getX()+1); // camera.setRotation(camera.getRotation()+2); camera.track(view); camera.apply(ortho); ortho.update(); batch.setProjectionMatrix(ortho.projection); batch.setTransformMatrix(ortho.view); if (useFbo) { batch.begin(); } Iterator<PObject> iter = view.getIterator(); while (iter.hasNext()) { PSprite sprite = (PSprite) iter.next(); sprite.draw(batch, spriteReference); } if (useFbo) { batch.end(); fbo.end(); } batch.setProjectionMatrix(oldPro); batch.setTransformMatrix(oldView); if (useFbo) { if (temp != null) { ScissorStack.pushScissors(temp); } Color oldColor = batch.getColor(); batch.setColor(tint); batch.begin(); batch.draw( fbo.getColorBufferTexture(), 0, 0, getWidth(), getHeight(), 0, 0, fbo.getWidth(), fbo.getHeight(), false, true); batch.setColor(oldColor); } }
/** Pause capturing to fbo. */ public void capturePause() { if (capturing) { capturing = false; frameBuffer.end(); } }