# Antialiased text rendering (D3DX9)

This topic is 3628 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Hi, I can't figure out how to render text at a decent quality, with D3DX. I'm creating the font like this:
// Unmanaged C++
D3DXCreateFont(d3dDevice, pxSize, 0, (bold ? FW_BOLD : FW_NORMAL), 0, italics,
DEFAULT_CHARSET, OUT_DEFAULT_PRECIS, ANTIALIASED_QUALITY, DEFAULT_PITCH|FF_DONTCARE,
fontface, &(pFont->d3dxfont));


Then I render it with:
    m_pD3DXSprite->Begin(D3DXSPRITE_OBJECTSPACE|D3DXSPRITE_ALPHABLEND);

font.d3dxfont->DrawText(m_pD3DXSprite, text, -1, &rect, format, color);
m_pD3DXSprite->End();


The result looks pretty bad compared to drawing text in MS Paint: Any ideas what I'm doing wrong? Why is the text coming out so knobbly and aliased even with ANTIALIASED_QUALITY set? Thanks for any help.

##### Share on other sites
Try CLEARTYPE_QUALITY or PROOF_QUALITY for the Quality parameter. They should produce even better results. Check out the full description here.

##### Share on other sites
Ah, thanks. Cleartype quality improves it - but it's still nowhere near as nice as with MS Paint. Is it not possible to render text at that quality in DirectX?

Here's how it looks now. Note CLEARTYPE_QUALITY is better, but still not as good as MS Paint.

##### Share on other sites
Interesting link legalize, but surely I would be reinventing the wheel? Presumably MS Paint calls some GDI function that looks lovely, so why can't I get D3DX to do it that nicely?

##### Share on other sites
GDI doesn't natively support alpha. Using GDI directly to draw text would be slow. ID3DXFont works by grabbing glyphs from GDI and rasterizing them once using GDI into a texture. The texture is then used for drawing the text, but it isn't re-rasterized at different sizes. GDI re-rasterizes in software every time you change a parameter that controls font size (but not glyph spacing). Reproducing all the font subtlety behaviors in ID3DXFont is tedious and can also impact performance. ID3DXFont doesn't promise to get the same quality as GDI font rendering; it does remarkably well considering. If you need exact GDI quality output, then I'd suggest that you use a system memory surface that is compatible with GDI, render text to that and then make a billboard texture from that surface yourself and draw the text with the billboard.

However, all of that is going to be slower and at worse quality than the method presented by Blinn and Loop in that paper. I would not be surprised if you see GDI's text rendering ultimately replaced with the Blinn and Loop algorithm, or a variant of it, at some point in the future as Vista and subsequent releases of Windows leverage the GPU more and more for desktop operations.

##### Share on other sites
Quote:
 Original post by legalize[...] If you need exact GDI quality output, then I'd suggest that you use a system memory surface that is compatible with GDI, render text to that and then make a billboard texture from that surface yourself and draw the text with the billboard.

Either that or you can construct a bitmapped font altogether if you can stick with one single size. Then you would have full control over the quality of characters.

##### Share on other sites
Quote:
Original post by staaf
Quote:
 Original post by legalize[...] If you need exact GDI quality output, then I'd suggest that you use a system memory surface that is compatible with GDI, render text to that and then make a billboard texture from that surface yourself and draw the text with the billboard.

Either that or you can construct a bitmapped font altogether if you can stick with one single size. Then you would have full control over the quality of characters.

This is what ID3DXFont does.

##### Share on other sites
Ah, yes, sorry. I was going more along the line of using an external program or way to create a high quality bitmap font specifically for the situation. It could be some work but if quality is a high priority it might also be worth it.

Interesting article by the way legalize.

##### Share on other sites
Quote:
 Original post by legalizeID3DXFont works by grabbing glyphs from GDI and rasterizing them once using GDI into a texture.

I don't understand why this still results in poor quality text - doesn't it render each glyph with GDI (which should render glyphs at the same quality MS Paint does), then move them to a texture and render strings from the texture? As in, effectively render it to a bitmap font in video memory. Why would this result in poor quality text rendering, if it's using GDI?

So is there no way for ID3DXFont to achieve MS Paint quality? How do commercial games go about this? And is there some kind of library someone's already written to do text rendering in decent quality? I set out to draw text to the screen, and wasn't really expecting to have to design my own entire font rendering engine...

1. 1
Rutin
25
2. 2
JoeJ
20
3. 3
4. 4
5. 5

• 9
• 9
• 46
• 41
• 23
• ### Forum Statistics

• Total Topics
631749
• Total Posts
3002051
×