Sign in to follow this  

D3DXCreateFont problem

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

Probably a simple problem I'm not seeing the solution to immediately. I'm on a Drunken Hyena tutorial to get id3dxfont working. I followed the code on the tutorial and input the following:
	if(FAILED(D3DXCreateFont(*(graphics->getDevice()),24,0,FW_NORMAL,1,false,DEFAULT_CHARSET,
		OUT_DEFAULT_PRECIS,ANTIALIASED_QUALITY,DEFAULT_PITCH|FF_DONTCARE,
		"Arial",&g_font))) return false;

// Render function
g_font->DrawTextW(NULL, "Testing text", -1, &rText, DT_LEFT|DT_NOCLIP, 0x00000000);

Both lines there kick back the same error: main.cpp(67) : error C2664: 'D3DXCreateFontW' : cannot convert parameter 11 from 'const char [6]' to 'LPCWSTR' main.cpp(135) : error C2664: 'ID3DXFont::DrawTextW' : cannot convert parameter 2 from 'const char [13]' to 'LPCWSTR' Anyone know what I can do with this?

Share this post


Link to post
Share on other sites
You know that article does look interesting. I tried turning off the Unicode character set option, but that produces a huge problem for me. Why? About a good month's work of trial-and-error coding is built around that unicode option. Most of my code uses wchar_t, and to turn off the unicode option invalidates much of my code in the following way:

direct3d.cpp(52) : error C2664: 'D3DXGetImageInfoFromFileA' : cannot convert parameter 1 from 'wchar_t *' to 'LPCSTR'

So changing to a non-unicode character set is, unfortunately, not an option for me. (It's not just the one error, there are several occurences of this type of error)

I think I figured something out though. I don't know how it slipped by me, but I preceded my text inputs with an L, which fixed all my problems in the past:

	if(FAILED(D3DXCreateFont(*(graphics->getDevice()),24,0,FW_NORMAL,1,false,
DEFAULT_CHARSET,OUT_DEFAULT_PRECIS,ANTIALIASED_QUALITY,DEFAULT_PITCH|FF_DONTCARE,
L"Arial",&g_font))) return false;

g_font->DrawText(NULL, textSample, -1, &rText, DT_LEFT|DT_NOCLIP, 0x00000000);






This no longer produces errors, but now there's nothing being displayed on the screen. On breakpoint, the g_font object gives me no useful information, only several addresses but no readable values attached to anything.

Anyone see anything obviously wrong with this?

Edit: Strangely enough, while "DrawText" is not listed by intellisense, I can use that function as opposed to DrawTextW or DrawTextA. I edited the code in this post to reflect that.

[Edited by - pteri498 on March 25, 2006 7:36:30 AM]

Share this post


Link to post
Share on other sites
Make sure you put an 'L' before your strings, so that the compiler knows that they are wide character strings.


if(FAILED(D3DXCreateFont(*(graphics->getDevice()),24,0,FW_NORMAL,1,false,DEFAULT_CHARSET,
OUT_DEFAULT_PRECIS,ANTIALIASED_QUALITY,DEFAULT_PITCH|FF_DONTCARE,
L"Arial",&g_font))) return false;

// Render function
g_font->DrawTextW(NULL, L"Testing text", -1, &rText, DT_LEFT|DT_NOCLIP, 0x00000000);


xyzzy

Share this post


Link to post
Share on other sites
All righty! I figured out why my text wasn't showing up! My problem was setting the first two numbers in my color code to zero, which effectively renders my text invisible. All right, thanks a lot guys!

Share this post


Link to post
Share on other sites

This topic is 4284 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.

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