List of usage examples for com.badlogic.gdx.graphics.g2d PixmapPacker PixmapPacker
public PixmapPacker(int width, int height, Format format, int padding, boolean duplicateBorder)
Creates a new ImagePacker which will insert all supplied images into a width
by height
image.
From source file:com.austinerb.project0.engine.SpriterLoader.java
License:Apache License
@Override public void load(final Reference ref, String path) { FileHandle f;/*from w w w . jav a 2 s . c om*/ switch (Gdx.app.getType()) { case iOS: f = Gdx.files.absolute(path); break; default: f = Gdx.files.internal(path); break; } if (!f.exists()) throw new GdxRuntimeException("Could not find file handle " + path + "! Please check your paths."); if (this.packer == null && this.pack) this.packer = new PixmapPacker(this.atlasWidth, this.atlasHeight, Pixmap.Format.RGBA8888, 2, true); final Pixmap pix = new Pixmap(f); this.files.put(ref, null); this.pixmaps.put(ref, pix); }
From source file:com.kotcrab.vis.plugin.spriter.runtime.loader.SpriterLoader.java
License:Apache License
@Override protected Sprite loadResource(FileReference ref) { FileHandle f;// www .j av a2 s. c o m String path = super.root + "/" + data.getFile(ref).name; switch (Gdx.app.getType()) { case iOS: f = Gdx.files.absolute(path); break; default: f = Gdx.files.internal(path); break; } if (!f.exists()) throw new GdxRuntimeException("Could not find file handle " + path + "! Please check your paths."); if (this.packer == null && this.pack) this.packer = new PixmapPacker(this.atlasWidth, this.atlasHeight, Pixmap.Format.RGBA8888, 2, true); final Pixmap pix = new Pixmap(f); this.pixmaps.put(ref, pix); return null; }
From source file:com.me.gdxspriter.SpriterLoader.java
License:Apache License
@Override public void load(final Reference ref, String path) { if (packer == null && this.pack) packer = new PixmapPacker(2048, 2048, Pixmap.Format.RGBA8888, 2, true); final Pixmap pix = new Pixmap(Gdx.files.internal(path)); if (packer != null) packer.pack(ref.fileName, pix);//from w ww .j a v a2s.co m files.put(ref, null);//Put first the reference into the map, in the next frame, the null value will be replaced with the actual texture. Gdx.app.postRunnable(new Runnable() { //Post the creation of a OpenGL Texture to the LibGDX rendering thread. //This is necessary if you are loading the scml file asynchrouously with more than one thread. @Override public void run() { files.put(ref, createSprite(new Texture(pix))); pix.dispose(); } }); }
From source file:com.pogs.runpogsrun.util.SpriterLoader.java
License:Apache License
@Override public void load(final Reference ref, String path) { FileHandle f;//from ww w . j ava 2s .c om switch (Gdx.app.getType()) { case iOS: f = Gdx.files.absolute(path); break; default: f = Gdx.files.internal(path); break; } if (!f.exists()) throw new GdxRuntimeException("Could not find file handle " + path + "! Please check your paths."); if (this.packer == null && this.pack) this.packer = new PixmapPacker(this.atlasWidth, this.atlasHeight, Pixmap.Format.RGBA8888, 2, true); final Pixmap pix; Texture tex; TextureRegion texRegion; if (!Gdx.graphics.isGL20Available()) { Pixmap temp = new Pixmap(f); pix = new Pixmap(MathUtils.nextPowerOfTwo(temp.getWidth()), MathUtils.nextPowerOfTwo(temp.getHeight()), temp.getFormat()); pix.drawPixmap(temp, 0, 0); tex = new Texture(pix); texRegion = new TextureRegion(tex, temp.getWidth(), temp.getHeight()); temp.dispose(); } else { pix = new Pixmap(f); tex = new Texture(pix); texRegion = new TextureRegion(tex, pix.getWidth(), pix.getHeight()); } tex.setFilter(TextureFilter.Linear, TextureFilter.Linear); if (this.packer != null) packer.pack(ref.fileName, pix); this.files.put(ref, new Sprite(texRegion)); pix.dispose(); }
From source file:com.randombot.theme.Ttf2FntGenerator.java
License:Open Source License
/** * Convenience method for generating a font, and then writing the fnt and * png files. Writing a generated font to files allows the possibility of * only generating the fonts when they are missing, otherwise loading from a * previously generated file.//from ww w . ja v a 2s .com * * @param fontFile * @param fontSize * @param destiny */ private void generateFiles(String fontName, FileHandle fontFile, int fontSize, int pageWidth, int pageHeight, FileHandle destiny) { FreeTypeFontGenerator generator = new FreeTypeFontGenerator(fontFile); PixmapPacker packer = new PixmapPacker(pageWidth, pageHeight, Pixmap.Format.RGBA8888, 2, false); FreeTypeFontParameter param = new FreeTypeFontParameter(); param.packer = packer; param.characters = FreeTypeFontGenerator.DEFAULT_CHARS; param.size = fontSize; param.flip = false; FreeTypeFontGenerator.FreeTypeBitmapFontData fontData = generator.generateData(param); saveFontToFile(fontData, fontSize, fontName, packer, destiny); generator.dispose(); packer.dispose(); }
From source file:com.spritertest.SpriterLoader.java
License:Apache License
@Override public void load(Reference ref, String path) { if (packer == null && this.pack) packer = new PixmapPacker(1024, 1024, Pixmap.Format.RGBA8888, 2, true); Pixmap pix = new Pixmap(Gdx.files.internal(path)); if (packer != null) packer.pack(ref.fileName, pix);/*from w w w .java 2 s . c o m*/ files.put(ref, this.createSprite(new Texture(pix))); pix.dispose(); }
From source file:es.eucm.ead.maven.GenerateSkinMojo.java
License:Open Source License
/** * Convenience method for generating a font, and then writing the fnt and * png files. Writing a generated font to files allows the possibility of * only generating the fonts when they are missing, otherwise loading from a * previously generated file.//from w w w. j a v a 2 s . com * * @param fontFile * @param fontSize * @param destiny */ private void generateFiles(String fontName, FileHandle fontFile, int fontSize, FileHandle destiny) { FreeTypeFontGenerator generator = new FreeTypeFontGenerator(fontFile); // compute the minimum page size for a square png FreeType.Library library = FreeType.initFreeType(); FreeType.Face face = FreeType.newFace(library, fontFile, 0); FreeType.setPixelSizes(face, 0, fontSize); FreeType.SizeMetrics fontMetrics = face.getSize().getMetrics(); float scale = FreeType.toInt(fontMetrics.getHeight()); for (int c = 32; c < (32 + face.getNumGlyphs()); c++) { if (FreeType.loadChar(face, c, FreeType.FT_LOAD_DEFAULT)) { int lh = FreeType.toInt(face.getGlyph().getMetrics().getHeight()); scale = (lh > scale) ? lh : scale; } } // generate the glyphs int maxGlyphHeight = (int) Math.ceil(scale); float area = maxGlyphHeight * maxGlyphHeight * FreeTypeFontGenerator.DEFAULT_CHARS.length(); int pageWidth = MathUtils.nextPowerOfTwo((int) Math.sqrt(area)); pageWidth = Math.min(pageWidth, 1024); PixmapPacker packer = new PixmapPacker(pageWidth, pageWidth, Pixmap.Format.RGBA8888, 2, false); FreeTypeFontGenerator.FreeTypeFontParameter param = new FreeTypeFontGenerator.FreeTypeFontParameter(); param.packer = packer; param.characters = FreeTypeFontGenerator.DEFAULT_CHARS; param.size = fontSize; param.flip = false; FreeTypeFontGenerator.FreeTypeBitmapFontData fontData = generator.generateData(param); saveFontToFile(fontData, fontSize, fontName, packer, destiny); generator.dispose(); packer.dispose(); }
From source file:es.eucm.piel.fonts.TTFtoFNT.java
License:Apache License
public void toFnt(int size, float scale, int atlasSize, String characters, File dst) { int fontSize = (int) (size * scale); PixmapPacker packer = new PixmapPacker(atlasSize, atlasSize, Pixmap.Format.RGBA8888, 2, false); FreeTypeFontParameter parameter = new FreeTypeFontParameter(); parameter.packer = packer;/*from www . ja va2 s . c o m*/ parameter.characters = characters == null ? FreeTypeFontGenerator.DEFAULT_CHARS : characters; parameter.size = fontSize; parameter.flip = false; FreeTypeBitmapFontData data = generator.generateData(parameter); String fontName = ttfName + "-" + size; BitmapFontWriter.setOutputFormat(BitmapFontWriter.OutputFormat.Text); String[] pageRefs = BitmapFontWriter.writePixmaps(parameter.packer.getPages(), new FileHandle(dst), fontName); BitmapFontWriter.writeFont(data, pageRefs, new FileHandle(new File(dst, fontName + ".fnt")), new BitmapFontWriter.FontInfo(fontName, size), 1, 1); }