Jump to content
  • Advertisement
Sign in to follow this  
ArchangelMorph

ID3DXFONT

This topic is 4815 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

Advertisement
Simply put, it renders text. Example usage (from my source):

LPDIRECT3DDEVICE9 pDevice; // A valid D3D Device
ID3DXFont* pFont = NULL;

// Create a bold, size 16 Ariel font //
HRESULT hResult = D3DXCreateFont(pDevice,16,0,FW_BOLD,1,FALSE,ANSI_CHARSET,
OUT_DEFAULT_PRECIS,DEFAULT_QUALITY,DEFAULT_PITCH|FF_DONTCARE,"Ariel",&pFont);
if(FAILED(hResult))
{
char szBuff[256];
sprintf(szBuff,"D3DXCreateFont() failed. Error: 0x%08X",hResult);
MessageBox(NULL,szBuff,"Error",MB_ICONERROR|MB_OK);
return false;
}

// ...
// Other setup code here
// ...

// At rendering time...
RECT rc = {0,0,1024,768}; // Rectangle to draw text in

// Draw some yellow text //
pFont->DrawText(NULL,"Hello World!",-1,&rc,DT_LEFT|DT_TOP,0xffffff00);



And be sure to Release() your fint when you're done. Also, you need to call OnLostDevice() and OnResetDevice() when you lose your device, and after you reset your device.

Hope this helps.

Share this post


Link to post
Share on other sites
For information on what all of those crazy parameters for D3DXCreateFont mean, go here. Almost exactly halfway down the page is a section titled "The Logical Font Structure". The members of that structure correspond to the 2nd through 11th parameters to the function.

Share this post


Link to post
Share on other sites
Quote:
Original post by ArchangelMorph
Ok cool, so I can actually use windows truetype fonts with this program?


Bingo. Any font that windows can use via CreateFont/CreateFontIndirect, you can use with D3DXCreateFont/D3DXCreateFontIndirect. The D3DX and Win32 versions of these functions are very similar. Also, the D3DX and Win32 DrawText functions are similar as well.

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!