Upcoming Events
Unite 2010
11/10 - 11/12 @ Montréal, Canada

GDC China
12/5 - 12/7 @ Shanghai, China

Asia Game Show 2010
12/24 - 12/27  

GDC 2011
2/28 - 3/4 @ San Francisco, CA

More events...
Quick Stats
102 people currently visiting GDNet.
2406 articles in the reference section.

Help us fight cancer!
Join SETI Team GDNet!
Link to us Events 4 Gamers
Intel sponsors gamedev.net search:

  Contents

 Introduction
 Arising Conflicts
 Resolving Conflicts
 Bitmapped Fonts
 Conclusion

 Printable version

 


Bitmapped Fonts -- Good or Bad?

Bitmapped fonts are something that can be a hassle, or something that will make your game look more attractive. Whenever you want to use bitmaps for fonts, always check to make sure you really need them. Meaning if you are looking at the fact that GDI is slow, and you need that few extra frames to increase your FPS, blitting the font from a surface is probably the best choice. However, it is worth considering that speed is not always the only issue. You might need to format your text output (like centering, italicizing, underlining, etc.) which is easier with GDI.

However most people (including myself) have some trouble using bitmapped fonts. Although there are many approaches to implement them, one method that Quake used, which changed the way I thought (creating a font editor, making my own custom font file format, etc.) was to create a font bitmap in ASCII order. Although it might seem obvious now, I had no idea that creating a font in ASCII order would be so much easier than creating a bitmap in A-Z order or keyboard order.

When you are creating a bitmapped font, always create them in ASCII order (you can look up ASCII codes in MSDN by using the keyword: "character codes"). Since the KeyPress Event (Message WM_KEYPRESS) comes with an ASCII code, you can just use this value as a base to get the position of the character you want in the bitmap file by using this formula (Special thanks to: Benjamin Marty). Excerpt 3.1 shows this:

Excerpt 3.1

'char_code: ASCII value of the key pressed.
'NUM_CHARS_PER_LINE: number of characters on each line
'FONT_START_Y: vertical pixel position for char's start.
'FONT_Y_SIZE: pixel size of each character's height.
'FONT_X_SIZE: pixel size of each character's width.
'FONT_BMP_WIDTH: width of the whole font bitmap file.
''Mod': VB's modulo operator (for those confused).

top = ( Int( (char_code-32) / NUM_CHARS_PER_LINE)
   * FONT_Y_SIZE) + FONT_START_Y ' 32 is ASCII for space

left = (char_code * FONT_X_SIZE) Mod FONT_BMP_WIDTH

Pretty simple if you think about it, instead of hard-coding values which you may need to do over if you changed the file. If you already knew this technique, kudos to you.


Next : Conclusion