List of usage examples for com.badlogic.gdx.graphics Pixmap drawPixmap
public void drawPixmap(Pixmap pixmap, int srcx, int srcy, int srcWidth, int srcHeight, int dstx, int dsty, int dstWidth, int dstHeight)
From source file:CB_UI_Base.graphics.Images.BitmapDrawable.java
License:Open Source License
private void createData() { Pixmap pix;//from w w w .j a v a 2s. com try { pix = new Pixmap(buffer, 0, buffer.length); } catch (Exception e) { // Can't create e.printStackTrace(); return; } // scale? if (this.scaleFactor != 1) { int w = (int) (pix.getWidth() * this.scaleFactor); int h = (int) (pix.getHeight() * this.scaleFactor); Pixmap tmpPixmap = new Pixmap(w, h, pix.getFormat()); Pixmap.setFilter(Pixmap.Filter.NearestNeighbour); tmpPixmap.drawPixmap(pix, 0, 0, pix.getWidth(), pix.getHeight(), 0, 0, w, h); pix.dispose(); pix = tmpPixmap; } try { Packer.pack(AtlasHashString, pix); } catch (Exception e) { e.printStackTrace(); } if (Atlas == null) { Atlas = Packer.generateTextureAtlas(TextureFilter.Linear, TextureFilter.Linear, false); } else { Packer.updateTextureAtlas(Atlas, TextureFilter.Linear, TextureFilter.Linear, false); } pix.dispose(); buffer = null; }
From source file:com.agateau.pixelwheels.tools.MapScreenshotGenerator.java
License:Apache License
private static Pixmap scaleScreenshot(Pixmap src) { int srcW = src.getWidth(); int srcH = src.getHeight(); float ratio = (float) SHOT_SIZE / Math.min(srcW, srcH); int dstW = (int) (srcW * ratio); int dstH = (int) (srcH * ratio); Pixmap dst = new Pixmap(SHOT_SIZE, SHOT_SIZE, src.getFormat()); dst.setFilter(Pixmap.Filter.BiLinear); dst.drawPixmap(src, 0, 0, srcW, srcH, (SHOT_SIZE - dstW) / 2, (SHOT_SIZE - dstH) / 2, dstW, dstH); return dst;/*from w ww . j a v a 2 s . c om*/ }
From source file:com.digitale.screens.MissionScreen.java
License:Open Source License
public Texture generateDynamicTexture(String iconFilename, String category, int quality) { Pixmap baseImage; if (category.equals("blueprint")) { FileHandle baseFile = Gdx.files.internal("data/blueprint.png"); baseImage = new Pixmap(baseFile); } else {//from www. j a v a 2 s .c o m baseImage = new Pixmap(64, 64, Format.RGBA8888); } FileHandle iconFile = Gdx.files.internal(iconFilename); FileHandle iconGlowFile = Gdx.files.internal(iconFilename); if (Stardust3d.DEEPDEBUG) System.out.println("base format" + baseImage.getFormat()); Pixmap imgA = new Pixmap(iconGlowFile); if (Stardust3d.DEEPDEBUG) System.out.println("a format" + imgA.getFormat()); Pixmap imgB = new Pixmap(iconFile); if (Stardust3d.DEEPDEBUG) System.out.println("b " + iconFilename + " format" + imgB.getFormat()); // overdraw rectangle to tint icon where needed // if(tintcolour !null){imgB.SetColor(tintcolour); imgB.fillRectangle(0, 0, 64, 64); // set colour for quality marker switch (quality) { case 0: imgB.setColor(.5f, .5f, .5f, 1f); break; case 1: imgB.setColor(.75f, .75f, .75f, 1f); break; case 2: imgB.setColor(1f, 1f, 1f, 1f); break; case 3: imgB.setColor(0f, .5f, 0f, 1f); break; case 4: imgB.setColor(0f, 1f, 0f, 1f); break; case 5: imgB.setColor(0f, 0f, 1f, 1f); break; case 6: imgB.setColor(0f, 0f, .5f, 1f); break; case 7: imgB.setColor(.5f, 0f, 1f, 1f); break; case 8: imgB.setColor(1f, .5f, 0f, 1f); break; case 9: imgB.setColor(1f, 0.5f, 0f, 1f); break; } // draw quality indicator imgB.fillRectangle(0, 54, 10, 10); baseImage.setColor(0f, 1f, 0f, .2f); // baseImage.drawPixmap(imgA, 0, 0, 64, 64, 0, 0, 64, 64); // superimpose item's icon baseImage.drawPixmap(imgB, 0, 0, 64, 64, 0, 0, 64, 64); Texture dynamicTexture = new Texture(baseImage); baseImage.dispose(); imgA.dispose(); imgB.dispose(); return dynamicTexture; }
From source file:com.googlecode.gdxquake2.game.render.GlRenderer.java
License:Open Source License
public void uploadImage(Image image) { GlState.checkError("before upload image"); image.has_alpha = true;/* www . j a v a2 s . c o m*/ image.complete = true; Images.GL_Bind(image.texnum); if (image.type == com.googlecode.gdxquake2.game.common.QuakeImage.it_pic) { GlState.gl.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_S, GL11.GL_CLAMP_TO_EDGE); GlState.gl.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_T, GL11.GL_CLAMP_TO_EDGE); GlState.gl.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_LINEAR); GlState.gl.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_NEAREST); texImage2D(image.pixmap, GL20.GL_TEXTURE_2D, 0, GL20.GL_RGBA, GL20.GL_RGBA, GL20.GL_UNSIGNED_BYTE); image.upload_width = image.width; image.upload_height = image.height; } else if (image.type == com.googlecode.gdxquake2.game.common.QuakeImage.it_sky) { GlState.gl.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_S, GL11.GL_CLAMP_TO_EDGE); GlState.gl.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_T, GL11.GL_CLAMP_TO_EDGE); GlState.gl.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_LINEAR); GlState.gl.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_NEAREST); if (Images.skyTarget == null) Images.skyTarget = image; Images.GL_Bind(Images.skyTarget.texnum); if (Images.skyTarget.upload_width != 6 * image.width) { texImage2D(new Pixmap(6 * image.width, image.height, Pixmap.Format.RGBA8888), GL20.GL_TEXTURE_2D, 0, GL20.GL_RGBA, GL20.GL_RGBA, GL20.GL_UNSIGNED_BYTE); Images.skyTarget.upload_width = 6 * image.width; } Images.skyTarget.upload_height = image.height; texSubImage2D(image.pixmap, GL20.GL_TEXTURE_2D, 0, image.width * image.skyIndex, 0, GL20.GL_RGBA, GL20.GL_UNSIGNED_BYTE); } else { GlState.gl.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_S, GL11.GL_REPEAT); GlState.gl.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_T, GL11.GL_REPEAT); GlState.gl.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_LINEAR_MIPMAP_LINEAR); GlState.gl.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_LINEAR); int p2size = 1 << ((int) Math.ceil(Math.log(Math.max(image.width, image.height)) / Math.log(2))); image.upload_width = p2size; image.upload_height = p2size; int level = 0; do { Pixmap canvas = getTmpImage(p2size, p2size); canvas.setColor(0x88888888); canvas.fill(); try { canvas.drawPixmap(image.pixmap, 0, 0, image.pixmap.getWidth(), image.pixmap.getHeight(), 0, 0, p2size, p2size); } catch (Exception e) { GdxQuake2.tools.log("Error rendering image " + image.name + "; size: " + p2size + " MSG: " + e); break; } texImage2D(canvas, GL20.GL_TEXTURE_2D, level++, GL20.GL_RGBA, GL20.GL_RGBA, GL20.GL_UNSIGNED_BYTE); p2size /= 2; } while (p2size > 0); } GLDebug.checkError(GlState.gl, "uploadImage"); }
From source file:com.mbrlabs.mundus.ui.modules.inspector.terrain.TerrainGenTab.java
License:Apache License
private void loadHeightMap(FileHandle heightMap) { Terrain terrain = parent.component.getTerrain().getTerrain(); TerrainHeightCommand command = new TerrainHeightCommand(terrain); command.setHeightDataBefore(terrain.heightData); Pixmap originalMap = new Pixmap(heightMap); // scale pixmap if it doesn't fit the terrain if (originalMap.getWidth() != terrain.vertexResolution || originalMap.getHeight() != terrain.vertexResolution) { Pixmap scaledPixmap = new Pixmap(terrain.vertexResolution, terrain.vertexResolution, originalMap.getFormat()); scaledPixmap.drawPixmap(originalMap, 0, 0, originalMap.getWidth(), originalMap.getHeight(), 0, 0, scaledPixmap.getWidth(), scaledPixmap.getHeight()); originalMap.dispose();/*from w w w.ja v a 2 s . c o m*/ Terraformer.heightMap(terrain).maxHeight(terrain.terrainWidth * 0.17f).map(scaledPixmap).terraform(); scaledPixmap.dispose(); } else { Terraformer.heightMap(terrain).maxHeight(terrain.terrainWidth * 0.17f).map(originalMap).terraform(); originalMap.dispose(); } command.setHeightDataAfter(terrain.heightData); history.add(command); }
From source file:com.ridiculousRPG.GameBase.java
License:Apache License
/** * Takes a screenshot from the current frame buffer. The screenshot will be * stretched to fit into the Rectangle specified by dstW and dstH * //from w ww. jav a2 s. c o m * @param srcX * @param srcY * @param srcW * @param srcH * @param dstW * @param dstH * @return A Pixmap containing the screenshot. The screenshot will be * flipped at the y-axis. * @throws IOException */ public Pixmap takeScreenshot(int srcX, int srcY, int srcW, int srcH, int dstW, int dstH) throws IOException { Gdx.gl.glPixelStorei(GL10.GL_PACK_ALIGNMENT, 1); Pixmap pixmap = new Pixmap(srcW, srcH, Format.RGBA8888); Gdx.gl.glReadPixels(srcX, srcY, srcW, srcH, GL10.GL_RGBA, GL10.GL_UNSIGNED_BYTE, pixmap.getPixels()); // scale the picture if (srcW != dstW || srcH != dstH) { Pixmap scale = new Pixmap(dstW, dstH, Format.RGBA8888); Blending old = Pixmap.getBlending(); Pixmap.setBlending(Blending.None); scale.drawPixmap(pixmap, 0, 0, srcW, srcH, 0, 0, dstW, dstH); Pixmap.setBlending(old); pixmap.dispose(); pixmap = scale; } return pixmap; }
From source file:com.xemplar.games.android.nerdshooter.screens.ui.Button.java
License:Open Source License
public Button(BitmapFont font, TextureRegion tex, float x, float y, float width, float height) { super(font, "", x, y, width, height); Pixmap map = tex.getTexture().getTextureData().consumePixmap(); this.font = font; this.tex = tex; array_pressed = new float[] { 0.5F, 0.5F, 0.5F, 1.0F }; array_not_pressed = new float[] { 0.5F, 0.5F, 0.5F, 1.0F }; System.out.println("Is Null : " + this.tex == null); Pixmap pix_not_pressed = new Pixmap((int) width, (int) height, Pixmap.Format.RGBA8888); pix_not_pressed.drawPixmap(map, 0, 0, map.getWidth(), map.getHeight(), 0, 0, (int) width, (int) height); tex_not_pressed = new Texture(pix_not_pressed); Pixmap pix_pressed = new Pixmap((int) width, (int) height, Pixmap.Format.RGBA8888); pix_pressed.drawPixmap(map, 0, 0, map.getWidth(), map.getHeight(), 0, 0, (int) width, (int) height); tex_pressed = new Texture(pix_pressed); map.dispose();/* w ww . j a v a2 s . c o m*/ }
From source file:com.xemplar.games.android.nerdshooter.screens.ui.Button.java
License:Open Source License
public Button(BitmapFont font, TextureRegion tex, float[] colors, float x, float y, float width, float height) { super(font, "", x, y, width, height); Pixmap map = tex.getTexture().getTextureData().consumePixmap(); this.tex = tex; array_pressed = colors;//from w w w.jav a2 s . co m array_not_pressed = colors; Pixmap pix_not_pressed = new Pixmap((int) width, (int) height, Pixmap.Format.RGBA8888); pix_not_pressed.setColor(colors[0], colors[1], colors[2], colors[3]); pix_not_pressed.fill(); pix_not_pressed.drawPixmap(map, 0, 0, map.getWidth(), map.getHeight(), 0, 0, (int) width, (int) height); tex_not_pressed = new Texture(pix_not_pressed); Pixmap pix_pressed = new Pixmap((int) width, (int) height, Pixmap.Format.RGBA8888); pix_pressed.setColor(colors[0], colors[1], colors[2], colors[3]); pix_pressed.fill(); pix_pressed.drawPixmap(map, 0, 0, map.getWidth(), map.getHeight(), 0, 0, (int) width, (int) height); tex_pressed = new Texture(pix_pressed); map.dispose(); }
From source file:com.xemplar.games.android.nerdshooter.screens.ui.Button.java
License:Open Source License
public Button(BitmapFont font, TextureRegion tex, float[] colors, float[] pressedColors, float x, float y, float width, float height) { super(font, "", x, y, width, height); Pixmap map = tex.getTexture().getTextureData().consumePixmap(); this.tex = tex; array_pressed = colors;// w w w . j av a 2 s.c om array_not_pressed = pressedColors; Pixmap pix_not_pressed = new Pixmap((int) width, (int) height, Pixmap.Format.RGBA8888); pix_not_pressed.setColor(colors[0], colors[1], colors[2], colors[3]); pix_not_pressed.fill(); pix_not_pressed.drawPixmap(map, 0, 0, map.getWidth(), map.getHeight(), 0, 0, (int) width, (int) height); tex_not_pressed = new Texture(pix_not_pressed); Pixmap pix_pressed = new Pixmap((int) width, (int) height, Pixmap.Format.RGBA8888); pix_pressed.setColor(pressedColors[0], pressedColors[1], pressedColors[2], pressedColors[3]); pix_pressed.fill(); pix_pressed.drawPixmap(map, 0, 0, map.getWidth(), map.getHeight(), 0, 0, (int) width, (int) height); tex_pressed = new Texture(pix_pressed); map.dispose(); }
From source file:de.myreality.acid.gdx.GdxCellRenderer.java
License:Open Source License
@Override public void drawCell(float x, float y, float width, float height, float r, float g, float b, float a) { Texture buffer = renderer.getBuffer(); if (buffer != null) { Pixmap map = new Pixmap((int) width, (int) height, Format.RGBA8888); map.setColor(r, g, b, a);/* w ww. j ava2s. c o m*/ if (image != null) { Sprite sprite = new Sprite(image); sprite.setColor(r, g, b, a); image = sprite.getTexture(); TextureData data = image.getTextureData(); data.prepare(); Pixmap tmp = data.consumePixmap(); map.drawPixmap(tmp, 0, 0, tmp.getWidth(), tmp.getHeight(), 0, 0, (int) width, (int) height); image.getTextureData().disposePixmap(); } else { map.fillRectangle(0, 0, (int) width, (int) height); } buffer.draw(map, (int) x, (int) y); map.dispose(); } }