Creating a fontsystem

Because in a game it is somewhere required to use a line of text, most game engines are able to process fonts on the fly or on startup. XNA supports so called “spritefonts”, a system that uses xml-files as informationcontainer. These xml-files are saved as “*.spritefont”-file, but even inside they reveal their truth: The first line is an xml-validation.

But xml can’t be used to tell the graphics-processor what to draw, so XNA compiles the information into an xnb-file which is just a collection of bitmaps that are connected to Unicode-Characters. When these characters are called, the font provides the required infomation about them.

The problem is: This system can’t be used on the fly, but in compiletime. And thats the problem. I don’t use the regular contentpipeline. I load my stuff into the engine when I need it, spritefonts don’t support this behaviour.

I had to create my own font-system.

The *.gef-system

I created a system that saves characters into a binary-file followed by bitmaps representing them. I will write an article about the file-architecture sometime, but the current article will be about the creation of the font.

The encoders and the decoder are both extracted from the core-assembly of the game-engine. The reason is simple: I wanted an external tool for the creation of the fonts.

I know there are some simple rules about creating object-oriented assemblies and these tell me that one class has only one job and one purpose. Same goes for the assembly itself. I want to have it as a standalone linked-library. The engine uses the decoder, the tool the encoder, but instead of splitting these up, I create an independent assembly. And there is another thing that I want to mention about the independent assembly: I can update and build it without rebuilding a whole gameengine.

Leave a Reply

Your email address will not be published. Required fields are marked *