Search in sources :

Example 31 with BitmapFont

use of com.badlogic.gdx.graphics.g2d.BitmapFont in project libgdx by libgdx.

the class BitmapFontMetricsTest method create.

@Override
public void create() {
    spriteBatch = new SpriteBatch();
    atlas = new TextureAtlas("data/pack");
    smallFont = new BitmapFont();
    font = new BitmapFont(Gdx.files.internal("data/verdana39.fnt"), atlas.findRegion("verdana39"), false);
    font = new BitmapFont(Gdx.files.internal("data/arial-32-pad.fnt"), false);
    renderer = new ShapeRenderer();
    renderer.setProjectionMatrix(spriteBatch.getProjectionMatrix());
}
Also used : TextureAtlas(com.badlogic.gdx.graphics.g2d.TextureAtlas) BitmapFont(com.badlogic.gdx.graphics.g2d.BitmapFont) SpriteBatch(com.badlogic.gdx.graphics.g2d.SpriteBatch) ShapeRenderer(com.badlogic.gdx.graphics.glutils.ShapeRenderer)

Example 32 with BitmapFont

use of com.badlogic.gdx.graphics.g2d.BitmapFont in project libgdx by libgdx.

the class BitmapFontTest method render.

@Override
public void render() {
    // red.a = (red.a + Gdx.graphics.getDeltaTime() * 0.1f) % 1;
    int viewHeight = Gdx.graphics.getHeight();
    Gdx.gl.glClearColor(0, 0, 0, 1);
    Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
    // Test wrapping or truncation with the font directly.
    if (!true) {
        // BitmapFont font = label.getStyle().font;
        BitmapFont font = this.font;
        font.getRegion().getTexture().setFilter(TextureFilter.Nearest, TextureFilter.Nearest);
        font.getData().setScale(2f);
        renderer.begin(ShapeRenderer.ShapeType.Line);
        renderer.setColor(0, 1, 0, 1);
        float w = Gdx.input.getX();
        // w = 855;
        renderer.rect(10, 10, w, 500);
        renderer.end();
        spriteBatch.begin();
        String text = "your new";
        text = "How quickly [RED]daft jumping zebras vex.";
        // text = "Another font wrap is-sue, this time with    multiple whitespace characters.";
        text = "test with AGWlWi      AGWlWi issue";
        if (true) {
            // Test wrap.
            layout.setText(font, text, 0, text.length(), font.getColor(), w, Align.center, true, null);
        } else {
            // Test truncation.
            layout.setText(font, text, 0, text.length(), font.getColor(), w, Align.center, false, "...");
        }
        float meowy = (500 / 2 + layout.height / 2 + 5);
        font.draw(spriteBatch, layout, 10, 10 + meowy);
        spriteBatch.end();
        renderer.begin(ShapeRenderer.ShapeType.Line);
        renderer.setColor(0, 1, 0, 1);
        for (int i = 0, n = layout.runs.size; i < n; i++) {
            GlyphRun r = layout.runs.get(i);
            renderer.rect(10 + r.x, 10 + meowy + r.y, r.width, -font.getLineHeight());
        }
        renderer.end();
        font.getData().setScale(1f);
        return;
    }
    // Test wrapping with label.
    if (false) {
        label.debug();
        label.getStyle().font = font;
        label.setStyle(label.getStyle());
        label.setText("How quickly [RED]daft[] jumping zebras vex.");
        label.setWrap(true);
        //			label.setEllipsis(true);
        label.setAlignment(Align.center, Align.right);
        label.setWidth(Gdx.input.getX() - label.getX());
        label.setHeight(label.getPrefHeight());
    } else {
        // Test various font features.
        spriteBatch.begin();
        String text = "Sphinx of black quartz, judge my vow.";
        font.setColor(Color.RED);
        float x = 100, y = 20;
        float alignmentWidth;
        if (false) {
            alignmentWidth = 0;
            font.draw(spriteBatch, text, x, viewHeight - y, alignmentWidth, Align.right, false);
        }
        if (true) {
            alignmentWidth = 280;
            font.draw(spriteBatch, text, x, viewHeight - y, alignmentWidth, Align.right, true);
        }
        font.draw(spriteBatch, "[", 50, 60, 100, Align.left, true);
        font.getData().markupEnabled = true;
        font.draw(spriteBatch, "[", 100, 60, 100, Align.left, true);
        font.getData().markupEnabled = false;
        // 'R' and 'p' are in different pages
        String txt2 = "this font uses " + multiPageFont.getRegions().size + " texture pages: RpRpRpRpRpNM";
        spriteBatch.renderCalls = 0;
        // regular draw function
        multiPageFont.setColor(Color.BLUE);
        multiPageFont.draw(spriteBatch, txt2, 10, 100);
        // expert usage.. drawing with bitmap font cache
        BitmapFontCache cache = multiPageFont.getCache();
        cache.clear();
        cache.setColor(Color.BLACK);
        cache.setText(txt2, 10, 50);
        cache.setColors(Color.PINK, 3, 6);
        cache.setColors(Color.ORANGE, 9, 12);
        cache.setColors(Color.GREEN, 16, txt2.length());
        cache.draw(spriteBatch, 5, txt2.length() - 5);
        cache.clear();
        cache.setColor(Color.BLACK);
        float textX = 10;
        textX += cache.setText("[black] ", textX, 150).width;
        multiPageFont.getData().markupEnabled = true;
        textX += cache.addText("[[[PINK]pink[]] ", textX, 150).width;
        textX += cache.addText("[PERU][[peru] ", textX, 150).width;
        cache.setColor(Color.GREEN);
        textX += cache.addText("green ", textX, 150).width;
        textX += cache.addText("[#A52A2A]br[#A52A2ADF]ow[#A52A2ABF]n f[#A52A2A9F]ad[#A52A2A7F]in[#A52A2A5F]g o[#A52A2A3F]ut ", textX, 150).width;
        multiPageFont.getData().markupEnabled = false;
        cache.draw(spriteBatch);
        // tinting
        cache.tint(new Color(1f, 1f, 1f, 0.3f));
        cache.translate(0f, 40f);
        cache.draw(spriteBatch);
        spriteBatch.end();
        // System.out.println(spriteBatch.renderCalls);
        renderer.begin(ShapeType.Line);
        renderer.setColor(Color.BLACK);
        renderer.rect(x, viewHeight - y - 200, alignmentWidth, 200);
        renderer.end();
    }
    stage.act(Gdx.graphics.getDeltaTime());
    stage.draw();
}
Also used : GlyphRun(com.badlogic.gdx.graphics.g2d.GlyphLayout.GlyphRun) Color(com.badlogic.gdx.graphics.Color) BitmapFont(com.badlogic.gdx.graphics.g2d.BitmapFont) BitmapFontCache(com.badlogic.gdx.graphics.g2d.BitmapFontCache)

Example 33 with BitmapFont

use of com.badlogic.gdx.graphics.g2d.BitmapFont in project libgdx by libgdx.

the class AssetManagerTest method create.

public void create() {
    Gdx.app.setLogLevel(Application.LOG_ERROR);
    Resolution[] resolutions = { new Resolution(320, 480, ".320480"), new Resolution(480, 800, ".480800"), new Resolution(480, 856, ".480854") };
    ResolutionFileResolver resolver = new ResolutionFileResolver(new InternalFileHandleResolver(), resolutions);
    manager = new AssetManager();
    manager.setLoader(Texture.class, new TextureLoader(resolver));
    manager.setErrorListener(this);
    load();
    Texture.setAssetManager(manager);
    batch = new SpriteBatch();
    font = new BitmapFont(Gdx.files.internal("data/font.fnt"), false);
}
Also used : ResolutionFileResolver(com.badlogic.gdx.assets.loaders.resolvers.ResolutionFileResolver) AssetManager(com.badlogic.gdx.assets.AssetManager) InternalFileHandleResolver(com.badlogic.gdx.assets.loaders.resolvers.InternalFileHandleResolver) TextureLoader(com.badlogic.gdx.assets.loaders.TextureLoader) BitmapFont(com.badlogic.gdx.graphics.g2d.BitmapFont) SpriteBatch(com.badlogic.gdx.graphics.g2d.SpriteBatch) Resolution(com.badlogic.gdx.assets.loaders.resolvers.ResolutionFileResolver.Resolution)

Example 34 with BitmapFont

use of com.badlogic.gdx.graphics.g2d.BitmapFont in project libgdx by libgdx.

the class AssetManagerTest method load.

private void load() {
    // Gdx.app.setLogLevel(Logger.DEBUG);
    start = TimeUtils.nanoTime();
    tex1 = new Texture("data/animation.png");
    tex2 = new TextureAtlas(Gdx.files.internal("data/pack"));
    font2 = new BitmapFont(Gdx.files.internal("data/verdana39.fnt"), false);
    // tex3 = new Texture("data/test.etc1");
    // map = TiledLoader.createMap(Gdx.files.internal("data/tiledmap/tilemap csv.tmx"));
    // atlas = new TileAtlas(map, Gdx.files.internal("data/tiledmap/"));
    // renderer = new TileMapRenderer(map, atlas, 8, 8);
    shader = new ShaderProgram(Gdx.files.internal("data/g2d/batchCommon.vert").readString(), Gdx.files.internal("data/g2d/monochrome.frag").readString());
    System.out.println("plain took: " + (TimeUtils.nanoTime() - start) / 1000000000.0f);
    start = TimeUtils.nanoTime();
    manager.load("data/animation.png", Texture.class);
    // manager.load("data/pack1.png", Texture.class);
    manager.load("data/pack", TextureAtlas.class);
    // manager.load("data/verdana39.png", Texture.class);
    manager.load("data/verdana39.fnt", BitmapFont.class);
    // manager.load("data/multipagefont.fnt", BitmapFont.class);
    // manager.load("data/test.etc1", Texture.class);
    // manager.load("data/tiledmap/tilemap csv.tmx", TileMapRenderer.class, new
    // TileMapRendererLoader.TileMapParameter("data/tiledmap/", 8, 8));
    manager.load("data/i18n/message2", I18NBundle.class, new I18NBundleLoader.I18NBundleParameter(reloads % 2 == 0 ? Locale.ITALIAN : Locale.ENGLISH));
    manager.load("data/g2d/monochrome.frag", ShaderProgram.class, new ShaderProgramLoader.ShaderProgramParameter() {

        {
            vertexFile = "data/g2d/batchCommon.vert";
        }
    });
}
Also used : I18NBundleLoader(com.badlogic.gdx.assets.loaders.I18NBundleLoader) ShaderProgram(com.badlogic.gdx.graphics.glutils.ShaderProgram) TextureAtlas(com.badlogic.gdx.graphics.g2d.TextureAtlas) BitmapFont(com.badlogic.gdx.graphics.g2d.BitmapFont) ShaderProgramLoader(com.badlogic.gdx.assets.loaders.ShaderProgramLoader) Texture(com.badlogic.gdx.graphics.Texture)

Example 35 with BitmapFont

use of com.badlogic.gdx.graphics.g2d.BitmapFont in project libgdx by libgdx.

the class AccelerometerTest method create.

@Override
public void create() {
    font = new BitmapFont(Gdx.files.internal("data/arial-15.fnt"), false);
    batch = new SpriteBatch();
}
Also used : BitmapFont(com.badlogic.gdx.graphics.g2d.BitmapFont) SpriteBatch(com.badlogic.gdx.graphics.g2d.SpriteBatch)

Aggregations

BitmapFont (com.badlogic.gdx.graphics.g2d.BitmapFont)104 SpriteBatch (com.badlogic.gdx.graphics.g2d.SpriteBatch)64 Texture (com.badlogic.gdx.graphics.Texture)31 OrthographicCamera (com.badlogic.gdx.graphics.OrthographicCamera)21 TextureRegion (com.badlogic.gdx.graphics.g2d.TextureRegion)18 Stage (com.badlogic.gdx.scenes.scene2d.Stage)16 OrthoCamController (com.badlogic.gdx.tests.utils.OrthoCamController)13 ShapeRenderer (com.badlogic.gdx.graphics.glutils.ShapeRenderer)12 TextureAtlas (com.badlogic.gdx.graphics.g2d.TextureAtlas)11 Label (com.badlogic.gdx.scenes.scene2d.ui.Label)10 Drawable (com.badlogic.gdx.scenes.scene2d.utils.Drawable)10 AssetManager (com.badlogic.gdx.assets.AssetManager)9 Color (com.badlogic.gdx.graphics.Color)8 Sprite (com.badlogic.gdx.graphics.g2d.Sprite)8 InputAdapter (com.badlogic.gdx.InputAdapter)7 Actor (com.badlogic.gdx.scenes.scene2d.Actor)7 Skin (com.badlogic.gdx.scenes.scene2d.ui.Skin)7 FileHandle (com.badlogic.gdx.files.FileHandle)6 Pixmap (com.badlogic.gdx.graphics.Pixmap)6 GlyphLayout (com.badlogic.gdx.graphics.g2d.GlyphLayout)6