1
\$\begingroup\$

I want to render text to bitmap to use it later as a decal texture. I've read through libGDX fonts drawing code and came up with this:

private void writeTextToPixmap(Pixmap destPixmap, Pixmap fontPixmap, BitmapFont.BitmapFontData fontData, int startX, int startY, String text) {
    int cursor = startX;

    char[] chars = text.toCharArray();
    for(int i = 0; i < chars.length; i++) {
        BitmapFont.Glyph glyph = fontData.getGlyph(chars[i]);
        destPixmap.drawPixmap(fontPixmap, glyph.srcX, glyph.srcY, glyph.width, glyph.height, cursor + glyph.xoffset, startY + glyph.yoffset, glyph.width, glyph.height);
        cursor += glyph.xadvance;
    }
}

The font was generated with Hiero using default settings.

But the result does not look as expected: http://i.imgur.com/T7Isg2R.png

Usage:

    Pixmap pixmap = new Pixmap(1024, 1024, Pixmap.Format.RGBA8888);
    BitmapFont.BitmapFontData fontData = new BitmapFont.BitmapFontData(Gdx.files.internal("data/couriernew.fnt"), false);
    Pixmap fontPixmap = new Pixmap(Gdx.files.internal("data/couriernew.png"));
    writeTextToPixmap(pixmap, fontPixmap, fontData, 300, 400, "ga");
\$\endgroup\$
0
1
\$\begingroup\$

The problem was hidden in this line:

    BitmapFont.BitmapFontData fontData = new BitmapFont.BitmapFontData(Gdx.files.internal("data/couriernew.fnt"), true);

The second argument: font should should be inverted.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.