# Ogre Image Font Tutorial

Last Modified: Dec. 13, 2003

Overview:
This tutorial is intended to help people add image fonts to their Ogre projects. If you don't know what Ogre is check out www.ogre3d.org/. You'll need Bitmap Font Builder program www.lmnopc.com/bitmapfontbuilder/. Adobe photoshop(www.Adobe.com/) to copy/paste the fonts onto a transparent background. You could probably figure out how to do this with other image editing programs. Lastly, you'll need the BitmapFontBuilderTool which I have modified, and should be included with this tutorial.
BitmapFontBuilderTool Changes:
Made a few minor changes to the BitmapFontBuilderTool that comes with Ogre. Basicly instead of generating the Ogre .fontdef 'glyph' statements. It generates a complete font script file. By removing all the 'glyph' statements before "!" and after "~". Theres an option to generate all of them if needed. "(Not Recommended)" shows up when it asks you if you want to generate all 'glyph' statements. I believe Ogre only handles glyph statements that are bound to standard keys or only handles a certain number of them. So if you decide to generate all the statements, the font script won't work until you fix or delete them.
Steps:
Bitmap Font Builder Steps
Photoshop Steps
BitmapFontBuilderTool Steps
Things to watchout for
FAQ

## Bitmap Font Builder Steps

1: Startup Bitmap Font Builder program.
2. Click on "Charater Set" and make sure "Full ASCII Charater Set(0-255)" is checked.
3. Click on "Font Smoothing" and make sure "Enable (Default)" is checked.
4. Select the font you want from the Font 1 combobox. You can adjust the font size by unchecking the box and typing in the size you want. You'll also be able to adjust the font size in .overlay scripts.
5. Select your the texture size. 256x256 or 512x512 is recommend.
6. Next comes the interesting part. This is where the image compression effects the look of your font. Below are images rendered in Ogre showing the different effects of compression. The example font is Arial, size 256x256, .png. Anti-aliasing option is dealt with in the image editing program. I'll explain a little later.
Bitmap with Anti-aliasing option
Bitmap without Anti-aliasing option
8-bit TGA with Anti-aliasing option
8-bit TGA without Anti-aliasing option
24-bit TGA with Anti-aliasing option
24-bit TGA without Anti-aliasing option
32-bit TGA with Anti-aliasing option
32-bit TGA without Anti-aliasing option
Raw with Anti-aliasing option
Raw without Anti-aliasing option
7. Once you have decided which file type you want click "File" then select it. Save the file in a temp directory.
8. You now need to save the Font widths file which will be used with the Tool. Click "File" then select "Save Font Widths (Byte Format)", save it to the same directory as the BitmapFontBuilderTool. Then you can exit Bitmap Font Builder.

## Photoshop Steps

1. Startup Photoshop and load the image file you made with Bitmap Font Builder.
2. Find the tool called "Magic Wand" in the toolbar panel .
3. Find the panel under the Menu bar with Tolerance/Anti-Alised/... This is where you configure the wand tool. First make sure "Contiguous" is unchecked. Keeping it checked will leave the inter parts of characters. "Tolerance" should be low, if its to high some parts of characters could be left out. Don't worry about "Use All Layers" cause we're not using layers. Finally, look at the test images above to see if you want the "Anti-alised" option checked or not.
4. If you've saved your image font as a 32-bit TGA file look at b.

a. Take the magic wand that you've configured and click in the black area of the image. You should see dashed lines around everything. Right click in the black area and a menu should popup. Select "Select Inverse" from the popup menu. If you don't inverse select you will be selecting everything but the fonts(All the Black area). Continue to step 5.

b. If you're using a 32-bit TGA file you should be looking at a white image. You need to edit the alpha layer of the image. To do this you need to use the Layers/Channels/Paths window. If its not already showing click "Window" from the menu bar at the top and select "Show Layers". That should bring up the window. In the window click on the Channels tab. You should now see five channels RGB/Red/Green/Blue/Alpha 1. Click on the Alpha 1 channel. The characters should now show up. Follow the above instructions(a.). Note: There will also be one extra step in part 5.

5. If you did the 32-bit TGA image you need to click on the RGB channel now. Next 32-bit or not click on "Edit" and select "Copy".
6. Now comes the important part. Click "File" then click "New...". Photoshop will auto size your copied area. So you need to make sure that the new image is the same size as the file you copied from. If you don't the letters will be bunched up or out of place when you render them in Ogre. You also need to have the "Tranparent" Background option selected. Then click "Ok".
7. After clicking Ok to create the new transparent image. You should be looking at a checkered image. Now click "Edit" and select "Paste". To paste the image onto the transparent background. Photoshop with center the fonts so you don't need to move them around.
8. Ogre recommends .png or .tga image fonts. To save your file click "File" then select "Save As...". In the Save As window select the "Format" from the combobox. After you have saved the file you can exit Photoshop.

## BitmapFontBuilderTool Steps

1. Make sure you have the widths file that Bitmap Font Builder generated for you in the same directory as the tool. Then start the tool.
2. Unqiue font name: Ogre uses it to identify the font script. Ex. MyFont
3. Font image name: Is the image you just made with your image editing program. Make sure you give the full name. Ex. MyFont.png
4. Size of texture: This is the dimension of your font image. If your image is 256x256 type 256.
5. Name of binary widths file: The file Bitmap Font Builder generated. Ex. MyFont.dat
6. Generate all glyph statements say n if you just want to get a script generated. Read the "BitmapFontBuilderTool Changes" at the top of this document if you want to know more.
7. Finally, enter the name of the file you want generated. The file it generates is a text file with the script in it. You can name it Ex."MyFont.fontdef" or you can copy it into another .fontdef file. Your Done!
If you want to test your font, move both .fontdef and font image into Ogre/Samples/Media directory. Or copy the font script into the sample.fontdef file and copy your font image to the Ogre/Samples/Media directory. Next edit the BasicOgreGuiTemplates.inc in the media directory with a text editor like notepad. Look for "font_name" under "template element TextArea(SS/Templates/BasicText)". Change "font_name Ogre" to font_name whatever your unique font name was(Ex. font_name Myfont). Save BasicOgreGuiTemplates.inc then goto Ogre/Samples/Common/bin/Debug or Release and run "Demo_Gui.exe". You should be able to see your font in the GUI. Hope this helped.

## Things to watchout for

The Bitmap Font Builder program can generate characters that are to close together. Allowing parts of other characters to show up.
and
This is what it looked like in the Bitmap Font Builder program. (Example: Arail 256x256 font size 10.5).
There are a couple of ways you can fix this. You can increase the size of the font texture file in Bitmap Font Builder while keeping the font size the same. Which increases the space between the characters. The other way is to unselect the characters that are over lapping when you're doing the magic wond step. Meaning don't include them in the image font, if there useless characters.

## FAQ

Q: Who wrote this tutorial?
A: [Shug]... I don't know.
Q: Why did you write this tutorial?
A: Well a long time ago... Hey, you tricked me!
Q: How many people do you think will read this tutorial?
A: LOL!
Q: Will you be writting more Ogre Tutorials?
A: Hmm... depends apon the real answer to the previous question.
Q: Can anybody modify and correct your mistakes?
A: No!
Q: Please!?
A: Oh alright, you can modify anything you want.
Q: Where can I find more information about .fontdef files or scripts in general?
A: Ogre Manaul(ie. Ogre/Docs/manual)
Q: Why is this tutorial so long?
A: Because of people like you!
Q: Whats that supposed to mean?
A: Sigh

Top