@Override public Texture create(int width, int height) { Pixmap map = new Pixmap(width, height, Format.RGBA8888); Color skinColor = getSkinColor(); Color hairColor = getHairColor(); Color shoeColor = getShoeColor(); Color trousesColor = getTrousesColor(); Color shirtColor = getShirtColor(); generate(map, skinColor, hairColor, shoeColor, trousesColor, shirtColor); Texture texture = new Texture(map); map.dispose(); return texture; }
@Override public void load() { if(isLoaded()) return; bird = loadTextureRegion("angrybirds/sprites/bird.png"); pig = loadTexture("angrybirds/sprites/pig.png"); sling = loadTextureRegion("angrybirds/sprites/sling.png"); block = loadTexture("angrybirds/sprites/woods/block.gif"); longwood = loadTexture("angrybirds/sprites/woods/long.gif"); smallblock = loadTexture("angrybirds/sprites/woods/small.gif"); tallwood = loadTexture("angrybirds/sprites/woods/tall.gif"); background = loadTexture("bg.jpg", Format.RGB565, true); font = loadBitmapFont("default.fnt", "default.png"); damaged_block = loadTexture("angrybirds/sprites/damaged_woods/block.gif"); damaged_longwood = loadTexture("angrybirds/sprites/damaged_woods/long.gif"); damaged_smallblock = loadTexture("angrybirds/sprites/damaged_woods/small.gif"); damaged_tallwood = loadTexture("angrybirds/sprites/damaged_woods/tall.gif"); setLoaded(true); }
private Texture createHighlightingGraphic(TextureRegion textureRegion) { TextureData textureData = textureRegion.getTexture().getTextureData(); textureData.prepare(); Pixmap sourcePixmap = textureData.consumePixmap(); Pixmap destinationPixmap = new Pixmap(textureRegion.getRegionWidth(), textureRegion.getRegionHeight(), Format.RGBA8888); Color color = new Color(); for (int x = 0; x < textureRegion.getRegionWidth(); x++) { for (int y = 0; y < textureRegion.getRegionHeight(); y++) { int colorInt = sourcePixmap.getPixel(textureRegion.getRegionX() + x, textureRegion.getRegionY() + y); Color.rgba8888ToColor(color, colorInt); destinationPixmap.setColor(1.0f, 1f, 1.0f, 1); if (color.a > 0.004f) destinationPixmap.drawPixel(x, y); } } Texture result = new Texture(destinationPixmap); textureData.disposePixmap(); destinationPixmap.dispose(); return result; }
public LightMap(RayHandler rayHandler, int fboWidth, int fboHeight) { this.rayHandler = rayHandler; if (fboWidth <= 0) fboWidth = 1; if (fboHeight <= 0) fboHeight = 1; frameBuffer = new FrameBuffer(Format.RGBA8888, fboWidth, fboHeight, false); pingPongBuffer = new FrameBuffer(Format.RGBA8888, fboWidth, fboHeight, false); lightMapMesh = createLightMapMesh(); shadowShader = ShadowShader.createShadowShader(); diffuseShader = DiffuseShader.createShadowShader(); withoutShadowShader = WithoutShadowShader.createShadowShader(); blurShader = Gaussian.createBlurShader(fboWidth, fboHeight); }
public Renderer () { try { lights = new Environment(); lights.add(new DirectionalLight().set(Color.WHITE, new Vector3(-1, -0.5f, 0).nor())); spriteBatch = new SpriteBatch(); modelBatch = new ModelBatch(); backgroundTexture = new Texture(Gdx.files.internal("data/planet.jpg"), Format.RGB565, true); backgroundTexture.setFilter(TextureFilter.MipMap, TextureFilter.Linear); font = new BitmapFont(Gdx.files.internal("data/font10.fnt"), Gdx.files.internal("data/font10.png"), false); camera = new PerspectiveCamera(67, Gdx.graphics.getWidth(), Gdx.graphics.getHeight()); } catch (Exception ex) { ex.printStackTrace(); } }
@Override public void show () { font = new BitmapFont(Gdx.files.internal("fonts/font.fnt")); cache = font.getCache(); if (Gdx.app.getType() == ApplicationType.Android) font.getData().setScale(2); polygonBatch = new PolygonSpriteBatch(); camera = new OrthographicCamera(Gdx.graphics.getWidth(), Gdx.graphics.getHeight()); Pixmap pixMap = new Pixmap(1, 1, Format.RGB565); pixMap.setColor(Color.WHITE); pixMap.fill(); emptyTexture = new Texture(pixMap); pixMap.dispose(); }
/** Resizes internal RavCamera for framebuffer use, call this in you ApplicationListener's resize. * * @param width - new screen width * @param height - new screen height * @param resizeFramebuffers - whether all of the framebuffers should be recreated to match new screen size */ public void resize (int width, int height, boolean resizeFramebuffers) { // ????? if (resizeFramebuffers) { Keys<String> keys = frameBuffers.keys(); while (keys.hasNext) { String key = keys.next(); FrameBuffer fb = frameBuffers.get(key); int oldWidth = fb.getWidth(); int oldHeight = fb.getHeight(); Format format = fb.getColorBufferTexture().getTextureData().getFormat(); fb.dispose(); frameBuffers.put(key, null); float factorX = 1f * width / screenCamera.viewportWidth; float factorY = 1f * height / screenCamera.viewportHeight; createFB(key, format, (int)(factorX * oldWidth), (int)(factorY * oldHeight)); // System.out.println("Recreated FB '" + key + "' from " + // oldWidth + "x" + oldHeight + " to " + // frameBuffers.get(key).getWidth() + "x" + // frameBuffers.get(key).getHeight()); } } screenCamera = new OrthographicCamera(width, height); createScreenQuad(); }
/** W power will be in luminance, and H power will be in alpha**/ public PowerLUT(float powerW, float intensityW, float powerH, float intensityH, int width, int height){ Pixmap pixmap = new Pixmap(width, height, Format.RGBA8888); for (int i=0; i<width; i++){ float valueW = (float)Math.pow((float)i/width, powerW) * intensityW; for (int j = 0; j < height; j++) { float valueH = (float)Math.pow((float)j/height, powerH) * intensityH; pixmap.setColor(valueW, valueH, 1.0f, 1.0f); pixmap.drawPixel(i, j); } } PixmapTextureData data = new PixmapTextureData(pixmap, Format.RGBA8888, false, false, true); texture = new Texture(data); texture.setWrap(TextureWrap.ClampToEdge, TextureWrap.ClampToEdge); texture.setFilter(TextureFilter.Linear, TextureFilter.Linear); }
/** * Returns the equivalent buffered image type ({@link BufferedImage#getType()}) for the given pixmap * format. */ public static int toBufferedImageType(Format format) { switch (format) { case Intensity: case Alpha: return BufferedImage.TYPE_BYTE_GRAY; case RGB565: case RGB888: return BufferedImage.TYPE_3BYTE_BGR; case LuminanceAlpha: case RGBA4444: case RGBA8888: return BufferedImage.TYPE_INT_ARGB; default: throw new IllegalArgumentException("Unsupported format: " + format); } }
@Override public void loadAsync(AssetManager manager, String fileName, FileHandle file, TextureParameter parameter) { if (parameter == null || parameter.textureData == null) { Format format = null; boolean genMipMaps = false; info.texture = null; if (parameter != null) { format = parameter.format; genMipMaps = parameter.genMipMaps; info.texture = parameter.texture; } info.data = loadTexData(file, format, genMipMaps); } else { info.data = parameter.textureData; info.texture = parameter.texture; } if (!info.data.isPrepared()) { info.data.prepare(); } }
/** * @param pixels A Pixmap in {@link Format#RGBA8888}. */ public static void flipVertical(Pixmap pixels) { Checks.checkArgument(pixels.getFormat() == Format.RGBA8888, "Pixmap with unsupported format: " + pixels.getFormat()); int bytesPerRow = pixels.getWidth() * 4; // RGBA8888 int h = pixels.getHeight(); byte[] lineBuffer0 = new byte[bytesPerRow]; byte[] lineBuffer1 = new byte[bytesPerRow]; ByteBuffer pixelsBuffer = pixels.getPixels(); for (int y = 0; y < h / 2; y++) { int y0 = y * bytesPerRow; int y1 = (h - 1 - y) * bytesPerRow; // Swap pixels in rows pixelsBuffer.position(y0); pixelsBuffer.get(lineBuffer0); pixelsBuffer.position(y1); pixelsBuffer.get(lineBuffer1); pixelsBuffer.position(y1); pixelsBuffer.put(lineBuffer0); pixelsBuffer.position(y0); pixelsBuffer.put(lineBuffer1); } pixelsBuffer.rewind(); }
/** * Converts the given pixmap to the specified target color format. If the source pixmap is already in the * correct format, the original pixmap is returned unmodified. */ public static Pixmap convert(Pixmap source, Format targetFormat, boolean disposeSource) { if (source.getFormat() == targetFormat) { return source; // Already the correct format } int iw = source.getWidth(); int ih = source.getHeight(); Pixmap result = newUninitializedPixmap(iw, ih, targetFormat); copySubRect(source, Rect.of(0, 0, iw, ih), result, Rect.of(0, 0, iw, ih), Filter.NearestNeighbour); if (disposeSource) { source.dispose(); } return result; }
/** * Copies the contents of {@code src} to {@code dst}. * * @throws IllegalArgumentException If the pixmaps are different sizes or different formats. */ public static void copy(Pixmap src, Pixmap dst) { Format srcFmt = src.getFormat(); Format dstFmt = dst.getFormat(); Checks.checkArgument(srcFmt == dstFmt, "Formats not equal: src=" + srcFmt + ", dst=" + dstFmt); int srcW = src.getWidth(); int dstW = dst.getWidth(); Checks.checkArgument(srcW == dstW, "Widths not equal: src.w=" + srcW + ", dst.w=" + dstW); int srcH = src.getHeight(); int dstH = src.getHeight(); Checks.checkArgument(srcH == dstH, "Heights not equal: src.h=" + srcH + ", dst.h=" + dstH); ByteBuffer srcPixels = src.getPixels(); ByteBuffer dstPixels = dst.getPixels(); BufferUtils.copy(srcPixels, dstPixels, srcPixels.limit()); srcPixels.clear(); dstPixels.clear(); }
@Test public void testFlipVertical() { Pixmap flip = new Pixmap(2, 3, Format.RGBA8888); flip.drawPixel(0, 0, 0xAABBCCDD); flip.drawPixel(1, 2, 0x11223344); PixmapUtil.flipVertical(flip); Pixmap expected = new Pixmap(2, 3, Format.RGBA8888); expected.drawPixel(0, 2, 0xAABBCCDD); expected.drawPixel(1, 0, 0x11223344); pixmapEquals.assertEquals(expected, flip); flip.dispose(); expected.dispose(); }
public static Texture generatePlanet(int[][] tileMap, ArrayList<Tile> tiles) { int s = tileMap.length; Pixmap pixmap = new Pixmap(s, s, Format.RGBA4444); // draw circle for planet pixmap.setColor(1, 1, 1, 1); pixmap.fillCircle(s/2,s/2,s/2-1); //draw noise for (int y = 0; y < s; ++y) { for (int x = 0; x < s; ++x) { //only draw on circle if (pixmap.getPixel(x, y) != 0) { pixmap.setColor(tiles.get(tileMap[x][y]).getColor()); pixmap.drawPixel(x, y); } } } Texture t = new Texture(pixmap); pixmap.dispose(); return t; }
public static Texture generateNoise(long seed, int size, double featureSize) { OpenSimplexNoise noise = new OpenSimplexNoise(seed); Pixmap pixmap = new Pixmap(size, size, Format.RGBA4444); //add layer of noise for (int y = 0; y < pixmap.getHeight(); ++y) { for (int x = 0; x < pixmap.getWidth(); ++x) { double nx = x / featureSize, ny = y / featureSize; double i = noise.eval(nx, ny, 0); i = (i * 0.5) + 0.5; // convert from range [-1:1] to [0:1] pixmap.setColor(new Color((float) i, (float) i, (float) i, 1)); pixmap.drawPixel(x, y); } } Texture t = new Texture(pixmap); pixmap.dispose(); return t; }
public static Texture generateCharacter() { pixmap = new Pixmap(4, 4, Format.RGB565); //fill square pixmap.setColor(0.5f, 0.5f, 0.5f, 1); pixmap.fill(); //draw face/eyes (front of character) pixmap.setColor(0, 1, 1, 1); pixmap.drawPixel(3, 2); pixmap.drawPixel(3, 1); Texture t = new Texture(pixmap); pixmap.dispose(); return t; }
@Override public void loadAsync(AssetManager manager, String fileName, FileHandle file, TextureParameter parameter) { info.filename = fileName; if (parameter == null || parameter.textureData == null) { info.texture = null; if (parameter != null) { info.texture = parameter.texture; } info.data = new PixmapTextureData(null, Format.RGB565, false, false); } else { info.data = parameter.textureData; info.texture = parameter.texture; } }
public OrthogonalTiledMapRendererWithObjects(TiledMap map) { super(map); this.occlusionFbo = new FrameBuffer(Format.RGBA8888, Gdx.graphics.getWidth() / 2, Gdx.graphics.getHeight() / 2, false); this.shadowmapFbo = new FrameBuffer(Format.RGBA8888, Gdx.graphics.getWidth() / 2, 1, false); this.shadowmapTex = shadowmapFbo.getColorBufferTexture(); this.shadowmapTex.setFilter(TextureFilter.Linear, TextureFilter.Linear); this.shadowmapTex.setWrap(TextureWrap.Repeat, TextureWrap.Repeat); //this.orthoCam = new OrthographicCamera(Gdx.graphics.getWidth(), Gdx.graphics.getHeight()); //this.orthoCam.setToOrtho(Y_DOWN); this.lights = new ArrayList<Light>(); this.mouseLight = new Light(0, 0, Color.WHITE); }
/** * Constructor apply default button style */ public MenuButtonFactory() { pixmap = new Pixmap(100, 100, Format.RGBA8888); pixmap.setColor(Color.WHITE); pixmap.fill(); skin = new Skin(); skin.add("white", new Texture(pixmap)); textButtonStyle = new TextButtonStyle(); textButtonStyle.up = skin.newDrawable("white", Color.DARK_GRAY); textButtonStyle.down = skin.newDrawable("white", Color.DARK_GRAY); textButtonStyle.over = skin.newDrawable("white", Color.LIGHT_GRAY); textButtonStyle.checked = skin.newDrawable("white", Color.BLACK); textButtonStyle.font = new BitmapFont( Gdx.files.internal("data/font.fnt"), Gdx.files.internal("data/font.png"), false); textButtonStyle.font.setScale(1.6f); }
public LifeBar(GameObject target, TweenManager tweenManager) { this.target = target; Texture lifeTexture = Resources.get(Resources.LIFE, Texture.class); currentPoints = target.getCurrentLife(); this.tweenManager = tweenManager; Pixmap map = new Pixmap(20, 100, Format.RGBA8888); map.setColor(Color.BLACK); map.fill(); Texture backgroundTexture = new Texture(map); map.dispose(); life = new Sprite(lifeTexture); background = new Sprite(backgroundTexture); padding = 10; getColor().a = 0.5f; }
@Override public void consumeCustomData (int target) { if (!isPrepared) throw new GdxRuntimeException("Call prepare() before calling consumeCompressedData()"); if (!Gdx.graphics.supportsExtension("GL_OES_compressed_ETC1_RGB8_texture")) { Pixmap pixmap = ETC1.decodeImage(data, Format.RGB565); Gdx.gl.glTexImage2D(target, 0, pixmap.getGLInternalFormat(), pixmap.getWidth(), pixmap.getHeight(), 0, pixmap.getGLFormat(), pixmap.getGLType(), pixmap.getPixels()); if (useMipMaps) MipMapGenerator.generateMipMap(target, pixmap, pixmap.getWidth(), pixmap.getHeight()); pixmap.dispose(); useMipMaps = false; } else { Gdx.gl.glCompressedTexImage2D(target, 0, ETC1.ETC1_RGB8_OES, width, height, 0, data.compressedData.capacity() - data.dataOffset, data.compressedData); if (useMipMaps()) Gdx.gl20.glGenerateMipmap(GL20.GL_TEXTURE_2D); } data.dispose(); data = null; isPrepared = false; }
/** Takes ETC1 compressed image data and converts it to a {@link Format#RGB565} or {@link Format#RGB888} {@link Pixmap}. Does * not modify the ByteBuffer's position or limit. * @param etc1Data the {@link ETC1Data} instance * @param format either {@link Format#RGB565} or {@link Format#RGB888} * @return the Pixmap */ public static Pixmap decodeImage (ETC1Data etc1Data, Format format) { int dataOffset = 0; int width = 0; int height = 0; if (etc1Data.hasPKMHeader()) { dataOffset = 16; width = ETC1.getWidthPKM(etc1Data.compressedData, 0); height = ETC1.getHeightPKM(etc1Data.compressedData, 0); } else { dataOffset = 0; width = etc1Data.width; height = etc1Data.height; } int pixelSize = getPixelSize(format); Pixmap pixmap = new Pixmap(width, height, format); decodeImage(etc1Data.compressedData, dataOffset, pixmap.getPixels(), 0, width, height, pixelSize); return pixmap; }
@Override public void loadAsync (AssetManager manager, String fileName, FileHandle file, CubemapParameter parameter) { info.filename = fileName; if (parameter == null || parameter.cubemapData == null) { Pixmap pixmap = null; Format format = null; boolean genMipMaps = false; info.cubemap = null; if (parameter != null) { format = parameter.format; info.cubemap = parameter.cubemap; } } else { info.data = parameter.cubemapData; info.cubemap = parameter.cubemap; } if (!info.data.isPrepared()) info.data.prepare(); }
@Override public void loadAsync (AssetManager manager, String fileName, FileHandle fileHandle, TextureParameter parameter) { if (parameter == null || (parameter != null && parameter.textureData == null)) { Pixmap pixmap = null; Format format = null; boolean genMipMaps = false; texture = null; if (parameter != null) { format = parameter.format; genMipMaps = parameter.genMipMaps; texture = parameter.texture; } FileHandle handle = resolve(fileName); pixmap = new Pixmap(handle); data = new FileTextureData(handle, pixmap, format, genMipMaps); } else { data = parameter.textureData; if (!data.isPrepared()) data.prepare(); texture = parameter.texture; } }
private void createTexture () { Pixmap pixmap = new Pixmap(256, 256, Format.RGBA8888); pixmap.setColor(1, 1, 1, 1); pixmap.fill(); pixmap.setColor(0, 0, 0, 1); pixmap.drawLine(0, 0, 256, 256); pixmap.drawLine(256, 0, 0, 256); texture = new Texture(pixmap); pixmap.dispose(); pixmap = new Pixmap(256, 256, Format.RGBA8888); pixmap.setColor(1, 1, 1, 1); pixmap.fill(); pixmap.setColor(0, 0, 0, 1); pixmap.drawLine(128, 0, 128, 256); texture2 = new Texture(pixmap); pixmap.dispose(); }
public void setupScene () { plane = new Mesh(true, 4, 6, new VertexAttribute(Usage.Position, 3, ShaderProgram.POSITION_ATTRIBUTE), new VertexAttribute( Usage.Normal, 3, ShaderProgram.NORMAL_ATTRIBUTE)); plane.setVertices(new float[] {-10, -1, 10, 0, 1, 0, 10, -1, 10, 0, 1, 0, 10, -1, -10, 0, 1, 0, -10, -1, -10, 0, 1, 0}); plane.setIndices(new short[] {3, 2, 1, 1, 0, 3}); texture = new Texture(Gdx.files.internal("data/badlogic.jpg"), Format.RGB565, true); texture.setFilter(TextureFilter.MipMap, TextureFilter.Nearest); cam = new PerspectiveCamera(67, Gdx.graphics.getWidth(), Gdx.graphics.getHeight()); cam.position.set(0, 5, 10); cam.lookAt(0, 0, 0); cam.update(); controller = new PerspectiveCamController(cam); projector = new PerspectiveCamera(67, Gdx.graphics.getWidth(), Gdx.graphics.getHeight()); projector.position.set(2, 3, 2); projector.lookAt(0, 0, 0); projector.normalizeUp(); projector.update(); }
@Override public void create () { mesh = new Mesh(true, 3, 0, new VertexAttribute(Usage.Position, 3, "a_Position"), new VertexAttribute(Usage.ColorPacked, 4, "a_Color"), new VertexAttribute(Usage.TextureCoordinates, 2, "a_texCoords")); float c1 = Color.toFloatBits(255, 0, 0, 255); float c2 = Color.toFloatBits(255, 0, 0, 255); float c3 = Color.toFloatBits(0, 0, 255, 255); mesh.setVertices(new float[] {-0.5f, -0.5f, 0, c1, 0, 0, 0.5f, -0.5f, 0, c2, 1, 0, 0, 0.5f, 0, c3, 0.5f, 1}); stencilMesh = new Mesh(true, 3, 0, new VertexAttribute(Usage.Position, 3, "a_Position"), new VertexAttribute( Usage.ColorPacked, 4, "a_Color"), new VertexAttribute(Usage.TextureCoordinates, 2, "a_texCoords")); stencilMesh.setVertices(new float[] {-0.5f, 0.5f, 0, c1, 0, 0, 0.5f, 0.5f, 0, c2, 1, 0, 0, -0.5f, 0, c3, 0.5f, 1}); texture = new Texture(Gdx.files.internal("data/badlogic.jpg")); spriteBatch = new SpriteBatch(); frameBuffer = new FrameBuffer(Format.RGB565, 128, 128, false); stencilFrameBuffer = new FrameBuffer(Format.RGB565, 128, 128, false, true); createShader(Gdx.graphics); }
@Override public void init() { //Initialize the libgdx objects spriteBatch = new SpriteBatch(); background = new Texture(width,height,Format.RGB888); //Initialize the image buffers image = new byte[width*height*3]; imageByteBuffer = ByteBuffer.allocateDirect(width*height*3); //Initialize the device camera interface camera = Webcam.getDefault(); camera.setViewSize(new Dimension(width,height)); camera.open(); //Launch the device camera listener cameraThread = new Thread(){ @Override public void run(){ webcamRunner(); } }; running = true; cameraThread.start(); }
@Override public void create () { font = new BitmapFont(); camera = new OrthographicCamera(Gdx.graphics.getWidth(), Gdx.graphics.getHeight()); controller = new OrthoCamController(camera); Gdx.input.setInputProcessor(controller); Pixmap pixmap = new Pixmap(32, 32, Format.RGB565); pixmap.setColor(1, 0, 0, 1); pixmap.fill(); pixmap.setColor(0, 1, 0, 1); pixmap.drawLine(0, 0, 32, 32); pixmap.drawLine(0, 32, 32, 0); ETC1Data encodedImage = ETC1.encodeImagePKM(pixmap); pixmap.dispose(); pixmap = ETC1.decodeImage(encodedImage, Format.RGB565); encodedImage.dispose(); img1 = new Texture(pixmap); img2 = new Texture("data/test.etc1"); batch = new SpriteBatch(); pixmap.dispose(); }
/** * */ public ShaderTest() { ShaderProgram.pedantic = false; vertBlur = loadShader("blurv.frag"); horBlur = loadShader("blurh.frag"); light = loadShader("light.frag"); shader = loadShader("inprint.frag"); this.camera = new OrthographicCamera(Gdx.graphics.getWidth(), Gdx.graphics.getHeight()); this.camera.setToOrtho(true, Gdx.graphics.getWidth(), Gdx.graphics.getHeight()); // camera.setToOrtho(false); transform = new Matrix4(); camera.update(); batch = new SpriteBatch();//1024, shader); batch.setShader(null); batch.setProjectionMatrix(camera.combined); batch.setTransformMatrix(transform); this.buffer = new FrameBuffer(Format.RGBA8888, Gdx.graphics.getWidth(), Gdx.graphics.getHeight(), false); this.fboPing = new FrameBuffer(Format.RGBA8888, Gdx.graphics.getWidth(), Gdx.graphics.getHeight(), false); this.fboPong = new FrameBuffer(Format.RGBA8888, Gdx.graphics.getWidth(), Gdx.graphics.getHeight(), false); }
@Override public void create () { spriteBatch = new SpriteBatch(); texture = new Texture(Gdx.files.internal("data/badlogicsmall.jpg")); Pixmap pixmap = new Pixmap(32, 32, Format.RGB565); pixmap.setColor(1, 1, 0, 0.7f); pixmap.fill(); texture2 = new Texture(pixmap); pixmap.dispose(); for (int i = 0; i < coords.length; i += 2) { coords[i] = (int)(Math.random() * Gdx.graphics.getWidth()); coords[i + 1] = (int)(Math.random() * Gdx.graphics.getHeight()); coords2[i] = (int)(Math.random() * Gdx.graphics.getWidth()); coords2[i + 1] = (int)(Math.random() * Gdx.graphics.getHeight()); } }
public DungeonMeter(DungeonKeeper target) { this.target = target; currentValue = 1f; Pixmap map = new Pixmap(128, 128, Format.RGBA8888); Color color = new Color(Color.BLACK); color.a = 0.3f; map.setColor(color); map.fill(); Texture texture = new Texture(map); map.dispose(); background = new Sprite(texture); map = new Pixmap(128, 128, Format.RGBA8888); map.setColor(Color.valueOf("99aa66")); map.fill(); texture = new Texture(map); map.dispose(); life = new Sprite(texture); padding = 5; }
private static void saveScreenshot() throws IOException { int w = Gdx.graphics.getWidth(); int h = Gdx.graphics.getHeight(); final Pixmap pixmap = new Pixmap(Gdx.graphics.getWidth(), Gdx.graphics.getHeight(), Format.RGBA8888); ByteBuffer pixels = pixmap.getPixels(); Gdx.gl.glReadPixels(0, 0, w, h, GL20.GL_RGBA, GL20.GL_UNSIGNED_BYTE, pixels); final int numBytes = w * h * 4; byte[] lines = new byte[numBytes]; final 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); System.out.println("Captured."); PixmapIO.writePNG(new FileHandle(androidDir+(++photoNumber)+".png"), pixmap); }
private static Pixmap getScreenshot(int x, int y, int w, int h, boolean flipY){ 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); final int numBytes = w * h * 4; byte[] lines = new byte[numBytes]; if (flipY){ pixels.clear(); pixels.get(lines); }else{ final 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); } return pixmap; }
public static Pixmap toWhite(Pixmap img) { Pixmap alpha = new Pixmap(img.getWidth(), img.getHeight(), Format.RGBA8888); //alpha.drawPixmap(img, 0, 0); int width = alpha.getWidth(); int height = alpha.getHeight(); //alpha.setColor(0xff00009f); for (int y = 0; y < height; y++) { for (int x = 0; x < width; x++) { int col = img.getPixel(x, y); Color color = new Color(col); if ( color.a > 0.2f ) { alpha.drawPixel(x, y, Color.WHITE.toIntBits()); } } } img.dispose(); return alpha; }