Skip to main content
GameDev.net gamedev.net
🔒 Locked

ID3DXFont Compiling error

Started by Arangol Jan 20, 2007 at 12:16 PM 1 replies 1.7k views
Original Post
Arangol
Arangol
Hi, I'm a beginner at DirectX and I'm trying to make a small driving game, so I need to print 2d text on the screen. Here's how I do my text...uhm...stuff:


LPD3DXFONT m_font;


//in Init_Graphics()


D3DXCreateFont( d3ddev,
			   20, 0,
			   FW_BOLD, 0,
			   FALSE, DEFAULT_CHARSET, 
			   OUT_DEFAULT_PRECIS, DEFAULT_QUALITY,
			   DEFAULT_PITCH | FF_DONTCARE,
			   TEXT("Arial"), &m_font );


//In Render_Frame()
D3DCOLOR fontColor = D3DCOLOR_ARGB(255,0,0,255);  

RECT rct;
rct.left=2;
rct.right=780;
rct.top=10;
rct.bottom=rct.top+20;
 

m_font->DrawText(NULL, "Hello World", -1, &rct, 0, fontColor );


//And finally
m_font->Release();




I get these compilation errors:

1>c:\program files\microsoft directx sdk (december 2006)\include\dinput.h: DIRECTINPUT_VERSION undefined. Defaulting to version 0x0800
1>c:\documents and settings\henrik stenius\my documents\visual studio 2005\projects\small game\small game\small game.cpp(152) : warning C4244: 'return' : conversion from 'WPARAM' to 'int', possible loss of data
1>c:\documents and settings\henrik stenius\my documents\visual studio 2005\projects\small game\small game\small game.cpp(268) : error C2664: 'ID3DXFont::DrawTextW' : cannot convert parameter 2 from 'const char [12]' to 'LPCWSTR'
1>        Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast



Can anyone help me out on this? Thanks EDIT: I'm using Visual C++ Express Edition [Edited by - Arangol on January 20, 2007 12:46:51 PM]
UriKiller
UriKiller
For some reason, your compiler uses ID3DXFont::DrawTextW, which is the widechar version of ID3DXFont::DrawText, so the function expects to get a unicode string (LPCWSTR) in the pString parameter.
You might need to convert your string into unicode. However, I am sure there is a way to let the compiler know that you will be using ASCII charachters and therefor use the ASCII versions of all the functions that work with strings. Then the compiler will use ID3DXFont::DrawTextA instead of ID3DXFont::DrawTextW.
I just can't rememeber how to do that. Try looking in the program's options or project settings.
MSDN states that when neither _UNICODE nor _MBCS are defined, the compiler will assume ASCII mode should be used, so check if those names are defined somewhere.
Arangol
Arangol
Thanks, I changed an option in the project properties and now it works.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.