More on Text and Fonts
Working with fonts is an extremely complex subject and not really something that I want to get into. If you want an in-depth treatise on this subject, your best bet is to pick up Charles Petzold's Programming Windows 95/98. For products such as games under DirectX, you will in most cases render text yourself with your own font engine. The only time you might want to use GDI to draw text is in a GUI situation or a quick solution to drawing scores or other simple information during development of your game. However, in the end you must create your own font system to get any kind of speed.
To be somewhat complete I want to at least show you how to change fonts for the DrawText() and TextOut() functions. This is done by selecting a new font object into the current graphics device context just as you would a new pen or brush. Table 4.1 shows a number of font constants, such as SYSTEM_FIXED_FONT, which is a monospaced font. Monospaced means that each character is always the same width. Proportional fonts have different spacing. Anyway, to select a new font into the graphics context, you would do this:
Whatever GDI text you rendered with TextOut() or DrawText() is drawn in the new font. If you want a little more power over the selection of fonts, you can use one of the built-in TrueType fonts listed in Table 4.4.
HFONT CreateFont( int nHeight, // logical height of font int nWidth, // logical average character width int nEscapement, // angle of escapement int nOrientation, // base-line orientation angle int fnWeight, // font weight DWORD fdwItalic, // italic attribute flag DWORD fdwUnderline, // underline attribute flag DWORD fdwStrikeOut, // strikeout attribute flag DWORD fdwCharSet, // character set identifier DWORD fdwOutputPrecision,// output precision DWORD fdwClipPrecision, // clipping precision DWORD fdwQuality, // output quality DWORD fdwPitchAndFamily, // pitch and family LPCTSTR lpszFace); // pointer to typeface name string // as shown in table 4.4
The explanation of the function is far too long, so take a look at the Win32 SDK Help for details. Basically, you fill in all those ugly parameters and the results are a handle to a rasterized version of the font you requested. Then you can select the font into your device context and you're ready to rock.