Search in sources :

Example 6 with PixmapPacker

use of com.badlogic.gdx.graphics.g2d.PixmapPacker in project TooCruelPixelDungeon by juh9870.

the class AndroidPlatformSupport method setupFontGenerators.

@Override
public void setupFontGenerators(int pageSize, boolean systemfont) {
    // don't bother doing anything if nothing has changed
    if (fonts != null && this.pageSize == pageSize && this.systemfont == systemfont) {
        return;
    }
    this.pageSize = pageSize;
    this.systemfont = systemfont;
    resetGenerators(false);
    fonts = new HashMap<>();
    basicFontGenerator = KRFontGenerator = SCFontGenerator = JPFontGenerator = null;
    if (systemfont && Gdx.files.absolute("/system/fonts/Roboto-Regular.ttf").exists()) {
        basicFontGenerator = new FreeTypeFontGenerator(Gdx.files.absolute("/system/fonts/Roboto-Regular.ttf"));
    } else if (systemfont && Gdx.files.absolute("/system/fonts/DroidSans.ttf").exists()) {
        basicFontGenerator = new FreeTypeFontGenerator(Gdx.files.absolute("/system/fonts/DroidSans.ttf"));
    } else {
        basicFontGenerator = new FreeTypeFontGenerator(Gdx.files.internal("fonts/pixel_font.ttf"));
    }
    // android 7.0+. all asian fonts are nicely contained in one spot
    if (Gdx.files.absolute("/system/fonts/NotoSansCJK-Regular.ttc").exists()) {
        // typefaces are 0-JP, 1-KR, 2-SC, 3-TC.
        int typeFace;
        switch(SPDSettings.language()) {
            case JAPANESE:
                typeFace = 0;
                break;
            case KOREAN:
                typeFace = 1;
                break;
            case CHINESE:
            default:
                typeFace = 2;
        }
        KRFontGenerator = SCFontGenerator = JPFontGenerator = new FreeTypeFontGenerator(Gdx.files.absolute("/system/fonts/NotoSansCJK-Regular.ttc"), typeFace);
    // otherwise we have to go over a few possibilities.
    } else {
        // Korean font generators
        if (Gdx.files.absolute("/system/fonts/NanumGothic.ttf").exists()) {
            KRFontGenerator = new FreeTypeFontGenerator(Gdx.files.absolute("/system/fonts/NanumGothic.ttf"));
        } else if (Gdx.files.absolute("/system/fonts/NotoSansKR-Regular.otf").exists()) {
            KRFontGenerator = new FreeTypeFontGenerator(Gdx.files.absolute("/system/fonts/NotoSansKR-Regular.otf"));
            koreanAndroid6OTF = true;
        }
        // Chinese font generators
        if (Gdx.files.absolute("/system/fonts/NotoSansSC-Regular.otf").exists()) {
            SCFontGenerator = new FreeTypeFontGenerator(Gdx.files.absolute("/system/fonts/NotoSansSC-Regular.otf"));
        } else if (Gdx.files.absolute("/system/fonts/NotoSansHans-Regular.otf").exists()) {
            SCFontGenerator = new FreeTypeFontGenerator(Gdx.files.absolute("/system/fonts/NotoSansHans-Regular.otf"));
        }
        // Japaneses font generators
        if (Gdx.files.absolute("/system/fonts/NotoSansJP-Regular.otf").exists()) {
            JPFontGenerator = new FreeTypeFontGenerator(Gdx.files.absolute("/system/fonts/NotoSansJP-Regular.otf"));
        }
        // set up a fallback generator for any remaining fonts
        FreeTypeFontGenerator fallbackGenerator;
        if (Gdx.files.absolute("/system/fonts/DroidSansFallback.ttf").exists()) {
            fallbackGenerator = new FreeTypeFontGenerator(Gdx.files.absolute("/system/fonts/DroidSansFallback.ttf"));
        } else {
            // no fallback font, just set to null =/
            fallbackGenerator = null;
        }
        if (KRFontGenerator == null)
            KRFontGenerator = fallbackGenerator;
        if (SCFontGenerator == null)
            SCFontGenerator = fallbackGenerator;
        if (JPFontGenerator == null)
            JPFontGenerator = fallbackGenerator;
    }
    if (basicFontGenerator != null)
        fonts.put(basicFontGenerator, new HashMap<>());
    if (KRFontGenerator != null)
        fonts.put(KRFontGenerator, new HashMap<>());
    if (SCFontGenerator != null)
        fonts.put(SCFontGenerator, new HashMap<>());
    if (JPFontGenerator != null)
        fonts.put(JPFontGenerator, new HashMap<>());
    // would be nice to use RGBA4444 to save memory, but this causes problems on some gpus =S
    packer = new PixmapPacker(pageSize, pageSize, Pixmap.Format.RGBA8888, 1, false);
}
Also used : FreeTypeFontGenerator(com.badlogic.gdx.graphics.g2d.freetype.FreeTypeFontGenerator) HashMap(java.util.HashMap) PixmapPacker(com.badlogic.gdx.graphics.g2d.PixmapPacker) SuppressLint(android.annotation.SuppressLint)

Example 7 with PixmapPacker

use of com.badlogic.gdx.graphics.g2d.PixmapPacker in project TooCruelPixelDungeon by juh9870.

the class IOSPlatformSupport method setupFontGenerators.

@Override
public void setupFontGenerators(int pageSize, boolean systemfont) {
    // don't bother doing anything if nothing has changed
    if (fonts != null && this.pageSize == pageSize && this.systemfont == systemfont) {
        return;
    }
    this.pageSize = pageSize;
    this.systemfont = systemfont;
    resetGenerators(false);
    fonts = new HashMap<>();
    if (systemfont) {
        basicFontGenerator = asianFontGenerator = new FreeTypeFontGenerator(Gdx.files.internal("fonts/droid_sans.ttf"));
    } else {
        basicFontGenerator = new FreeTypeFontGenerator(Gdx.files.internal("fonts/pixel_font.ttf"));
        asianFontGenerator = new FreeTypeFontGenerator(Gdx.files.internal("fonts/droid_sans.ttf"));
    }
    fonts.put(basicFontGenerator, new HashMap<>());
    fonts.put(asianFontGenerator, new HashMap<>());
    packer = new PixmapPacker(pageSize, pageSize, Pixmap.Format.RGBA8888, 1, false);
}
Also used : FreeTypeFontGenerator(com.badlogic.gdx.graphics.g2d.freetype.FreeTypeFontGenerator) PixmapPacker(com.badlogic.gdx.graphics.g2d.PixmapPacker)

Example 8 with PixmapPacker

use of com.badlogic.gdx.graphics.g2d.PixmapPacker in project var3dframe by Var3D.

the class FreeBitmapFont method createForEmoji.

private void createForEmoji(String characters, boolean haveMinPageSize) {
    // characters = characters.replaceAll("[\\t\\n\\x0B\\f\\r]", "");
    cs.clear();
    char[] chars = characters.toCharArray();
    for (int i = 0, len = chars.length; i < len; i++) {
        char ch = chars[i];
        String txt = String.valueOf(ch);
        boolean isEmoji = isEmojiCharacter(ch);
        if (isEmoji) {
            if (i + 1 < len) {
                txt += chars[i + 1];
                i++;
            }
        }
        if (charSet.add(txt))
            cs.add(txt);
    }
    // 根据字符参数和字符数量计算一个最小尺寸
    if (haveMinPageSize) {
        pageWidth = (paint.getTextSize() + 2) * (int) (Math.sqrt(cs.size) + 1);
    }
    if (packer == null) {
        packer = new PixmapPacker(pageWidth, pageWidth, Format.RGBA8888, 4, false);
    }
    for (int i = 0; i < cs.size; i++) {
        String txt = cs.get(i);
        char c;
        if (txt.length() == 1) {
            // 判断该符号是否在key库中
            boolean isNotKey = emojiKey.indexOf(txt) < 0;
            if (isNotKey) {
                c = txt.charAt(0);
                if (data.getGlyph(c) != null)
                    continue;
            } else {
                // 如果是key库的一员,那么给它映射一下
                boolean isCreated = isCreatedEmoji2(txt);
                // 如果创建过的,就跳过
                if (isCreated)
                    continue;
                if (ekid > emojiKey.length() - 1)
                    continue;
                // 如果没有创建过,就取一个key来用
                String key = emojiKey.substring(ekid++, ekid);
                c = key.charAt(0);
                Emoji emoj = new Emoji();
                emoj.text = txt;
                emoj.key = key;
                emojis2.add(emoj);
            // Gdx.app.log("aaaaaaa", "keyd=" + emoj.key);
            }
        } else {
            // 说明是emoji
            boolean isCreated = isCreatedEmoji4(txt);
            // 如果创建过的,就跳过
            if (isCreated)
                continue;
            if (ekid > emojiKey.length() - 1)
                continue;
            // 如果没有创建过,就取一个key来用
            String key = emojiKey.substring(ekid++, ekid);
            c = key.charAt(0);
            Emoji emoj = new Emoji();
            emoj.text = txt;
            emoj.key = key;
            emojis4.add(emoj);
        }
        if (data.getGlyph(c) != null)
            continue;
        putGlyph(c, listener.getFontPixmap(txt, paint));
    }
    upData();
    // 如果只有一张纹理,则设置使用一张纹理,提高运行速度
    if (getRegions().size == 1) {
        setOwnsTexture(true);
    } else {
        setOwnsTexture(false);
    }
}
Also used : PixmapPacker(com.badlogic.gdx.graphics.g2d.PixmapPacker)

Example 9 with PixmapPacker

use of com.badlogic.gdx.graphics.g2d.PixmapPacker in project var3dframe by Var3D.

the class FreeBitmapFont method create.

private void create(String characters, boolean haveMinPageSize) {
    if (!isEmoji) {
        characters = characters.replaceAll("[\\t\\n\\x0B\\f\\r]", "");
        cs.clear();
        char[] chars = characters.toCharArray();
        for (char c : chars) {
            if (charSet.add(c + "")) {
                cs.add(c + "");
            }
        }
        // 根据字符参数和字符数量计算一个最小尺寸
        if (haveMinPageSize) {
            pageWidth = (paint.getTextSize() + 2) * (int) (Math.sqrt(cs.size) + 1);
        }
        if (packer == null) {
            packer = new PixmapPacker(pageWidth, pageWidth, Format.RGBA8888, 4, false);
        }
        for (int i = 0; i < cs.size; i++) {
            String txt = cs.get(i);
            char c = txt.charAt(0);
            // 如果该字符存在于emoji地址库里,则创建这个emoji的纹理
            String css = c + "";
            if (emojiSet.get(css) != null) {
                charSet.remove(css);
                EmojiDate date = emojiSet.get(css);
                appendEmoji("" + c, date.path, date.size);
                continue;
            }
            putGlyph(c, listener.getFontPixmap(txt, paint));
        }
        // updataSize(size);
        upData();
        // 如果只有一张纹理,则设置使用一张纹理,提高运行速度
        if (getRegions().size == 1) {
            setOwnsTexture(true);
        } else {
            setOwnsTexture(false);
        }
    } else {
        createForEmoji(characters, haveMinPageSize);
    }
}
Also used : PixmapPacker(com.badlogic.gdx.graphics.g2d.PixmapPacker)

Example 10 with PixmapPacker

use of com.badlogic.gdx.graphics.g2d.PixmapPacker in project var3dframe by Var3D.

the class VGame method render.

public void render() {
    if (isLoading) {
        if (backgroundColor != null)
            clean(backgroundColor);
        if (assets.update()) {
            Array<Texture> out = new Array<Texture>();
            assets.getAll(Texture.class, out);
            for (Texture tex : out) {
                tex.setFilter(filter, filter);
            }
            if (isProtect && !isReProtect) {
                Array<PixmapPro> outPixmapPro = new Array<PixmapPro>();
                assets.getAll(PixmapPro.class, outPixmapPro);
                if (outPixmapPro.size > 0) {
                    if (atlas == null)
                        atlas = new TextureAtlas();
                    for (PixmapPro pix : outPixmapPro) {
                        Texture texture = pix.getTextrue();
                        texture.setFilter(filter, filter);
                        atlas.addRegion(pix.getName(), new TextureRegion(texture));
                        assets.unload(pix.getName());
                    }
                }
            }
            if (inpacks.size > 0) {
                // 将散图打包到大图
                if (packer == null)
                    packer = new PixmapPacker(pageWidth, pageWidth, Format.RGBA8888, 2, true);
                if (atlas == null)
                    atlas = new TextureAtlas();
                for (String path : inpacks) {
                    try {
                        Pixmap pixmap;
                        if (isProtect && !isReProtect) {
                            pixmap = assets.get(path, PixmapPro.class).getPixmap();
                        } else {
                            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();
            }
            if (inModels.size > 0) {
                // 将散模型打包到模型库
                if (packer == null)
                    packer = new PixmapPacker(pageWidthModel, pageWidthModel, Format.RGBA8888, 2, true);
                if (atlas == null)
                    atlas = new TextureAtlas();
                for (String path : inModels) {
                    Model addModel = assets.get(path);
                    if (model == null) {
                        model = addModel;
                        packRegion(model.materials, path);
                    } else {
                        packRegion(addModel.materials, path);
                        model.nodes.addAll(addModel.nodes);
                        model.animations.addAll(addModel.animations);
                        model.materials.addAll(addModel.materials);
                        model.meshes.addAll(addModel.meshes);
                        model.meshParts.addAll(addModel.meshParts);
                    }
                }
                // 移除所有动画里面的所属前缀
                Array<Animation> animations = model.animations;
                for (Animation animation : animations) {
                    animation.id = animation.id.substring(animation.id.lastIndexOf("|") + 1);
                }
                packer.dispose();
                packer = null;
                inModels.clear();
            }
            if (stage != null) {
                stage.init();
                stage.show();
                stage.act();
                stage.draw();
                stageStartTime = System.currentTimeMillis();
            }
            isLoading = false;
        }
        if (stageLoad != null) {
            stageLoad.act(assets.getProgress());
            stageLoad.draw();
        }
    } else {
        if (stage != null) {
            if (backgroundColor != null)
                clean(backgroundColor);
            stage.act();
            stage.draw();
        }
        stageTop.act();
        stageTop.draw();
        Batch batch = stageTop.getBatch();
        if (iphoneX != null) {
            batch.begin();
            batch.setColor(Color.WHITE);
            batch.draw(iphoneX, 0, 0, WIDTH, HEIGHT);
            batch.end();
        }
        if (isShowFps) {
            switch(Gdx.app.getType()) {
                case Android:
                    refushFps();
                    break;
                case Desktop:
                    Display.setTitle(getHeap());
                    break;
                case iOS:
                    break;
            }
        }
        if (soundRuns.size > 0) {
            // 从音效池里拖一个音效出来播放,该构造避免同一帧播放过多音效导致播放失败
            soundRuns.removeIndex(0).run();
        }
    }
}
Also used : Page(com.badlogic.gdx.graphics.g2d.PixmapPacker.Page) Texture(com.badlogic.gdx.graphics.Texture) InvocationTargetException(java.lang.reflect.InvocationTargetException) GdxRuntimeException(com.badlogic.gdx.utils.GdxRuntimeException) IOException(java.io.IOException) Array(com.badlogic.gdx.utils.Array) TextureRegion(com.badlogic.gdx.graphics.g2d.TextureRegion) PixmapPacker(com.badlogic.gdx.graphics.g2d.PixmapPacker) Batch(com.badlogic.gdx.graphics.g2d.Batch) TextureAtlas(com.badlogic.gdx.graphics.g2d.TextureAtlas) Model(com.badlogic.gdx.graphics.g3d.Model) Animation(com.badlogic.gdx.graphics.g3d.model.Animation) Pixmap(com.badlogic.gdx.graphics.Pixmap)

Aggregations

PixmapPacker (com.badlogic.gdx.graphics.g2d.PixmapPacker)17 FreeTypeFontGenerator (com.badlogic.gdx.graphics.g2d.freetype.FreeTypeFontGenerator)11 BitmapFont (com.badlogic.gdx.graphics.g2d.BitmapFont)3 TextureRegion (com.badlogic.gdx.graphics.g2d.TextureRegion)3 SuppressLint (android.annotation.SuppressLint)2 FileHandle (com.badlogic.gdx.files.FileHandle)2 Pixmap (com.badlogic.gdx.graphics.Pixmap)2 Array (com.badlogic.gdx.utils.Array)2 GdxRuntimeException (com.badlogic.gdx.utils.GdxRuntimeException)2 HashMap (java.util.HashMap)2 ApplicationAdapter (com.badlogic.gdx.ApplicationAdapter)1 InputAdapter (com.badlogic.gdx.InputAdapter)1 LwjglApplication (com.badlogic.gdx.backends.lwjgl.LwjglApplication)1 LwjglApplicationConfiguration (com.badlogic.gdx.backends.lwjgl.LwjglApplicationConfiguration)1 Color (com.badlogic.gdx.graphics.Color)1 OrthographicCamera (com.badlogic.gdx.graphics.OrthographicCamera)1 Texture (com.badlogic.gdx.graphics.Texture)1 Batch (com.badlogic.gdx.graphics.g2d.Batch)1 BitmapFontData (com.badlogic.gdx.graphics.g2d.BitmapFont.BitmapFontData)1 Glyph (com.badlogic.gdx.graphics.g2d.BitmapFont.Glyph)1