Game Development Reference
In-Depth Information
The following code snippet shows how to use this function:
LOGFONT lf;
ZeroMemory(&lf, sizeof(LOGFONT));
lf.lfHeight
= 25;
// in logical units
lf.lfWidth
= 12;
// in logical units
lf.lfWeight
= 500;
// boldness, range 0(light) - 1000(bold)
lf.lfItalic = false;
lf.lfUnderline = false;
lf.lfStrikeOut = false;
lf.lfCharSet = DEFAULT_CHARSET;
strcpy(lf.lfFaceName, "Times New Roman"); // font style
ID3DXFont* font = 0;
D3DXCreateFontIndirect(Device, &lf, &font);
Observe that first we must fill out a LOGFONT structure to describe the
kind of font we want to create.
Note: Alternatively, you can use the D3DXCreateFont function to
obtain a pointer to an ID3DXFont interface.
9.1.2 Drawing Text
Once we have obtained a pointer to an ID3DXFont interface, drawing
text is a simple matter of calling the ID3DXFont::DrawText method.
INT ID3DXFont::DrawText(
LPCSTR pString,
INT Count,
LPRECT pRect,
DWORD Format,
D3DCOLOR Color
);
pString —Pointer to the string to draw
Count —Number of characters in the string. We can specify -1 if
the string is null terminating.
pRect —Pointer to a RECT structure that defines the area on the
screen to which the text is to be drawn
Format —Optional flags that specify how the text should be for-
matted; see the SDK documentation for details.
Color —The text color
Example :
Font->DrawText(
"Hello World", // String to draw.
-1, // Null terminating string.
&rect, // Rectangle to draw the string in.
DT_TOP | DT_LEFT, // Draw in top-left corner of rect.
0xff000000);
// Black.
Team-Fly ®
Search WWH ::




Custom Search