Skip to main content
gamedev.net
🔒 Locked

D3DXFont problem

Started by Noggs 3 replies 1.6k views
Original Post
Noggs
Noggs
I really hope it's not something stupid due to lack of sleep but I'm having a problem rendering text in my d3d9 app on Vista (if that makes any difference). I know there's no error checking in this code but I've stepped through and checked the return values in the debugger and they all succeed apart from the DrawText call.

		// HACK!!		static ID3DXFont* font = NULL;		if(font==NULL) {			res = D3DXCreateFont( d3ddev, 10, 0, FW_DONTCARE, 0, FALSE, ANSI_CHARSET, OUT_DEFAULT_PRECIS, DEFAULT_QUALITY, DEFAULT_PITCH | FF_DONTCARE, "Verdana", &font );			AssertNoMessage( SUCCEEDED( res ) );		}		res = d3ddev->BeginScene();		static D3DCOLOR fontColor = D3DCOLOR_ARGB(255, 255, 255, 255);		static Int32 lineHeight = 12;		static Int32 lineWidth = 500;		static Int32 startPosX = 20;		static Int32 startPosY = 20;		{			RECT rect;			rect.top = startPosY;			rect.bottom = rect.top + lineHeight;			rect.left = startPosX;			rect.right = startPosX + lineWidth;			res = font->DrawText( NULL, "hello", 5, ▭, DT_LEFT|DT_NOCLIP, fontColor );			res = d3ddev->EndScene();			return;		}


The DrawText line always fails. In this example it returns 0xA "The environment is incorrect." If I change the font to Courier New it returns 0x8 "Not enough storage is available to process this command."

I've tried with and without Begin/EndScene calls - same problem.

Any help would be greatly appreciated!
Buckeye
Buckeye
Try setting rect.bottom and rect.right to 0. Using your font create, this works for me:
RECT rc;SetRect(&rc, 5, 5, 0, 0);g_pFont->DrawText(NULL,"hello",5,&rc,DT_LEFT | DT_NOCLIP,D3DCOLOR_RGBA(255,64,64,255));
Please don't PM me with questions. Post them in the forums for everyone's benefit, and I can embarrass myself publicly. You don't forget how to play when you grow old; you grow old when you forget how to play.
Noggs
Noggs
Thanks for the suggestions. I was already running with maximum debug output - it gives me nothing when I step the command. I tried setting the rect up as Buckeye suggested but it made no difference - still failed. It's odd that it's a windows error rather than a directx return code.

The Text3D and 2D sample works, so I'm going to start picking that apart.
Noggs
Noggs
Wow yep it WAS lack of sleep! DrawText doesn't return HRESULT it returns an int. When I ran the program I realised i had fixed the problem a while ago (was with the createfont call). I had not checked the 3d output just saw the 'failed' return codes in the debugger that didn't make any sense.

Apologies for wasting your time!

Topic Locked

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

Sign in to reply to this topic.