Game Development Reference
In-Depth Information
Text rendering
So now that we have some images rendering to the screen, you're ready to start mak-
ing millions. But wait, how are you going to communicate with the player? If you are
making an art game, you could probably get away with zero text, but most games
need to communicate with the players so they have the information they need to play
successfully. To do this, we need to render some text.
Windows has plenty of built in text functionality for rendering text in Windows 8 applic-
ations; however, we're working with raw Direct3D, so we don't have access to that,
and in many cases those nice features would get in the way of our games.
Thankfully we don't need to worry about perfect kerning and other text features that
are needed for a great reading experience, so text rendering becomes really easy.
Add in the SpriteFont class from DirectXTK and you'll be subtitling everything be-
fore you know it.
TTF versus BMP
Many fonts these days are stored as something called a True Type Font ( TTF ).
These define all of the details about the fonts and store them in a vector graphic form
(not the same as vectors in the previous section) so that the operating system can
render text in a crisp, correct fashion. Reading and correctly rendering these files is
a complicated endeavour, and for many games the detail just isn't needed. Therefore
we need another solution.
Enter the bitmap font . A bitmap font takes that detailed processing and does it all up
front so we get a nice texture with every character we need rendered out. This way,
rendering text is as simple as just drawing the part of the texture that contains the
glyph you want, and doing this for every letter in the word or sentence.
Building the font
As I just mentioned, we need to process the original TTF font into a texture that we
can use for rendering. Thankfully DirectXTK provides a command-line tool that will do
this for us quickly and easily. If you're using NuGet, you can find a pre-compiled ver-
sion of this tool in the following directory:
Search WWH ::




Custom Search