/** Inserts the pixmap without a name. It cannot be looked up by name. * @see #pack(String, Pixmap) */ public synchronized Rectangle pack (Pixmap image) { return pack(null, image); }
/** Creates a new page filled with the color provided by the {@link PixmapPacker#getTransparentColor()} */ public Page (PixmapPacker packer) { image = new Pixmap(packer.pageWidth, packer.pageHeight, packer.pageFormat); final Color transparentColor = packer.getTransparentColor(); this.image.setColor(transparentColor); this.image.fill(); }
@Override public void dispose () { if (stroker != null) stroker.dispose(); if (packer != null) packer.dispose(); } }
public void getGlyphs (GlyphRun run, CharSequence str, int start, int end, Glyph lastGlyph) { if (packer != null) packer.setPackToTexture(true); // All glyphs added after this are packed directly to the texture. super.getGlyphs(run, str, start, end, lastGlyph); if (dirty) { dirty = false; packer.updateTextureRegions(regions, parameter.minFilter, parameter.magFilter, parameter.genMipMaps); } }
PixmapPacker packer = new PixmapPacker(1024, 1024, Format.RGBA8888, 8, false, true, true, new PixmapPacker.GuillotineStrategy()); packer.setTransparentColor(Color.PINK); for (int count = 1; count <= 3; ++count) { packer.pack("badlogic " + count, pixmap1); packer.pack("fire " + count, pixmap2); packer.pack("isotile " + count, pixmap3); packer.pack("textfield-" + count + ".9", pixmap4); packer.pack("badlogic-whitespace " + count, pixmap5); atlas = packer.generateTextureAtlas(TextureFilter.Nearest, TextureFilter.Nearest, false); Gdx.app.log("PixmapPackerTest", "Number of initial textures: " + atlas.getTextures().size); packer.setPackToTexture(true); packer.pack("badlogic " + count, pixmap1); packer.pack("fire " + count, pixmap2); packer.pack("isotile " + count, pixmap3); packer.pack("textfield-" + count + ".9", pixmap4); packer.pack("badlogic-whitespace -" + count, pixmap5); packer.pack("badlogic-anim_0", pixmap1); packer.pack("badlogic-anim_1", pixmap5); packer.pack("badlogic-anim_2", pixmap1); packer.pack("badlogic-anim_3", pixmap5); packer.updateTextureAtlas(atlas, TextureFilter.Nearest, TextureFilter.Nearest, false); animation = new Animation<TextureRegion>(0.33f, atlas.findRegions("badlogic-anim"), Animation.PlayMode.LOOP);
packer = new PixmapPacker(size, size, Format.RGBA8888, 1, false, packStrategy); packer.setTransparentColor(parameter.color); packer.getTransparentColor().a = 0; if (parameter.borderWidth > 0) { packer.setTransparentColor(parameter.borderColor); packer.getTransparentColor().a = 0; packer.updateTextureRegions(data.regions, parameter.minFilter, parameter.magFilter, parameter.genMipMaps);
Rectangle rect = packer.pack(mainPixmap); glyph.page = packer.getPages().size - 1; // Glyph is always packed into the last page for now. glyph.srcX = (int)rect.x; glyph.srcY = (int)rect.y; packer.updateTextureRegions(data.regions, parameter.minFilter, parameter.magFilter, parameter.genMipMaps);
if (packer == null)packer = new PixmapPacker(pageWidth, pageWidth, Format.RGBA8888, 2, true); if (atlas == null)atlas = new TextureAtlas(); for (String path : inpacks) { pixmap = assets.get(path, Pixmap.class); packer.pack(path, pixmap); assets.unload(path); } catch (Exception e) { packer.updateTextureAtlas(atlas, filter, filter, false); for (Page page : packer.getPages()) { page.getPixmap().dispose(); packer.dispose(); packer = null; inpacks.clear();
PixmapPacker packer = new PixmapPacker(FONT_ATLAS_WIDTH, FONT_ATLAS_HEIGHT, Format.RGBA8888, 2, false); packer.updateTextureRegions(regions, TextureFilter.Nearest, TextureFilter.Nearest, false); packer.dispose();
param.shadowColor = new Color(0, 0, 0, 1); param.characters = Hiero.EXTENDED_CHARS; param.packer = new PixmapPacker(1024, 1024, Pixmap.Format.RGBA8888, 2, false, new PixmapPacker.SkylineStrategy()); BitmapFontWriter.writePixmaps(param.packer.getPages(), Gdx.files.local(""), "bitmapWrittenFont");
/** Updates the {@link TextureAtlas}, adding any new {@link Pixmap} instances packed since the last call to this method. This * can be used to insert Pixmap instances on a separate thread via {@link #pack(String, Pixmap)} and update the TextureAtlas on * the rendering thread. This method must be called on the rendering thread. After calling this method, disposing the packer * will no longer dispose the page pixmaps. Has useIndexes on by default so as to keep backwards compatibility*/ public synchronized void updateTextureAtlas (TextureAtlas atlas, TextureFilter minFilter, TextureFilter magFilter, boolean useMipMaps) { updateTextureAtlas(atlas, minFilter, magFilter, useMipMaps, true); }
packer = new PixmapPacker(FONT_ATLAS_WIDTH, FONT_ATLAS_HEIGHT, Format.RGBA8888, 2, false);
private void putGlyph(int id, Pixmap pixmap) { Rectangle rect = packer.pack(id + "", pixmap); pixmap.dispose(); int pIndex = packer.getPageIndex(id + ""); Glyph glyph = new Glyph(); glyph.id = id; glyph.page = pIndex; glyph.srcX = (int) rect.x; glyph.srcY = (int) rect.y; glyph.width = (int) rect.width; glyph.height = (int) rect.height; glyph.xadvance = (int)rect.width; data.setGlyph(id, glyph); }
@Override public void create() { camera = new OrthographicCamera(); batch = new SpriteBatch(); long start = System.currentTimeMillis(); int glyphCount = createFonts(); long time = System.currentTimeMillis() - start; text = glyphCount + " glyphs packed in " + packer.getPages().size + " page(s) in " + time + " ms"; }
/** Generates a new {@link BitmapFont}. The size is expressed in pixels. Throws a GdxRuntimeException if the font could not be * generated. Using big sizes might cause such an exception. * @param parameter configures how the font is generated */ public BitmapFont generateFont (FreeTypeFontParameter parameter, FreeTypeBitmapFontData data) { boolean updateTextureRegions = data.regions == null && parameter.packer != null; if (updateTextureRegions) data.regions = new Array(); generateData(parameter, data); if (updateTextureRegions) parameter.packer.updateTextureRegions(data.regions, parameter.minFilter, parameter.magFilter, parameter.genMipMaps); if (data.regions.isEmpty()) throw new GdxRuntimeException("Unable to create a font with no texture regions."); BitmapFont font = new BitmapFont(data, data.regions, true); font.setOwnsTexture(parameter.packer == null); return font; }
Pixmap pixmap5 = new Pixmap(Gdx.files.internal("data/badlogic-with-whitespace.png")); PixmapPacker packer = new PixmapPacker(1024, 1024, Format.RGBA8888, 8, false, true, true, new PixmapPacker.GuillotineStrategy()); packer.setTransparentColor(Color.PINK); for (int count = 1; count <= 3; ++count) { packer.pack("badlogic " + count, pixmap1); packer.pack("fire " + count, pixmap2); packer.pack("isotile " + count, pixmap3); packer.pack("textfield-" + count + ".9", pixmap4); packer.pack("badlogic-whitespace " + count, pixmap5); atlas = packer.generateTextureAtlas(TextureFilter.Nearest, TextureFilter.Nearest, false); Gdx.app.log("PixmapPackerTest", "Number of initial textures: " + atlas.getTextures().size); packer.setPackToTexture(true); packer.pack("badlogic " + count, pixmap1); packer.pack("fire " + count, pixmap2); packer.pack("isotile " + count, pixmap3); packer.pack("textfield-" + count + ".9", pixmap4); packer.pack("badlogic-whitespace -" + count, pixmap5); packer.updateTextureAtlas(atlas, TextureFilter.Nearest, TextureFilter.Nearest, false); textureRegions = new Array<TextureRegion>(); packer.updateTextureRegions(textureRegions, TextureFilter.Nearest, TextureFilter.Nearest, false); Gdx.app.log("PixmapPackerTest", "Number of updated textures: " + atlas.getTextures().size); Gdx.input.setInputProcessor(new InputAdapter() {
packer = new PixmapPacker(size, size, Format.RGBA8888, 1, false, packStrategy); packer.setTransparentColor(parameter.color); packer.getTransparentColor().a = 0; if (parameter.borderWidth > 0) { packer.setTransparentColor(parameter.borderColor); packer.getTransparentColor().a = 0; packer.updateTextureRegions(data.regions, parameter.minFilter, parameter.magFilter, parameter.genMipMaps);
Rectangle rect = packer.pack(mainPixmap); glyph.page = packer.getPages().size - 1; // Glyph is always packed into the last page for now. glyph.srcX = (int)rect.x; glyph.srcY = (int)rect.y; packer.updateTextureRegions(data.regions, parameter.minFilter, parameter.magFilter, parameter.genMipMaps);
public void getGlyphs (GlyphRun run, CharSequence str, int start, int end, Glyph lastGlyph) { if (packer != null) packer.setPackToTexture(true); // All glyphs added after this are packed directly to the texture. super.getGlyphs(run, str, start, end, lastGlyph); if (dirty) { dirty = false; packer.updateTextureRegions(regions, parameter.minFilter, parameter.magFilter, parameter.genMipMaps); } }
/** Updates the {@link TextureAtlas}, adding any new {@link Pixmap} instances packed since the last call to this method. This * can be used to insert Pixmap instances on a separate thread via {@link #pack(String, Pixmap)} and update the TextureAtlas on * the rendering thread. This method must be called on the rendering thread. After calling this method, disposing the packer * will no longer dispose the page pixmaps. Has useIndexes on by default so as to keep backwards compatibility*/ public synchronized void updateTextureAtlas (TextureAtlas atlas, TextureFilter minFilter, TextureFilter magFilter, boolean useMipMaps) { updateTextureAtlas(atlas, minFilter, magFilter, useMipMaps, true); }