Creating a Font

I’ve included several bitmapped fonts on the CD for your use. These fonts were created with a very useful tool called Bitmap Font Builder by Thom Wetzel, Jr. (www.lmnopc.com), which is included on the CD. You can use Bitmap Font Builder (shown in Figure 8.2) to create a bitmapped font from any TrueType font installed on your Windows system. The font shown in the figure is 10-point Verdana.

Figure 8.2. Bitmap Font Builder is used to render a TrueType font onto a bitmap.


The settings are important. I recommend setting the Texture Size field to Auto with 0-pixel spacing for best results. If the Character Set is configured to render two fonts, change it using the menu to a single ASCII font, as shown in the figure. Although you will never use most of those unusual ASCII characters, you never know, and the code for rendering the font is simpler when you are using a font with characters numbered 0–255.

When you have configured the font you want to produce, open the File menu, choose Save 32-bit TGA (RGBA), and enter a filename. This will save a new 32-bit Targa file with an alpha channel. Saving the 10-point Verdana font produces a Targa file shown in Figure 8.3. You can experiment with different fonts to come up with one you like for your games. When you are setting up a font, note that it will look sharper in your game than it looks in the BFB preview; although you may be tempted to output a font in bold, that usually is not needed.

Figure 8.3. Bitmap Font Builder automatically generates an alpha channel for transparency.


After you have saved the font to a Targa image, you will need to export the font width data, which will be used to render the font proportionally. BFB makes this very easy by exporting the width data into a simple binary data file that you can read and use when rendering a font (using an animated sprite).

Open the File menu in BFB and choose Save Font Widths (Byte Format). You will be prompted for a filename. I find it makes sense to use the same filename that I used for the font, but append a .dat extension. This data file will be composed of 256 font width values stored in binary format for a total of 512 bytes (two bytes per ASCII character width).

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset