Text system for a game

Are there any good tutorials on creating a text system for games? Or better yet has anyone on these boards ever developed such a thing and can you give me some insight into how it was implemented? Most examples I see use the easiest solution and make ugly text.
NeHe productions has a pretty good tutorial of how to do it in OpenGL.

... I used those tutorials several years ago so they might be dated.
If that's the tutorial I'm thinking of it mostly only shows how to render text using Windows fonts converted to bitmaps. I'm thinking of special effects that you might find in a dialogue-driven RPG, such as formatting and animating individual words and characters in a string. I'd also like to know how to create and represent custom bitmap fonts. Maybe the topic should have been "Dialogue system".
Well I was going to say GameDev.net, but after looking at their "font engine" tutorial I realized that it isn't really a font engine. The tutorial is more general, it basically shows using DirectX to make a variable, load the font into the variable's data location, and how to draw it to the screen. I've always wanted to make a font system where you could do a scripting language setup with NPC dialogue and then have it printed out one a box or such like in a RPG or such.

Though, honestly it seems fairly simple after you get that. A font system is nothing more than a chunk of code that reads in the text and prints out so many words a line. May have to tackle this later after I take my son to school.
Last edited on by closed account z6A9GNh0
The NeHe tutorials are horrible, try http://openglbook.com/
You need a graphics card that supports OpenGL 3.3 or later.
Though, honestly it seems fairly simple after you get that. A font system is nothing more than a chunk of code that reads in the text and prints out so many words a line. May have to tackle this later after I take my son to school.


But what kind of fonts? Fonts loaded from windows just don't look right to me. They look more appropriate for text editors than games. I tried display lists and outline fonts and couldn't get antialiasing on either of them. I think the best option is custom fonts and texture mapping. But what about pitch and descent and other crazy font properties? Would you store this information with the font or hard code it?
Wait, do you mean like command recognition like ZORK (love that game)? Or like NPC chat bubbles? Either way, cool stuff happens.
Well if you are talking about how a font looks, then that has little to do with the coding side and more with the application to make them. It depends on the application as you can use TTF, or PCX/BMP/etc and create your own fonts. Secondly, if the font looks good in say a text editor like Word or Office and then looks crappy in a game it is most likely because of the resolution the application is running in. Outside of that I'm not entirely sure what it is you are wanting.
I'm talking about a low level text system in general. One that represents text in a way that can be animated. Have you seen in some RPG's where dialogue comes out one character at a time, as if the NPC is speaking it? Or shaky text like the NPC is mad or something? Maybe "dialogue system" is a better term but I imagine this system could be used for all text in a game.

When I said text looks ugly it's probably mostly because I couldn't find a way to enable antialiasing with the methods I used, and simply drawing a string of text formatted inside a RECT doesn't look right for a game. What about TrueType fonts? Don't they need to be installed in the system before they can be used? These reasons lead me to believe that custom fonts is the way to go, because you get antialiasing right in the alpha channel and don't have to install anything extra or hope that a font is already installed.

I have an idea how to do this but I'm not a very good programmer so I could be way off base(why I was looking for tutorials):

- Uses custom bitmap font as a texture atlas. Control pixels in the bitmap point where the base line is, the ascent and descent, and the extents of each character.

- Text object is fed strings. The strings aren't rendered immediately but are split into tokens, which are delimited by one or more contiguous formatting symbols, and added to a main list of tokens.

- Tokens can be accessed at any time to modify various properties including font, format, color, offsets, and the text itself. These properties can then be animated.

- Text is rendered at any time by calling a Render() function on the Text object.
Well most people make their own bitmaps/pcx/ttf fonts for their games and seldom use existing fonts due to style reasons.

What about TrueType fonts? Don't they need to be installed in the system before they can be used?

Nope, just have a data directory in your 'game directory and load them from the data directory (depending on how your library you are using does it). For Allegro, for example, I can do:

1
2
3
4
ALLEGRO_FONT font;
// al_load_font(char const *filename, int size, int flags);
font = al_load_font("./data/pirulen.ttf", 12, 0);
// then just draw font to screen 


Topic archived. No new replies allowed.