Java Code Examples for com.badlogic.gdx.graphics.g2d.SpriteBatch#dispose()
The following examples show how to use
com.badlogic.gdx.graphics.g2d.SpriteBatch#dispose() .
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: 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 3
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; }