Load Glyphs with LibGDX

Posted by in Software

TL;DR: Remember to give the font loader the list of characters to render from the font!

I’m trying to get a more resolution-independent mechanism to load simple shapes in place. After investigating SVG loading for several days I got nowhere. Then, I found out that libGDX actually supports vector fonts (TTF). Woo-hoo! Internally, it’ll convert the loaded font to a BitmapFont, for a specific size (if you want to use the same font with different sizes, you’ll have to load and store it accordingly).

Preliminary stuff

It is important (to me) to note there are two ways to load fonts:

  1. Manual
  2. Using the asset manager

Manual loading

According to the wiki, this is really simple:

This is OK when you have a simple example implementing create() from ApplicationAdapter class. However, if you want to persist it, you’ll need to use something like an asset manager.

Using the Asset Manager

The asset manager way is a bit more convoluted and has several components. First, we need to initialise the loader for the manager:

Then, you can use a simple loader function:

Displaying glyphs

Once I’ve written the above, I’ve downloaded font awesome and whipped up some code to load and display. Basically:

…and, to my surprise, it didn’t show anything. loading something simple like Arial, and using str = "Test" it would work. Sooo… why not with font awesome?


The Eureka Moment came from looking at the inner workings of the vector font: It renders internally to a specified resolution. So, you need something to render (a list of characters). Font awesome doesn’t have the ASCII ones, but all are 0xF###. To load the right things, I had to gave the manager loader the correct sequence of characters, so the loader method looks something like this:

Now, you can load the font:


A little experiment: If you find this post and ad below useful, please check the ad out 🙂