Log In
Sign Up and Get Started Blogging!
JoeUser is completely free to use! By Signing Up on JoeUser, you can create your own blog and participate on the blogs of others!
Girl Geek
Lead Developer, Stardock Entertainment
Fonts in Computer Games
Published on October 21, 2004 By
CariElf
In
Game Developers
Brad recently received an e-mail from a user who had read the postmortem for The Poltiical Machine on Gamasutra
Link
Hi Brad,
I just read your article in Gamasutra and found it pretty interesting. Sounds like the Political Machine was a fun project to work on. In discussing it, you mentioned that the reason for using DirectX 9 was the TrueType font support, and something I was wondering about was whether you looked at using the FreeType font rendering engine or not. I do some graphics programming for my employer and recently wrote a wrapper for using the FreeType engine to render TrueType fonts in OpenGL. Just interested in your thoughts.
Carl Anderson
Brad forwarded the e-mail to me since I've worked on fonts in both our 2D and 3D code.
So I googled FreeType and went to the webite that I found:
Link
While FreeType creates font graphics, it doesn't format text and display it on the screen; you still have to load those graphics into OpenGL or DirectX to get them to display.
Fonts are one of the less fun things to code in a computer game. If you've ever noticed, a lot of computer games avoid using text wherever possible, and they generally have only a few different fonts, and the same font is usually in one color. One of the reasons for this is that before DirectX 9.0b came out, developers were pretty much stuck coding their own fonts. To do this, they had to create bitmaps with all the characters in the font that they wanted to use, one bitmap for every size,color, and style combination. If you were using a bitmap that doesn't support alpha channels, you had to create a grayscale copy of the first bitmap to represent the alpha channel. Unless you made a fixed width font, you'd also have to figure out offsets for each character so that it would be placed at position that was relative to the other characters in the text you're trying to draw. This appears to be what FreeType does. You can do it pretty easily with GDI in Windows, which might be faster than FreeType since it's specific to Windows, but on the other hand, maybe they wrote a bunch of code in assembly language to speed it up and it's faster than GDI.
However, that's only creating the graphics for the fonts. You still have to write code to get it to display correctly on the screen, and that's pretty painful, even before you get to the concept of wrapped text. And, you've got all of those graphics in memory, and taking up room on your hard drive. And since you have to redraw the screen a lot, you're doing those calculations for displaying the fonts every time you repaint the screen.
All of this changed with DirectX 9.0b, which optimized its font code to the point where it could actually be used without a performance hit. You give DirectX the name of a TrueType font, a size, whether you want it italic or bold, and a few other options, and it creates a font object for you with all of the characteristics that you told it to use. When you want to draw text on the screen, you take that font object and you tell it where you want it on the screen, what text to display, and what color you want it (including transparency) and DirectX does it for you, even wrapping text, and it looks great. It also stores the formatted text in a sprite so that it can be reused and not calculated with every frame, but it's only holding them in memory for as long as the text is on the screen.
The only downside is that older video cards whose drivers haven't been updated since before DirectX 9.0 came out don't necessarily support TrueType fonts in DirectX, so there are some people who can't play political machine because their video card manufacturer stopped supporting their video cards. Rather than blaming their video card manufacturer, they blame us.
By now, there's not much point in putting in support for bitmap fonts in Political Machine. If we were to use FreeType or make our own bitmap fonts, we would still have to write text formatting code. We could probably modify the code from Gal Civ to use it, but that was never terribly good at displaying text and we'd still end up doing a lot of work on it. Also, there's no guarantee that drivers that won't support DirectX 9.0 fonts will support a lot of our code in Gal Civ 2, although we're doing what we can to keep the minimum requirements low. Heck, there's no guarantee that the people who have no fonts in Political Machine would even be able to generate the state graphics if we managed to put in bitmap font support so that they could see what buttons to press to start a game. So our time is better spent working on Gal Civ 2.
Popular Articles in this Category
Using WPF for making game tools
Popular Articles from CariElf
I'm baaaaaaaaack!
Comments
1
historyishere
on Oct 21, 2004
This was a very interesting article, because I wasn't aware that the newer versions of DX supported True Type... that's wonderful news, as there are a lot of great typefaces out there. For a type freak like myself, I wonder if there is going to be a day when users can specify the typefaces they want to use for their gaming experience easily.
2
CariElf
on Oct 22, 2004
Well, if programmers put the font information in a configuration file of some sort, users could easily modify the text in the games simply by changing the name of the typeface, etc, in the file.
Welcome Guest! Please take the time to register with us.
There are many great features available to you once you register, including:
Richer content, access to many features that are disabled for guests like commenting on the forums.
Access to a great community, with a massive database of many, many areas of interest.
Access to contests & subscription offers like exclusive emails.
It's simple, and FREE!
Sign Up Now!
Meta
Views
» 10045
Comments
»
2
Category
»
Game Developers
Comment
Recent Article Comments
Let's see your political mem...
LightStar Design Windowblind...
Let's start a New Jammin Thr...
A day in the Life of Odditie...
Safe and free software downl...
Veterans Day
A new and more functional PC...
Post your joy
AI Art Thread: 2022
WD Black Internal and Extern...
Sponsored Links