List of usage examples for com.badlogic.gdx.graphics.glutils PixmapTextureData PixmapTextureData
public PixmapTextureData(Pixmap pixmap, Format format, boolean useMipMaps, boolean disposePixmap)
From source file:com.ridiculousRPG.util.TextureRegionLoader.java
License:Apache License
/** * Obtains a texture region for drawing {@link Pixmap}s on it.<br> * This method creates a texture region with an underlying texture (which is * sized with the next powers of two) for drawing. * /* w w w . j a v a 2 s . c o m*/ * @param width * the width of the texture region * @param height * the height of the texture region * @param format * the format for drawing {@link Pixmap}s onto this TextureRegion * @return A texture region with the specified width and height for drawing * on it. */ public static TextureRegionRef obtainEmptyRegion(int width, int height, final Format format) { final int safeWidth = MathUtils.nextPowerOfTwo(width); final int safeHeight = MathUtils.nextPowerOfTwo(height); final PixmapTextureData ptd = new PixmapTextureData(new Pixmap(safeWidth, safeHeight, format), null, false, true); TextureCache tCache; if (GameBase.$().isGlContextThread()) { tCache = new TextureCache(ptd); } else { final TextureCacheContainer tCC = new TextureCacheContainer(); new ExecWithGlContext() { @Override public void exec() { tCC.tCache = new TextureCache(ptd); } }.runWait(); tCache = tCC.tCache; } return tCache.obtainRegion(0, 0, width, height); }
From source file:com.ridiculousRPG.util.TextureRegionLoader.java
License:Apache License
private static TextureCache obtainCache(FileHandle filePath) { String fileName = filePath.path(); TextureCache tCache = textureCache.get(fileName); if (tCache == null) { final Pixmap pm = new Pixmap(filePath); final int width = pm.getWidth(); final int height = pm.getHeight(); final int safeWidth = MathUtils.nextPowerOfTwo(width); final int safeHeight = MathUtils.nextPowerOfTwo(height); if (width != safeWidth || height != safeHeight) { final PixmapTextureData ptd = new PixmapTextureData( new Pixmap(safeWidth, safeHeight, pm.getFormat()), null, false, true); if (GameBase.$().isGlContextThread()) { tCache = new TextureCache(ptd); tCache.drawPixmap(pm, true); } else { final TextureCacheContainer tCC = new TextureCacheContainer(); new ExecWithGlContext() { @Override/*from w w w . java2 s . c o m*/ public void exec() { tCC.tCache = new TextureCache(ptd); tCC.tCache.drawPixmap(pm, true); } }.runWait(); tCache = tCC.tCache; } } else { if (GameBase.$().isGlContextThread()) { tCache = new TextureCache(pm, true); } else { final TextureCacheContainer tCC = new TextureCacheContainer(); new ExecWithGlContext() { @Override public void exec() { tCC.tCache = new TextureCache(pm, true); } }.runWait(); tCache = tCC.tCache; } } textureCache.put(fileName, tCache); textureReverseCache.put(tCache, fileName); } return tCache; }
From source file:de.longri.cachebox3.gui.help.HelpWindow.java
License:Open Source License
public void show() { if (this.getStageBackground() == null) { if (this.style == null) this.style = VisUI.getSkin().get("default", HelpWindowStyle.class); //create a background texture as stageBackground with a ellipsed hole //Use SVG-drawing for create => http://svg.tutorial.aptico.de/start3.php?knr=10&kname=Pfade&uknr=10.8&ukname=A%20und%20a%20-%20Bogenkurven final Pixmap[] pixmap = new Pixmap[1]; Thread thread = new Thread(new Runnable() { @Override//from w w w . j a va 2 s . c o m public void run() { //replace Template with values String width = Float.toString(Gdx.graphics.getWidth()); String height = Float.toString(Gdx.graphics.getHeight()); String centerX = Float.toString(ellipseRectangle.getCenterPosX()); String posY = Float.toString(Gdx.graphics.getHeight() - ellipseRectangle.getY()); // Y flipped String maxY = Float.toString(Gdx.graphics.getHeight() - ellipseRectangle.getMaxY()); // Y flipped String radiusX = Float.toString(ellipseRectangle.getHalfWidth()); String radiusY = Float.toString(ellipseRectangle.getHalfHeight()); String borderSize = Float.toString(HelpWindow.this.style.borderSize); Color color = HelpWindow.this.style.backgroundColor; String value = Integer.toHexString( ((int) (255 * color.r) << 16) | ((int) (255 * color.g) << 8) | ((int) (255 * color.b))); while (value.length() < 6) value = "0" + value; String fillColor = "#" + value; String fillOpacity = Float.toString(color.a); color = HelpWindow.this.style.borderColor; value = Integer.toHexString( ((int) (255 * color.r) << 16) | ((int) (255 * color.g) << 8) | ((int) (255 * color.b))); while (value.length() < 6) value = "0" + value; String borderColor = "#" + value; String borderOpacity = Float.toString(color.a); String svgString = SVG_TEMPLATE.replaceAll("#WIDTH#", width); svgString = svgString.replaceAll("#HEIGHT#", height); svgString = svgString.replaceAll("#FILLCOLOR#", fillColor); svgString = svgString.replaceAll("#FILLOPACITY#", fillOpacity); svgString = svgString.replaceAll("#BORDERCOLOR#", borderColor); svgString = svgString.replaceAll("#BORDEROPACITY#", borderOpacity); svgString = svgString.replaceAll("centerX", centerX); svgString = svgString.replaceAll("posY", posY); svgString = svgString.replaceAll("radiusX", radiusX); svgString = svgString.replaceAll("radiusY", radiusY); svgString = svgString.replaceAll("maxY", maxY); svgString = svgString.replaceAll("#BORDERSIZE#", borderSize); //create a InputStream from SVG-String InputStream stream = new ByteArrayInputStream(svgString.getBytes(Charset.forName("UTF-8"))); try { pixmap[0] = Utils.getPixmapFromBitmap( PlatformConnector.getSvg("", stream, PlatformConnector.SvgScaleType.NONE, 1)); } catch (IOException e) { e.printStackTrace(); } // create texture on GlThread Gdx.app.postRunnable(new Runnable() { @Override public void run() { Texture texture = new Texture( new PixmapTextureData(pixmap[0], Pixmap.Format.RGBA8888, false, true)); TextureRegion region = new TextureRegion(texture); setStageBackground(new TextureRegionDrawable(region)); } }); } }); thread.start(); } super.show(); }