Sign in to follow this  
Benjamin GD

Direct3D 9 text is coming out nasty and jagged

Recommended Posts

My font class:
class font
{
private:
ID3DXFont *my_font;

public:
void create(LPCSTR p_fontname, uint p_fontsize, uint p_bold, bool p_italic)
{
uint weight;
if (p_bold)
weight = 1000;
else
weight = FW_NORMAL;

D3DXCreateFont(device,MulDiv(p_fontsize,GetDeviceCaps(hdc,LOGPIXELSY),72),0,weight,0,p_italic,DEFAULT_CHARSET,OUT_DEFAULT_PRECIS,ANTIALIASED_QUALITY,DEFAULT_PITCH | FF_DONTCARE,p_fontname,&my_font);
}

void draw(LPCTSTR p_text, int p_x, int p_y, D3DXCOLOR p_color)
{
RECT rect = {p_x,p_y,0,0};
my_font->DrawTextA(NULL,p_text,-1,&rect,DT_TOP | DT_LEFT | DT_NOCLIP,p_color);
}
};


It looks extremely ugly on my screen with skipped lines and things like that. I have bought some Direct3D 9 games and the text doesn't look like this...

What do you think is wrong?

Share this post


Link to post
Share on other sites
Well, first of all, most published games probably don't use the ID3DXFont interface and roll out their own font routines.

Secondly, could you provide a screenshot or something? Would be easier to suggest what is wrong if we can actually see the result.

Share this post


Link to post
Share on other sites
Screenshot: http://www.upurload.com/files/b3163cfca5ed1fe842d5139e185ec9c6.png
How do I make this image show in the post? Can I use HTML or is it a weird form of BB code?

"most published games probably don't use the ID3DXFont interface"

What do they do then?

[Edited by - Benjamin GD on October 1, 2010 9:50:42 PM]

Share this post


Link to post
Share on other sites
Quote:
How do I make this image show in the post?

Take a look at the faq (upper-right-hand corner of this page).



Click on EDIT for my post and take a look at the format.

Are you drawing the text before or after you render the triangle?

EDIT: If you want to scare yourself about D3DXSPRITE and D3DXFONT, take a look at Evil Steve's article.

Share this post


Link to post
Share on other sites
Create a texture atlas offline (Photoshop, GIMP, perhaps a custom tool) that contains all your glyphs (and polish it appropriately), then use it in-game with a textured quad per character (batching, caching, etc as necessary).

Share this post


Link to post
Share on other sites
I'm not sure how relevant EvilSteve's article is anymore, Buckeye.

I know there have been many performance enhancements in ID3DXSprite/Font over the years, and at least one really big one. I'm rather certain that he was looking through an older version, especially if that was written in 2006.

Share this post


Link to post
Share on other sites
Could I possibly load font characters into an array of bitmaps or something? I don't actually know how to do this, but I want to know. I don't want to go without text in my game.


Edit: I mean font files themselves, it would be much easier for the people who use my engine to be able to choose default fonts, rather than get an artist to draw each letter...

[Edited by - Benjamin GD on October 1, 2010 10:24:26 PM]

Share this post


Link to post
Share on other sites
Make sure your back-buffer has the same size as the window. If you set the size of the back-buffer when creating your window, use AdjustWindowRectEx to make sure the actual client-area of the window is the same size. When you create a window the size you specify includes borders. If your back-buffer doesn't match your window size, it could make your image look wrong and miss pixels.

Share this post


Link to post
Share on other sites
Quote:
Original post by Benjamin GD
Edit: I mean font files themselves, it would be much easier for the people who use my engine to be able to choose default fonts, rather than get an artist to draw each letter...


You could base your engine's font system on the files produced by BMFont and instruct users to use this with whatever fonts they want.

Share this post


Link to post
Share on other sites
I second Erik's comment. To me it looks just like there's a problem with your setup, not with the font/sprite. Are the triangle's top and left side of the same length ? Then the diagonal shouldn't be "jagged" either. Can you show us your device creation/reset code, i.e. the presentation parameters you use, please ?

Share this post


Link to post
Share on other sites
Quote:
Original post by Flimflam
I'm not sure how relevant EvilSteve's article is anymore, Buckeye.

Quote:
Original post by Benjamin GD
Thank you, it worked! By the way, how old is Evil Steve's article? Was it before Direct3D 9?
It was written after the "substantial improvements" to the D3DX library in DX9.0c, but there's still a good chance that they've been made to perform better by now.
If in doubt, see what PIX shows you; you'll be able to see all the render states, etc that are set.

As for the actual problem, it looks to me like you're not using AdjustWindowRect() when you create your window. That means that a window that's created as 640x480 will have a client area (Area not including window borders, etc) of around 632x458 or similar.
Because the D3D device is created with a backbuffer of 640x480, you're having to shrink the backbuffer when displaying it on the window. Because the text is distorted a lot more vertically than it is horizontally, I think this is pretty likely.

The size you pass to CreateWindow is the window size - that's the size including the window borders. D3D only renders to the client area. To find the correct window size to use for a given client area size, use AdjustWindowRect.

Clicky:

Share this post


Link to post
Share on other sites

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