Bitmap fonts

Juan Javier Cassani edited this page Jun 23, 2017 · 17 revisions

LibGdx makes use of bitmap files (pngs) to render fonts. Each glyph in the font has a corresponding TextureRegion.

BitmapFont class (code)

BitmapFont was refactored for the LibGdx 1.5.6 release. This blog post has details about the changes and also a small example showing how to move from pre 1.5.6 code to the new API.

A tutorial on using BitmapFont is available on LibGDX.info

File format specifications for the font file

References point to bmFont being originally created by Andreas Jönsson over at AngelCode

BMFont - the original specification for the file format.

Glyph Designer - Details about output, include a binary format.

Tools for Creating Bitmaps

Hiero - a utility for converting a system font to a bitmap

ShoeBox - lets you load customized glyphs from an image, and then create a bitmap font from them. There's a great tutorial for using it with libgdx.

Glyph Designer - a commercial bitmap font tool with a wide variety of options for shadows, gradients, stroke, etc.

Littera - online bitmap font generator, with a great amount of customizations (needs Adobe Flash).

Other Tools

FreeTypeFontGenerator - generating bitmaps for fonts instead of supplying a pre-rendered bitmap made by utilities like Hiero

Examples : (more)

FreeTypeFontGenerator generator = new FreeTypeFontGenerator(Gdx.files.internal("data/unbom.ttf"));

FreeTypeFontParameter parameter = new FreeTypeFontParameter();
parameter.size = 18;
parameter.characters = "한국어/조선�?";

BitmapFont koreanFont = generator.generateFont(parameter);

parameter.characters = FreeTypeFontGenerator.DEFAULT_CHARS;
generator = new FreeTypeFontGenerator(Gdx.files.internal("data/russkij.ttf"));
BitmapFont cyrillicFont = generator.generateFont(parameter);
generator.dispose();

Distance field fonts - useful for scaling/rotating fonts without ugly artifacts

gdx-smart-font - unofficial libgdx addon for automatically generating and caching bitmap fonts based on screen size. (Uses FreeTypeFontGenerator)

Table of Contents

Clone this wiki locally
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.
Press h to open a hovercard with more details.