Jump to content
  • Advertisement
Sign in to follow this  

CD3DFont artifact fix

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

Hello, I recently tried using a CD3DFont object for drawing text and noticed some artifacts while using certain fonts (notably, Times New Roman and Arial). The artifacts appear below a lowercase letter 'i' when the text size is sufficiently large (a height of 19 or above for Times New Roman, for example). This can be seen in this screenshot: text artifacts When looking at the large versions, it's clear that the 'artifacts' are really just the bottom portion of the letter 'j' in the font bitmap that is being displayed along with the 'i.' So, for a quick hack that seems to fix this problem for all sizes of text (atleast on Times New Roman and Arial), I changed how the CD3DFont calculates its texture coordinates that are used with the font bitmap. Specifically, I raised the bottom edge of the lowercase 'i' coordinate slightly (the amount raised is proportional to the height of the text). The result: no text artifacts In the HRESULT CD3DFont::InitDeviceObjects( LPDIRECT3DDEVICE9 pd3dDevice ) method, scroll down to this part:
m_fTexCoords[c-32][0] = ((FLOAT)(x+0))/m_dwTexWidth;
m_fTexCoords[c-32][1] = ((FLOAT)(y+0))/m_dwTexHeight;
m_fTexCoords[c-32][2] = ((FLOAT)(x+0+size.cx))/m_dwTexWidth;
m_fTexCoords[c-32][3] = ((FLOAT)(y+0+size.cy))/m_dwTexHeight;
And change it to:
m_fTexCoords[c-32][0] = ((FLOAT)(x+0))/m_dwTexWidth;
m_fTexCoords[c-32][1] = ((FLOAT)(y+0))/m_dwTexHeight;
m_fTexCoords[c-32][2] = ((FLOAT)(x+0+size.cx))/m_dwTexWidth;

if( (char)c == 'i' )
	m_fTexCoords[c-32][3] = ((FLOAT)(y-(m_dwFontHeight/6)+size.cy))/m_dwTexHeight;
else
	m_fTexCoords[c-32][3] = ((FLOAT)(y+0+size.cy))/m_dwTexHeight;
It's a quick hack that does the trick :) If there are any fonts that this works incorrectly with, post 'em here.

Share this post


Link to post
Share on other sites
Advertisement
Good post - might be useful to a few people [smile]

However, it's worth noting that CD3DFont is from the older application framework for DX-SDK (unless I'm being stupid!) and has been superceded by ID3DXFont - which is a lot better from what I've seen.

Cheers,
Jack

Share this post


Link to post
Share on other sites
Yeah, from my tests it seems as though ID3DXFont is alot faster than CD3DFont with the DX9 release (and it has always been more robust).

Share this post


Link to post
Share on other sites
Quote:
Original post by kosmon_x
Yeah, from my tests it seems as though ID3DXFont is alot faster than CD3DFont with the DX9 release (and it has always been more robust).

I haven't really stress-tested it myself, I'm one of few people (I'd guess) that chose to roll-their-own [grin]

Not that ID3DXFont is bad, but I could, and have, got quite substantially higher performance by tailoring a text output system to the domain of our game engine; basically taking advantage of the way that it works by caching/preprocessing as much stuff as possible.

Jack

Share this post


Link to post
Share on other sites
Quote:
Original post by jollyjeffers
I'm one of few people (I'd guess) that chose to roll-their-own [grin]


Hey, Microsoft actually recommends it in the DirectX 9 Developer FAQ :P

Share this post


Link to post
Share on other sites
Maybe someone can help me here :)
I'm having a problem with ID3DXFont and rendering to screen: the result has a bad blur effect on characters.
I'm trying to compare my code with the sample in DX SDK, but i can't see the difference. Maybe kosmon_x have a clue?

Share this post


Link to post
Share on other sites
Quote:
Original post by il_maestro
Maybe someone can help me here :)
I'm having a problem with ID3DXFont and rendering to screen: the result has a bad blur effect on characters.
I'm trying to compare my code with the sample in DX SDK, but i can't see the difference. Maybe kosmon_x have a clue?


Same problem over here. Characters are looking very blurry with ID3DXFont. I noted the blur-effect for the first time, after i installed the december SDK. IIRC, with the summer SDK everything looked perfectly good.

Share this post


Link to post
Share on other sites
Quote:
Original post by il_maestro
Maybe someone can help me here :)
I'm having a problem with ID3DXFont and rendering to screen: the result has a bad blur effect on characters.
I'm trying to compare my code with the sample in DX SDK, but i can't see the difference. Maybe kosmon_x have a clue?

I've seen this in a few places with text rendering - all of which resolve down to using a small (or large) font and then scaling it at the rendering level.. Thus texture filtering kicks in to try and smooth things over...

As I declared earlier, I don't use ID3DXFont, so I can't be of direct help - but I'd check that the font size you're using and the output rect/size aren't causing some nasty scaling issues.

If thats not the case, then maybe look into the ClearType and Anti Aliasing "hints" that sometimes appear with text rendering. Might well be an additional flag you can pass into ID3DXFont to stop the blurring.

hth
Jack

Share this post


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

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!