From Open Surge Engine Wiki
Revision as of 03:42, 25 December 2010 by Alexandre (Talk | contribs) (True-Type)

Jump to: navigation, search


Fonts are used to display texts in Open Surge. They are described by .fnt files located in the fonts/ folder and they can be classified in two types:

  • Bitmap fonts
  • True-Type fonts

.fnt files are human-readable: they can be opened with any simple text editor like Notepad or gedit.

Font types


Bitmap fonts are fixed-width fonts. Essentially, you provide to Open Surge an image containing lots of characters, all of them having the same size. Besides, you tell the engine which characters correspond to each block in the image. Working that way, whenever you want the engine to display some text, it will read your font definition and copy the correct blocks in your image to the screen, hence drawing the text you need.

Suppose the image below is stored in images/smallfont.png:


You may then open a simple text editor and save the following script to fonts/smallfont.fnt:

font "small"
        source_file             "images/smallfont.png"
        source_rect             0 0 128 72
        frame_size              8 12
        keymap                  " !\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_\x60abcdefghijklmnopqrstuvwxyz{|}~"
  • source_file is the file where the engine should grab the characters
  • source_rect describes a rectangle in the image (x-position, y-position, width and height). The entire set of characters are contained in this rectangle
  • 'frame_size is the size of each character in the rectangle above
  • keymap is the association between the image and their respective characters (from left to right, top to bottom)


The Open Surge Engine supports True-Type fonts since version 0.2.0. True-Type fonts are the ones one usually uses in modern text editors: DejaVu Sans, DejaVu Serif, Helvetica, etc. They are stored in .ttf files, in the ttf/ folder. Unlike bitmap fonts, these are not necessarily monospaced.

Creating a .fnt script for True-Type fonts is easy as cake. Supposing that ttf/DejaVuSans.ttf is the font you want to add to the engine, you may save the following piece of text to fonts/dejavu.fnt:

font "dejavu"
        source_file             "ttf/DejaVuSans.ttf"
        size                    13
* source_file is the path to your .ttf file
* size is the size you want to pick. The higher this value, the bigger the font.