Table of Contents

Using RTFont

RTFont is a class to load and blit bitmapped fonts. It loads a custom .rtfont format which includes kerning data, the font image, colors for “color codes”. (Old school BBS people who played LORD may remember this as “Seth ANSI”, it just allows you to change color easy in a text string)

Example of use:

RTFont myFont("interface/font_trajan_big.rtfont"); //we could also use myFont.Load()
myFont.Draw(0,0, "Hello.\n`4Red`` is cool.");

Notice that:

If you put this code in your main loop it will work, but it's a bad idea because you'd be loading and destroying the font each frame.

Instead, you should use the font area allocated for you in BaseApp as the examples do. The advantage here is engine-level components can use these “global” fonts by id.

Let's show an example of that and explore some other features.

Text wrapping and the kerning map

//init a global font one time somewhere (RTSimpleApp does this already):
GetFont(FONT_LARGE)->Load("interface/font_big.rtfont"); //taken from Dink
//in your game loop we'll do this:
string msg = "`9Smile. it makes them wonder what `5you're up to``.  Hey, a kerning map.";
rtRect wrapArea(0,0,GetScreenSizeX(), GetScreenSizeY());
GetFont(FONT_LARGE)->DrawWrapped(wrapArea, msg);
//let's zoom in to show something about kerning = 70; //start farther down to not overwrite the above thing
GetFont(FONT_LARGE)->DrawWrapped(wrapArea, "Hey, a kerning map.", false, false, MAKE_RGBA(255,255,255,170), 4.0f);

Notice that:

Disabling anti-aliasing

That blurry anti aliasing when scaling is the default, but you can turn it off by doing:


Better? Depends what you're going for I guess.

How to make a new font

First, if you've run RTSimpleApp you've technically already made a font so it can't be that hard.

Its update_media.bat automatically builds each fonts it finds by takes three files and producing a .rtfont file using RTPack.exe.

For the trajan font it needs (located in RTSimpleApp/media/interface) :

BMFont is AngelCode's Bitmap Font Generator, a free utility to generate bmps and data for fonts.

RTPack.exe can be found in /shared/win/utils. If you're on linux/osx, check here for info on compiling it. (It also works using wine: RTPack.exe -opts etc).

The command line to make this font is:

rtpack.exe -make_font font_trajan.txt

If you're making your own font, notice the file font_trajan.mbfc is with the other font stuff. This is the settings file for Bitmap Font Generator, load it to see what good values are or to tweak an existing font.

Making a new font step by step


The font code is fast because it batches characters together when it renders using the global RenderBatcher, or allows you to pass in your own RenderBatcher object so you can render multiple DrawFont calls with a single GL operation later.