Java Code Examples for com.badlogic.gdx.graphics.glutils.FrameBuffer#end()
The following examples show how to use
com.badlogic.gdx.graphics.glutils.FrameBuffer#end() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: GLTFBinaryExporter.java From gdx-gltf with Apache License 2.0 | 6 votes |
public void export(GLTFImage image, Texture texture, String baseName) { String fileName = baseName + ".png"; image.uri = fileName; FileHandle file = folder.child(fileName); FrameBuffer fbo = new FrameBuffer(texture.getTextureData().getFormat(), texture.getWidth(), texture.getHeight(), false); fbo.begin(); Gdx.gl.glClearColor(0, 0, 0, 0); Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT); SpriteBatch batch = new SpriteBatch(); batch.getProjectionMatrix().setToOrtho2D(0, 0, 1, 1); batch.setBlendFunction(GL20.GL_SRC_ALPHA, GL20.GL_ONE); batch.begin(); batch.draw(texture, 0, 0, 1, 1, 0, 0, 1, 1); batch.end(); Pixmap pixmap = ScreenUtils.getFrameBufferPixmap(0, 0, texture.getWidth(), texture.getHeight()); fbo.end(); batch.dispose(); fbo.dispose(); savePNG(file, pixmap); pixmap.dispose(); }
Example 2
Source File: GameScreenUI.java From uracer-kotd with Apache License 2.0 | 6 votes |
public void render (FrameBuffer dest) { if (!enabled) return; ui.act(URacer.Game.getLastDeltaSecs() /* Config.Physics.Dt */); boolean hasDest = (dest != null); if (hasDest) { ui.getViewport().update(dest.getWidth(), dest.getHeight(), true); dest.begin(); } else { ui.getViewport().update(Gdx.graphics.getWidth(), Gdx.graphics.getHeight(), true); } ui.draw(); if (hasDest) { dest.end(); } }
Example 3
Source File: UIScreen.java From uracer-kotd with Apache License 2.0 | 6 votes |
@Override public void render (FrameBuffer dest) { boolean hasDest = (dest != null); if (hasDest) { ui.getViewport().update(dest.getWidth(), dest.getHeight(), true); dest.begin(); } else { ui.getViewport().update(Gdx.graphics.getWidth(), Gdx.graphics.getHeight(), true); } draw(); if (hasDest) { dest.end(); } }
Example 4
Source File: IBLBuilder.java From gdx-gltf with Apache License 2.0 | 5 votes |
/** * Creates an radiance map, to be used with {@link net.mgsx.gltf.scene3d.attributes.PBRCubemapAttribute#SpecularEnv} * generated cubemap contains mipmaps in order to perform roughness in PBR shading * @param levels mipMapLevels how many mipmaps level, eg. 10 levels produce a 1024x1024 cubemap with mipmaps. * @return generated cubemap, caller is responsible to dispose it when no longer used. */ public Cubemap buildRadianceMap(final int mipMapLevels){ Pixmap[] maps = new Pixmap[mipMapLevels * 6]; int index = 0; for(int level=0 ; level<mipMapLevels ; level++){ int size = 1 << (mipMapLevels - level - 1); FrameBuffer fbo = new FrameBuffer(Format.RGBA8888, size, size, false); fbo.begin(); for(int s=0 ; s<6 ; s++){ Gdx.gl.glClearColor(0, 0, 0, 0); Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT); CubemapSide side = CubemapSide.values()[s]; float blur = (float)level / (float)mipMapLevels; renderGradient(side, blur); renderLights(side, false); maps[index] = ScreenUtils.getFrameBufferPixmap(0, 0, size, size); index++; } fbo.end(); fbo.dispose(); } FacedMultiCubemapData data = new FacedMultiCubemapData(maps, mipMapLevels); Cubemap map = new Cubemap(data); map.setFilter(TextureFilter.MipMap, TextureFilter.Linear); return map; }
Example 5
Source File: ScreenUtils.java From uracer-kotd with Apache License 2.0 | 5 votes |
/** Clear the specified buffer. */ public static void clear (FrameBuffer buffer, Color clearColor, float clearDepth, boolean useDepth) { Gdx.gl20.glClearColor(clearColor.r, clearColor.g, clearColor.b, clearColor.a); buffer.begin(); { if (useDepth) { Gdx.gl20.glClearDepthf(clearDepth); Gdx.gl20.glClear(GL20.GL_COLOR_BUFFER_BIT | GL20.GL_DEPTH_BUFFER_BIT); } else { Gdx.gl20.glClear(GL20.GL_COLOR_BUFFER_BIT); } } buffer.end(); }
Example 6
Source File: World.java From bladecoder-adventure-engine with Apache License 2.0 | 5 votes |
public void takeScreenshot(String filename, int w) { // get viewport IntBuffer results = BufferUtils.newIntBuffer(16); Gdx.gl20.glGetIntegerv(GL20.GL_VIEWPORT, results); int h = (int) (w * getSceneCamera().viewportHeight / getSceneCamera().viewportWidth); FrameBuffer fbo = new FrameBuffer(Format.RGB565, w, h, false); fbo.begin(); Gdx.gl.glClearColor(0, 0, 0, 1); Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT); draw(); Pixmap pixmap = ScreenUtils.getFrameBufferPixmap(0, 0, w, h); // restore viewport fbo.end(results.get(0), results.get(1), results.get(2), results.get(3)); // Flip the pixmap upside down ByteBuffer pixels = pixmap.getPixels(); int numBytes = w * h * 4; byte[] lines = new byte[numBytes]; int numBytesPerLine = w * 4; for (int i = 0; i < h; i++) { pixels.position((h - i - 1) * numBytesPerLine); pixels.get(lines, i * numBytesPerLine, numBytesPerLine); } pixels.clear(); pixels.put(lines); PixmapIO.writePNG(EngineAssetManager.getInstance().getUserFile(filename), pixmap); fbo.dispose(); }
Example 7
Source File: SceneList.java From bladecoder-adventure-engine with Apache License 2.0 | 5 votes |
private TextureRegion createBgIcon(String atlas, String region) { TextureAtlas a = new TextureAtlas( Gdx.files.absolute(Ctx.project.getAssetPath() + Project.ATLASES_PATH + "/1/" + atlas + ".atlas")); AtlasRegion r = a.findRegion(region); if (r == null) { a.dispose(); return null; } GLFrameBuffer.FrameBufferBuilder frameBufferBuilder = new GLFrameBuffer.FrameBufferBuilder(200, (int) (r.getRegionHeight() * 200f / r.getRegionWidth())); frameBufferBuilder.addColorTextureAttachment(GL30.GL_RGBA8, GL30.GL_RGBA, GL30.GL_UNSIGNED_BYTE); FrameBuffer fbo = frameBufferBuilder.build(); 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; }
Example 8
Source File: Ssao.java From uracer-kotd with Apache License 2.0 | 4 votes |
@Override public void render (final FrameBuffer src, final FrameBuffer dest) { Texture tsrc = src.getColorBufferTexture(); Gdx.gl.glDisable(GL20.GL_CULL_FACE); Gdx.gl.glDisable(GL20.GL_DEPTH_TEST); Camera cam = GameEvents.gameRenderer.camPersp; mtxRot.set(cam.view); invPrj.set(cam.projection).inv(); // invRot.set(mtxRot).inv(); occlusionMap.begin(); occlusionMap.capture(); { shSsao.begin(); { Gdx.gl.glClearColor(0, 0, 0, 1); Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT); // samplers normalDepthMap.bind(0); randomField.bind(1); shSsao.setUniformi("normaldepth", 0); shSsao.setUniformi("random_field", 1); shSsao.setUniformMatrix("proj", cam.projection); shSsao.setUniformMatrix("inv_proj", invPrj); shSsao.setUniformMatrix("inv_rot", invRot); shSsao.setUniformf("viewport", occlusionMap.width, occlusionMap.height); shSsao.setUniformf("near", cam.near); shSsao.setUniformf("far", cam.far); quad.render(shSsao); } shSsao.end(); // blur pass blur.render(occlusionMap); } occlusionMap.end(); restoreViewport(dest); if (dest != null) dest.begin(); shMix.begin(); { tsrc.bind(0); occlusionMap.getResultTexture().bind(1); shMix.setUniformi("scene", 0); shMix.setUniformi("occlusion_map", 1); quad.render(shMix); } shMix.end(); if (dest != null) dest.end(); }
Example 9
Source File: LightMap.java From uracer-kotd with Apache License 2.0 | 4 votes |
public void render( Rectangle viewport, FrameBuffer dest ) { boolean needed = rayHandler.lightRenderedLastFrame > 0; // this way lot less binding if( needed && rayHandler.blur ) gaussianBlur(); frameBuffer.getColorBufferTexture().bind( 0 ); if( dest != null ) { dest.begin(); } else { Gdx.gl.glViewport( (int)viewport.x, (int)viewport.y, (int)viewport.width, (int)viewport.height ); } Gdx.gl20.glEnable( GL20.GL_BLEND ); // at last lights are rendered over scene if( rayHandler.shadows ) { final Color c = rayHandler.ambientLight; ShaderProgram shader = shadowShader; if( RayHandler.isDiffuse ) { shader = diffuseShader; shader.begin(); Gdx.gl20.glBlendFunc( GL20.GL_DST_COLOR, GL20.GL_SRC_COLOR ); shader.setUniformf( "ambient", c.r, c.g, c.b, c.a ); } else { shader.begin(); Gdx.gl20.glBlendFunc( GL20.GL_ONE, GL20.GL_ONE_MINUS_SRC_ALPHA ); shader.setUniformf( "ambient", c.r * c.a, c.g * c.a, c.b * c.a, 1f - c.a ); } // shader.setUniformi( "u_texture", 0 ); lightMapMesh.render( shader, GL20.GL_TRIANGLE_FAN ); shader.end(); } else if( needed ) { Gdx.gl.glBlendFunc( GL20.GL_SRC_ALPHA, GL20.GL_ONE ); withoutShadowShader.begin(); // withoutShadowShader.setUniformi( "u_texture", 0 ); lightMapMesh.render( withoutShadowShader, GL20.GL_TRIANGLE_FAN ); withoutShadowShader.end(); } if( dest != null ) dest.end(); }
Example 10
Source File: ShareChallenge.java From Klooni1010 with GNU General Public License v3.0 | 4 votes |
public boolean saveChallengeImage(final int score, final boolean timeMode) { final File saveAt = getShareImageFilePath(); if (!saveAt.getParentFile().isDirectory()) if (!saveAt.mkdirs()) return false; final FileHandle output = new FileHandle(saveAt); final Texture shareBase = new Texture(Gdx.files.internal("share.png")); final int width = shareBase.getWidth(); final int height = shareBase.getHeight(); final FrameBuffer frameBuffer = new FrameBuffer(Pixmap.Format.RGB888, width, height, false); frameBuffer.begin(); // Render the base share texture final SpriteBatch batch = new SpriteBatch(); final Matrix4 matrix = new Matrix4(); matrix.setToOrtho2D(0, 0, width, height); batch.setProjectionMatrix(matrix); Gdx.gl.glClearColor(Color.GOLD.r, Color.GOLD.g, Color.GOLD.b, 1); Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT); batch.begin(); batch.draw(shareBase, 0, 0); // Render the achieved score final Label.LabelStyle style = new Label.LabelStyle(); style.font = new BitmapFont(Gdx.files.internal("font/x1.0/geosans-light64.fnt")); Label label = new Label("just scored " + score + " on", style); label.setColor(Color.BLACK); label.setPosition(40, 500); label.draw(batch, 1); label.setText("try to beat me if you can"); label.setPosition(40, 40); label.draw(batch, 1); if (timeMode) { Texture timeModeTexture = new Texture("ui/x1.5/stopwatch.png"); batch.setColor(Color.BLACK); batch.draw(timeModeTexture, 200, 340); } batch.end(); // Get the framebuffer pixels and write them to a local file final byte[] pixels = ScreenUtils.getFrameBufferPixels(0, 0, width, height, true); final Pixmap pixmap = new Pixmap(width, height, Pixmap.Format.RGBA8888); BufferUtils.copy(pixels, 0, pixmap.getPixels(), pixels.length); PixmapIO.writePNG(output, pixmap); // Dispose everything pixmap.dispose(); shareBase.dispose(); batch.dispose(); frameBuffer.end(); return true; }