com.badlogic.gdx.utils.ScreenUtils Java Examples
The following examples show how to use
com.badlogic.gdx.utils.ScreenUtils.
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: ScreenshotService.java From talos with Apache License 2.0 | 6 votes |
private void takeScreenshot() { byte[] pixels = ScreenUtils.getFrameBufferPixels(0, 0, Gdx.graphics.getBackBufferWidth(), Gdx.graphics.getBackBufferHeight(), true); float scaleX = (float)Gdx.graphics.getBackBufferWidth()/Gdx.graphics.getWidth(); float scaleY = (float)Gdx.graphics.getBackBufferHeight()/Gdx.graphics.getHeight(); // This loop makes sure the whole screenshot is opaque and looks exactly like what the user is seeing for (int i = 4; i < pixels.length; i += 4) { pixels[i - 1] = (byte) 255; } Pixmap pixmap = new Pixmap(Gdx.graphics.getBackBufferWidth(), Gdx.graphics.getBackBufferHeight(), Pixmap.Format.RGBA8888); BufferUtils.copy(pixels, 0, pixmap.getPixels(), pixels.length); color.set(pixmap.getPixel((int)(posX * scaleX), (int)(posY * scaleY))); pixmap.dispose(); }
Example #2
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 #3
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 #4
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 #5
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 #6
Source File: Screenshot.java From Cubes with MIT License | 5 votes |
@Override public void frameEnd() { if (!state.compareAndSet(1, 2)) return; Pixmap pixmap = ScreenUtils.getFrameBufferPixmap(0, 0, screenshotWidth, screenshotHeight); frameBuffer.end(); Adapter.getInterface().resize(oldWidth, oldHeight); writeScreenshot(pixmap); }
Example #7
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; }
Example #8
Source File: Screenshot.java From Cubes with MIT License | 4 votes |
@Override public void frameEnd() { Pixmap pixmap = ScreenUtils.getFrameBufferPixmap(0, 0, Graphics.RENDER_WIDTH, Graphics.RENDER_HEIGHT); writeScreenshot(pixmap); }