Jump to content
  • Advertisement
Sign in to follow this  
Vony256

D3DX Font object in C++

This topic is 2686 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

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
Advertisement
Create the font once at initialization. If you want to draw text with different fonts, simply create more fonts.

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites
// 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.


Share this post


Link to post
Share on other sites

// 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 =)

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!