List of usage examples for com.badlogic.gdx.graphics Pixmap getPixels
public ByteBuffer getPixels()
From source file:com.badlogic.gdx.tests.g3d.HeightField.java
public void set(final Pixmap map) { if (map.getWidth() != width || map.getHeight() != height) throw new GdxRuntimeException("Incorrect map size"); set(map.getPixels(), map.getFormat()); }
From source file:com.badlogic.gdx.tests.g3d.voxel.PerlinNoiseGenerator.java
License:Apache License
public static Pixmap generatePixmap(int width, int height, int min, int max, int octaveCount) { byte[] bytes = generateHeightMap(width, height, min, max, octaveCount); Pixmap pixmap = new Pixmap(width, height, Format.RGBA8888); for (int i = 0, idx = 0; i < bytes.length; i++) { byte val = bytes[i]; pixmap.getPixels().put(idx++, val); pixmap.getPixels().put(idx++, val); pixmap.getPixels().put(idx++, val); pixmap.getPixels().put(idx++, (byte) 255); }/*from ww w . j a va 2 s . c o m*/ return pixmap; }
From source file:com.bladecoder.engine.model.World.java
License:Apache License
public void takeScreenshot(String filename, int w) { int h = (int) (w * getSceneCamera().viewportHeight / getSceneCamera().viewportWidth); FrameBuffer fbo = new FrameBuffer(Format.RGB565, w, h, false); fbo.begin();/*from ww w . j a v a 2s .co m*/ draw(); Pixmap pixmap = ScreenUtils.getFrameBufferPixmap(0, 0, w, h); fbo.end(); // 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); }
From source file:com.explatcreations.sft.Game.java
License:Open Source License
private static void setIcons() { if (os == HardwareInfo.OS.Windows) { final Pixmap small = Game.assets.SmallIcon; final Pixmap medium = Game.assets.MediumIcon; Display.setIcon(new ByteBuffer[] { small.getPixels(), medium.getPixels() }); } else if (os == HardwareInfo.OS.Mac) { final Pixmap large = Game.assets.LargeIcon; Display.setIcon(new ByteBuffer[] { large.getPixels() }); } else {//from ww w. jav a 2 s .co m final Pixmap medium = Game.assets.MediumIcon; Display.setIcon(new ByteBuffer[] { medium.getPixels() }); } }
From source file:com.github.unluckyninja.mousekiller.graphics.TextRenderer.java
License:Open Source License
/** * ????/*from w w w . j ava 2s .c o m*/ * * @param i */ public void readTextures(int i) { if (pixmaps[i] != null) { return; } String s = String.format("res/textures/font/unicode_page_%02X.png", new Object[] { Integer.valueOf(i) }); FileHandle file = Gdx.files.internal(s); if (file.exists()) { try { BufferedImage image = ImageIO.read(file.read()); Pixmap map = new Pixmap(256, 256, Pixmap.Format.RGBA8888); int[] colors = new int[65536]; for (int j = 0; j < 65536; j++) { colors[j] = 0; } image.getData().getPixels(0, 0, 256, 256, (int[]) colors); ByteBuffer pixels = map.getPixels(); pixels.clear(); pixels.put(readColor(colors)); pixels.position(0); pixmaps[i] = map; } catch (IOException ex) { ex.printStackTrace(); } } }
From source file:com.googlecode.gdxquake2.game.render.GlRenderer.java
License:Open Source License
void texImage2D(Pixmap pixmal, int target, int level, int internalFormat, int format, int type) { GlState.gl.glTexImage2D(target, level, internalFormat, pixmal.getWidth(), pixmal.getHeight(), 0, format, type, pixmal.getPixels()); }
From source file:com.googlecode.gdxquake2.game.render.GlRenderer.java
License:Open Source License
void texSubImage2D(Pixmap pixmap, int target, int level, int xOffset, int yOffset, int format, int type) { GlState.gl.glTexSubImage2D(target, level, xOffset, yOffset, pixmap.getWidth(), pixmap.getHeight(), format, type, pixmap.getPixels()); }
From source file:com.heaven7.fantastictank.test.ScreenUtils.java
License:Apache License
public static Pixmap getFrameBufferPixmap(int x, int y, int w, int h) { Gdx.gl.glPixelStorei(GL20.GL_PACK_ALIGNMENT, 1); final Pixmap pixmap = new Pixmap(w, h, Format.RGBA8888); ByteBuffer pixels = pixmap.getPixels(); Gdx.gl.glReadPixels(x, y, w, h, GL20.GL_RGBA, GL20.GL_UNSIGNED_BYTE, pixels); return pixmap; }
From source file:com.lyeeedar.Roguelike3D.Graphics.Models.SkyBox.java
License:Open Source License
private void glTexImage2D(int textureCubeMapIndex, Pixmap pixmap) { Gdx.gl20.glTexImage2D(textureCubeMapIndex, 0, pixmap.getGLInternalFormat(), pixmap.getWidth(), pixmap.getHeight(), 0, pixmap.getGLFormat(), pixmap.getGLType(), pixmap.getPixels()); }
From source file:com.mbrlabs.mundus.editor.tools.picker.BasePicker.java
License:Apache License
public Pixmap getFrameBufferPixmap(Viewport viewport) { int w = viewport.getScreenWidth(); int h = viewport.getScreenHeight(); int x = viewport.getScreenX(); int y = viewport.getScreenY(); final ByteBuffer pixelBuffer = BufferUtils.newByteBuffer(w * h * 4); Gdx.gl.glBindFramebuffer(GL20.GL_FRAMEBUFFER, fbo.getFramebufferHandle()); Gdx.gl.glReadPixels(x, y, w, h, GL30.GL_RGBA, GL30.GL_UNSIGNED_BYTE, pixelBuffer); Gdx.gl.glBindFramebuffer(GL20.GL_FRAMEBUFFER, 0); final int numBytes = w * h * 4; byte[] imgLines = new byte[numBytes]; final int numBytesPerLine = w * 4; for (int i = 0; i < h; i++) { pixelBuffer.position((h - i - 1) * numBytesPerLine); pixelBuffer.get(imgLines, i * numBytesPerLine, numBytesPerLine); }//from w ww . j a va2 s . c o m Pixmap pixmap = new Pixmap(w, h, Pixmap.Format.RGBA8888); BufferUtils.copy(imgLines, 0, pixmap.getPixels(), imgLines.length); return pixmap; }