Game Development Reference
In-Depth Information
Chapter 9
Fonts
During a game we often need to display textual information to the user.
This chapter discusses three ways that we can generate and output
text in Direct3D. Each way has a corresponding sample application on
the web page for this chapter and in the companion files.
Objectives
To learn how to render text using the ID3DXFont interface
To learn how to render text using the CD3DFont class
To learn how to calculate the number of frames rendered per
second
To learn how to create and render 3D text using the
D3DXCreateText function
9.1 ID3DXFont
The D3DX library provides the ID3DXFont interface that can be used
to draw text in a Direct3D application. This interface uses GDI inter-
nally to draw the text, and so we take a performance hit using this
interface. However, ID3DXFont can handle complex fonts and format-
ting because it uses GDI.
9.1.1 Creating an ID3DXFont
We can create an ID3DXFont interface using the D3DXCreateFont-
Indirect function.
HRESULT D3DXCreateFontIndirect(
LPDIRECT3DDEVICE9 pDevice, // device to be associated with
// the font
CONST LOGFONT* pLogFont,
// LOGFONT structure describing
// the font
LPD3DXFONT* ppFont
// return the created font
);
153
Search WWH ::




Custom Search