Advertisement Jump to content
Sign in to follow this  

ID3DXFont troubles

This topic is 4879 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 call the DrawText (DX 9) function like this: m_Font->DrawText(NULL, Text, Length, &Rect, Format, Color) the problem is, all that is displayed is squares and L's. it doesn't matter if the string is one word or two or three, as all act the same i really need some help here thanx

Share this post

Link to post
Share on other sites
Hi there Harryu,
How are you doing?

The Problem
Text drawn is being displayed as squares and L's

The Solution
Harry, A couple of things I want you to check.

1) Is the font format that you have chosen valid? You know when you are in word and you choose a font, sometimes the characters you type are displayed as Squares.
This might be a problem. Just check. Set the font to Arial or Times New Roman.

ID3DXFont* text;
ZeroMemory(&textAttr, sizeof(textAttr));
textAttr.Height = 16;
textAttr.Width = 7;
textAttr.Weight = 750;
strcpy(textAttr.FaceName, "Arial");
D3DXCreateFontIndirect(pDevice, &textAttr, &text);

2) Make sure that the font you are drawing isn't cut off by some other primitives. If you are rendering the font first and the some other primitives the font might be cut off and you might see the effects you are seeing now.

3) If the font is too small you might see a different effect than the one you would like to see.

If this does not help please paste your font creation code. I am sure someone on the forums have some other ideas.

Take care buddy.

Share this post

Link to post
Share on other sites
Hi Armadon,

I already had the font set to Arial, and I tried Times New Roman as well. I also tried changing the sizes, but all this did was change the size of the squares and L's. It does the same thing with numbers. I found that when I changed one of the fonts to not use bold, it showed up with squares, instead of L's, so now all the characters are squares.

Share this post

Link to post
Share on other sites
I have encountered a similar problem, when my exe was working alright else where, displaying fonts the way they were supposed to, but just once on one PC, nothing showed except white squares (and no font) where DX was supposed to render text. Furhter more, other exes using the same font displayed correctly on the same PC (where no fonts showed up).

Just as a test run, make a small dx based application and try drawing some text in it the same way. Also, you can try out your exe on a different computer, see if that helps.

I know its not the solution but we might be sharing the same problem.

Share this post

Link to post
Share on other sites
well, i tried on my sisters computer and got the same results, and similar things happen if i use another application and try to draw the fonts

i have just realised however, that some letters sometimes display, but in the wrong places

Share this post

Link to post
Share on other sites
By the way, I just noticed: what version of directX 9 are you using? I am using version 9.0a. DirectX API reference gives me the function DrawText as follows:

DrawText( LPCSTR pString,
INT Count,
DWORD Format,

Where as, your version has NULL as first parameter..i.e.

m_Font->DrawText(NULL, Text, Length, &Rect, Format, Color)

What is the significance first NULL has?

Just for testing, why dont you draw just one simple string, do something like

char str[90]="hello";
int Length = (UINT)strlen(str);
RECT Rect;

Rect.left = 10; = 10;
Rect.right = 510;
Rect.bottom = 60;

//draw using format DT_CENTER
Format = DT_CENTER

Color = 0xffffffff;

This is just supposed to draw some text in a big area, 500 pixels wide, and 50 pixels height.
pText->DrawText( str, Length, &Rect, Format, Color );

Is the whole rectangular area of same color? If so try changing Color. Anything new?

One more thing, how did you acquire handle to font that you used to create m_pFont?

Share this post

Link to post
Share on other sites
i am using directx 9.0c

this is actually quite a long story

at first, i couldn't get the program to run whenever i used the DrawText function
i looked on msdn and found that the version of d3dx9core.h must have been 9.0a, because it's definition for the function was different to the one msdn had
i concluded that the reason my program didn't run, was because the DLL must have been 9.0c, which used a different function definition to that which was used in d3dx9core.h
in the end, i added the extra parameter in d3dx9core.h (which is for a sprite object by the way) and my program would run

well, it wasn't actually that long a story, but still

i don't really know about that kind of stuff though, so i might have stuffed something up

i figured that anything that allowed my program to run was better than anything that didn't, so i left it the way i changed it

i acquired the handle with CreateFontIndirect or something like that, using a LOGFONT structure

by the way Armadon and Taha Ansari, thanks for the help you've given me so far
if you have any more ideas, i could really do with them


Share this post

Link to post
Share on other sites
That is a problem. While rest (many, if not all) of the things are back ward compatible for dx 9.0c, the ID3DXFont is not. One difference is in initializing it, as you'll notice that in call to

D3DXCreateFont( LPDIRECT3DDEVICE9 pDevice, HFONT hFont, LPD3DXFONT *ppFont );

you pass hFont. I think it is different with Dx 9.0c, it manages hFont on its own (?).

Like you've said, header declaration is different for dx9c and dx9a.

If you change the header, without changing dll, things should get unpredictable. And you cannot change dll.

I had encountered similar problem, then resolved it by uninstalling dx9csdk and installing dx9asdk..

Share this post

Link to post
Share on other sites
the thing is, when the header declaration was as it was when i downloaded it, the program wouldn't run at all, i think this is because the functions didn't match up in the dll and in the header

i would go back and try with directx 9a, but using that gives me other errors

i've already put a lot of work into this project, and i really don't want to have to start again, just to make my fonts work --- i KNOW there is a way to fix it

(or at least i hope there is)

just as a point, i should of mentioned this earlier, but if the thing im trying to say ends in a vowel, one of the spaces will be filled with that vowel

don't know if it means anything, but at least it CAN print fonts

[Edited by - Harryu on September 7, 2005 2:01:25 AM]

Share this post

Link to post
Share on other sites
ok, well, i fixed that part of my problem, but now i have a new problem

i learnt that DrawText was interpretting(?) my string (eg "hello") as UNICODE. i needed to change it to L"hello"

now my problem is, if i want the DrawText function to be contained in a different "Print" function, which finds the length of the string, calculates the rectangle, etc..., i need to pass the string to the function somehow

i can't do "Lhello" or something like that, because that would just print squares again, and i know that i can't say:

DrawText(NULL, LText, etc...)

any ideas???

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using, you agree to our community Guidelines, Terms of Use, and Privacy Policy. 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!