Game Development Reference
In-Depth Information
ID3DXFont does. If you're after speed and only need a simple font, the
CD3DFont class is the way to go.
To use the CD3DFont class, you need to add the following files to
your application: d3dfont.h, d3dfont.cpp, d3dutil.h, d3dutil.cpp, dxutil.h,
and dxutil.cpp. These files can be found in the Include and Src folders
located in the previously mentioned Common folder.
9.2.1 Constructing a CD3DFont
To create a CD3DFont instance, we simply instantiate it like a normal
C++ object; below is the constructor prototype:
CD3DFont(const TCHAR* strFontName, DWORD dwHeight, DWORD
dwFlags=0L);
strFontName —A null-terminated string that specifies the type-
face name of the font
dwHeight —The height of the font
dwFlags —Optional creation flags; you can set this parameter to
zero or use a combination of the following flags; D3DFONT_BOLD ,
D3DFONT_ITALIC , D3DFONT_ZENABLE .
After we have instantiated a CD3DFont object, we must call the follow-
ing methods (in the order shown) that initialize the font:
Font = new CD3DFont("Times New Roman", 16, 0); // instantiate
Font->InitDeviceObjects( Device );
Font->RestoreDeviceObjects();
9.2.2 Drawing Text
Now that we have constructed and initialized a CD3DFont object, we
are ready to draw some text. Text drawing is done with the following
method:
HRESULT CD3DFont::DrawText(FLOAT x, FLOAT y, DWORD dwColor,
const TCHAR* strText, DWORD dwFlags=0L);
x —The x-coordinate in screen space of where to begin drawing the
text
y —The y-coordinate in screen space of where to begin drawing the
text
dwColor —The color of the text
strText —Pointer to the string to draw
dwFlags —Optional rendering flags; you can set this parameter to
0 or use a combination of the following: D3DFONT_CENTERED ,
D3DFONT_TWOSIDED , D3DFONT_FILTERED .
Search WWH ::




Custom Search