# 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.

## 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 on other sites
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 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 on other sites
Quote:
 Original post by kosmon_xYeah, 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 on other sites
Quote:
 Original post by jollyjeffersI'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 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 on other sites
Quote:
 Original post by il_maestroMaybe 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 on other sites
Quote:
 Original post by il_maestroMaybe 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 on other sites
If someone is interested, here i posted something else about the problem.

• 10
• 18
• 14
• 18
• 15