I was wondering when creating a font object using D3DXCreateFont. Is it best to create the object when creating the device and then using this device over and over again. This allows me to create text but dose not allow me to change font, font size or font color. and then release the device when the program ends.
Or is it ok to Create the device and also release it in the create text call and release it in the same call wich allows me to change Font, color and size on the fly?
eg
void DrawText(float X, float Y, float Item)
{
D3DXCreateFont(d3ddev, 12, 0, FW_NORMAL, 1, false, DEFAULT_CHARSET,OUT_DEFAULT_PRECIS, DEFAULT_QUALITY, DEFAULT_PITCH | FF_DONTCARE,"Arial", &dxfont);
RECT Part;
//Creats Box for text and decides position
SetRect(&Part, X, Y, 1024, 768);
//Sets a container for the Variable output
static char strText[10];
_itoa_s(Item, strText, 10);
//Draw the text
dxfont->DrawTextA(NULL,(LPCSTR)&strText,strlen((LPCSTR) &strText),&Part,DT_LEFT,D3DCOLOR_ARGB(255, 255, 255, 255));
dxfont->Release();
return;
}
D3DX Font object in C++
Create the font once at initialization. If you want to draw text with different fonts, simply create more fonts.
Create the font once at initialization. If you want to draw text with different fonts, simply create more fonts.
Thanks, it didn't really come to me to do it that way, i probably wont need very many different fonts either.
// Create a font array
LPD3DXFONT lpD3DXfont[MAX_FONTS] = {NULL};
// then you can create up to MAX_FONTS you like.
for (UINT i = 0; i < MAX_FONTS; i++)
{
D3DXCreateFont(m_pd3dDevice,
nHeight,
0,
nWeight,
1,
FALSE,
DEFAULT_CHARSET,
OUT_DEFAULT_PRECIS, DEFAULT_QUALITY, DEFAULT_PITCH | FF_DONTCARE,
strFace,
&lpD3DXfont ) );
}
Error handling omitted.
LPD3DXFONT lpD3DXfont[MAX_FONTS] = {NULL};
// then you can create up to MAX_FONTS you like.
for (UINT i = 0; i < MAX_FONTS; i++)
{
D3DXCreateFont(m_pd3dDevice,
nHeight,
0,
nWeight,
1,
FALSE,
DEFAULT_CHARSET,
OUT_DEFAULT_PRECIS, DEFAULT_QUALITY, DEFAULT_PITCH | FF_DONTCARE,
strFace,
&lpD3DXfont ) );
}
Error handling omitted.
// Create a font array
LPD3DXFONT lpD3DXfont[MAX_FONTS] = {NULL};
// then you can create up to MAX_FONTS you like.
for (UINT i = 0; i < MAX_FONTS; i++)
{
D3DXCreateFont(m_pd3dDevice,
nHeight,
0,
nWeight,
1,
FALSE,
DEFAULT_CHARSET,
OUT_DEFAULT_PRECIS, DEFAULT_QUALITY, DEFAULT_PITCH | FF_DONTCARE,
strFace,
&lpD3DXfont ) );
}
Error handling omitted.
Tyvm for this one, ill probably use it if it turns out i need more than a couple of different fonts =)
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement