Saturday, 26 February 2011

AutoBFont

AutoBFont is small tool for text rendering on OpenGL(and can be easily ported to DX) with bitmap fonts, providing a way to draw perfectly aligned text with bitmap sheets created in Fireworks/Photoshop/Gimp and Inkscape. The tool is composed by two parts : an generator and a loader class.

The monospace font with and without a drop shadow(effect created in Inkscape) rendered with the help of autobfont
The generator computes each character limits from the character sheet bitmap, which should be a RGBA TGA image with no compression. It should have 16 columns by 16 rows to fill with characters and the size of the image should be power of 2 (1024x1024 for example). If only the first 8 rows are used, the remaining rows can be used to fit a "bold" version of the font.

The generator program requires 3 mandatory arguments :
-i CHARACTER_CONVERSION_MAP.TXT 
-m CHARACTER_BITMAP_SHEET.TGA
-o OUTPUT_MAP.TXT
Optional arguments :
-b Compute the Bold characters in the last 8 rows.
-h VALUE  Set all characters line height (the default value is 3*CELL_SIZE/4).
-t VALUE Set alpha threshold value, improves character boundaries detection (default value is 50, max is 255).

The conversion map is a text file with the ASCII character for each cell in the bitmap sheet, although it's limited to Latin characters, the generator and loader can be changed to use wchar_t structure instead of char for other languages such as japanese. All the characters in the bitmap font should by white (if you want to use color blending in OGL, but isn't mandatory) with a background transparent (below the alpha threshold value).

The loader class is available in the demo.cpp class, which loads the generated output map and the renders the characters with OpenGL.

To convert the SVG to TGA use gimp with no RLE compression and  bottom left origin.

The typical commands to compile and run the generator and demo on linux:
make
./generator -i ct_PT.txt -m font_ubuntu.tga -o font_ubuntu_map.txt
./demo font_ubuntu_map.txt font_ubuntu.tga

DOWNLOAD

No comments: