Jump to content
  • Advertisement
Sign in to follow this  

directx font issues

This topic is 3172 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'm trying to display some english text but when I render it I get chinese characters. What params do I need to change/set? Below is what I currently have:

fontDesc.Height = 20;
fontDesc.Width = 10;
fontDesc.Weight = FW_NORMAL;
fontDesc.MipLevels = 0;
fontDesc.Italic = false;
fontDesc.CharSet = DEFAULT_CHARSET;
fontDesc.OutputPrecision = OUT_DEFAULT_PRECIS;
fontDesc.Quality = DEFAULT_QUALITY;
fontDesc.PitchAndFamily = DEFAULT_PITCH | FF_DONTCARE;
_tcscpy( fontDesc.FaceName, _T("Times New Roman") );

HRESULT Result = D3DXCreateFontIndirect( d3ddev, &fontDesc, &FontData );

std::string wtf( "testing" );
RECT hi;
hi.left = 0;
hi.top = 0;
hi.bottom = fontDesc.Height;
hi.right = fontDesc.Width * wtf.size();

FontData->DrawText( 0, (LPCWSTR)(wtf.c_str()), -1, &hi, DT_LEFT, D3DCOLOR_XRGB( 255, 0, 0 ) );

Note that I just get an error when I replace (LPCWSTR)(wtf.c_str()) with _T(wtf.c_str()) - I get 'Lwtf' : undeclared identifier. Stupid macros... Also, I'm getting Result as D3D_OK. [Edited by - 16bit_port on April 12, 2010 9:10:47 PM]

Share this post

Link to post
Share on other sites
You can't convert an ansi string to a unicode string just by casting it, you either need to use one of the APIs for doing so or use wstring instead...

std::wstring wtf( "testing" );

Share this post

Link to post
Share on other sites
jbb, thanks, it worked, however I had to change it to

std::wstring wtf( L"testing" );

to get it to work.

EvilSteve, thanks for the link. It was very informative.

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.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!