Sign in to follow this  
Vony256

D3DX Font object in C++

Recommended Posts

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;
}

Edited by Vony256

Share this post


Link to post
Share on other sites
[quote name='Mussi' timestamp='1302732717' post='4798165']
Create the font once at initialization. If you want to draw text with different fonts, simply create more fonts.
[/quote]

Thanks, it didn't really come to me to do it that way, i probably wont need very many different fonts either.

Share this post


Link to post
Share on other sites
[size="2"]// 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[i] ) );

[/size][size="2"]}

Error handling omitted.


[/size]

Share this post


Link to post
Share on other sites
[quote name='standby01' timestamp='1302733461' post='4798169']
[size="2"]// 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[i] ) );

[/size][size="2"]}

Error handling omitted.


[/size]
[/quote]

Tyvm for this one, ill probably use it if it turns out i need more than a couple of different fonts =)

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this