List of usage examples for com.badlogic.gdx.graphics Pixmap Pixmap
public Pixmap(byte[] encodedData, int offset, int len)
From source file:com.github.skittishSloth.openSkies.maps.MapGenerator.java
public Texture generateRainfallTexture(final TerrainTile[][] tiles, final int width, final int height, final int tileSize) { final Pixmap pm = new Pixmap(width * tileSize, height * tileSize, Pixmap.Format.RGBA8888); for (int x = 0; x < width; ++x) { for (int y = 0; y < height; ++y) { final TerrainTile tile = tiles[x][y]; final Color c = tile.getRainfallColor(); pm.setColor(c);/*from w ww .j a v a2 s .co m*/ pm.fillRectangle(x * tileSize, y * tileSize, tileSize, tileSize); } } final Texture res = new Texture(pm); pm.dispose(); return res; }
From source file:com.github.skittishSloth.openSkies.maps.MapGenerator.java
public Texture generateElevationGrayscaleTexture(final TerrainTile[][] tiles, final int width, final int height, final int tileSize) { final Pixmap pm = new Pixmap(width * tileSize, height * tileSize, Pixmap.Format.RGBA8888); for (int x = 0; x < width; ++x) { for (int y = 0; y < height; ++y) { final TerrainTile tile = tiles[x][y]; final Color c = tile.getElevationGrayscale(); pm.setColor(c);//from w ww. j a v a2 s. c o m pm.fillRectangle(x * tileSize, y * tileSize, tileSize, tileSize); } } final Texture res = new Texture(pm); pm.dispose(); return res; }
From source file:com.github.skittishSloth.openSkies.maps.MapGenerator.java
public Texture generateLatitudeTexture(final TerrainTile[][] tiles, final int width, final int height, final int tileSize) { final Pixmap pm = new Pixmap(width * tileSize, height * tileSize, Pixmap.Format.RGBA8888); for (int x = 0; x < width; ++x) { for (int y = 0; y < height; ++y) { final TerrainTile tile = tiles[x][y]; final Color c = tile.getLatitudeColor(); pm.setColor(c);/*from w w w.j a va2s.c o m*/ pm.fillRectangle(x * tileSize, y * tileSize, tileSize, tileSize); } } final Texture res = new Texture(pm); pm.dispose(); return res; }
From source file:com.github.skittishSloth.openSkies.maps.MapGenerator.java
public Texture generateMineralsTexture(final TerrainTile[][] tiles, final int width, final int height, final int tileSize) { final Pixmap pm = new Pixmap(width * tileSize, height * tileSize, Pixmap.Format.RGBA8888); for (int x = 0; x < width; ++x) { for (int y = 0; y < height; ++y) { final TerrainTile tile = tiles[x][y]; final Color c = tile.getMineralColor(); pm.setColor(c);// w ww . j a v a 2s . com pm.fillRectangle(x * tileSize, y * tileSize, tileSize, tileSize); } } final Texture res = new Texture(pm); pm.dispose(); return res; }
From source file:com.github.skittishSloth.openSkies.maps.VoronoiTestScreen.java
public VoronoiTestScreen() { final int tileSize = 1; final int width = Gdx.graphics.getWidth() / tileSize; final int height = Gdx.graphics.getHeight() / tileSize; final int numSites = 2000; map = VoronoiMap.generateRandom(numSites, width, height); final Collection<Site> sites = map.getSites(); bfMap = new BruteForceVoronoiMap(width, height, tileSize, sites); final float[][] landProbability = PerlinNoiseGenerator.generatePerlinNoise(width, height, 2); final Pixmap pm = new Pixmap(width, height, Pixmap.Format.RGBA8888); pm.setColor(Color.BLACK);//from w w w. j a v a 2s . co m pm.fill(); final Map<Site, Cell> cells = bfMap.buildCells(landProbability); for (final Site site : sites) { final Cell cell = cells.get(site); if (cell == null) { System.err.println("Cell was null for site " + site.getX() + ", " + site.getY()); continue; } final boolean landCell = cell.isLand(); final Color cellColor; if (landCell) { cellColor = Elevation.PLAINS.getColor(); } else { cellColor = Elevation.WATER.getColor(); } pm.setColor(cellColor); final List<VoronoiTile> tiles = cell.getTiles(); for (final VoronoiTile tile : tiles) { final int x = tile.getX(); final int y = tile.getY(); pm.drawPixel(x, y); } } pm.setColor(Color.BLACK); for (final Site site : sites) { final Cell cell = cells.get(site); if (cell == null) { System.err.println("Cell was null for site " + site.getX() + ", " + site.getY()); continue; } final Polygon polygon = cell.calculateConvexHull(); final float[] vertices = polygon.getVertices(); final boolean hasCornerPoint = cell.hasCornerPoint(); final List<Point> verticesPoints = new ArrayList<Point>(); for (int i = 0; i < vertices.length - 1;) { final int x = Math.round(vertices[i++]); final int y = Math.round(vertices[i++]); if ((x == 0) && (y == 0)) { if (!hasCornerPoint) { continue; } } final Point p = new Point(x, y); verticesPoints.add(p); } final int numPoints = verticesPoints.size(); for (int i = 0; i < numPoints - 1;) { final Point p1 = verticesPoints.get(i++); final Point p2 = verticesPoints.get(i++); pm.drawLine(p1.x, p1.y, p2.x, p2.y); } } pm.setColor(Color.WHITE); for (final Site site : sites) { final int x = site.getX(); final int y = site.getY(); pm.drawPixel(x, y); } mapTexture = new Texture(pm); pm.dispose(); batch = new SpriteBatch(); }
From source file:com.github.unluckyninja.mousekiller.graphics.TextRenderer.java
License:Open Source License
/** * ????/* w w w.ja v a 2 s . 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
private Pixmap getTmpImage(int w, int h) { String name = w + "x" + h; Pixmap image = tmpImages.get(name);//from w w w . j a v a 2 s .co m if (image == null) { image = new Pixmap(w, h, Pixmap.Format.RGBA8888); tmpImages.put(name, image); } return image; }
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;//from www .j a v a 2 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.googlecode.gdxquake2.game.render.GlRenderer.java
License:Open Source License
@Override public Image GL_LoadNewImage(String name, int type) { final Image image = Images.GL_Find_free_image_t(name, type); name = name.toLowerCase();//from w w w.j a va2 s .c o m // int cut = name.lastIndexOf('.'); // String normalizedName = cut == -1 ? name : name.substring(0, cut); Dimension d = GdxQuake2.getImageSize(name); if (d == null) { name = "install/data/baseq2/" + name; } d = GdxQuake2.getImageSize(name); if (d == null) { image.width = 128; image.height = 128; } else { image.width = d.width; image.height = d.height; } final int loadId = GlRenderer.loadId++; image.loadId = loadId; image.pixmap = new Pixmap(image.width, image.height, Pixmap.Format.RGBA8888); pendingImages.add(image); image.ready = false; GdxQuake2.asyncLocalStorage.getFileHandle(name.toLowerCase() + ".png", new Callback<AsyncFileHandle>() { @Override public void onSuccess(AsyncFileHandle result) { AsyncPixmapLoader.loadPixmap(result, new Callback<Pixmap>() { @Override public void onSuccess(Pixmap pixmap) { //Image was recycled in the meantime. if (image.loadId != loadId) { return; } image.pixmap = pixmap; image.ready = true; } @Override public void onFailure(Throwable cause) { cause.printStackTrace(); } }); } @Override public void onFailure(Throwable e) { e.printStackTrace(); } }); /* if (type != com.googlecode.gdxquake2.core.id.common.QuakeImage.it_pic) { GlState.gl.glTexImage2D(TEXTURE_2D, 0, RGBA, HOLODECK_TEXTURE_SIZE, HOLODECK_TEXTURE_SIZE, 0, RGBA, UNSIGNED_BYTE, holoDeckTexture); GlState.gl.glTexParameterf(TEXTURE_2D, TEXTURE_MIN_FILTER, LINEAR); GlState.gl.glTexParameterf(TEXTURE_2D, TEXTURE_MAG_FILTER, LINEAR); }*/ return image; }
From source file:com.googlecode.gdxquake2.installer.ImageConverter.java
License:Open Source License
static Pixmap makeImage(image_t source) { Pixmap image = new Pixmap(source.width, source.height, Pixmap.Format.RGBA8888); int ofs = 0;/* ww w . j a v a 2s .com*/ for (int y = 0; y < source.height; y++) { for (int x = 0; x < source.width; x++) { int rgba = (((source.pix[ofs] & 255) << 24) | ((source.pix[ofs + 1] & 255) << 16) | ((source.pix[ofs + 2] & 255) << 8) | ((source.pix[ofs + 3] & 255))); ofs += 4; image.drawPixel(x, y, rgba); } } return image; }