Joshua
Joshua

Reputation: 1208

How do you render super smooth fonts with DirectX9?

Simply using ID3DXFont::DrawText() alone produces jagged fonts, especially at larger font sizes. Is there a way to use DirectX9 to render fonts extremely smoothly like in the Windows 8 Metro UI?

I am sort of trying to avoid DirectWrite because it requires Direct2D, but I am using DirectX9.

Upvotes: 1

Views: 4436

Answers (3)

Darthman
Darthman

Reputation: 457

ID3DXFont is not capable to draw really cool and smooth fonts. To achieve this I render my own texture atlas for font and then draw it with quads with textures. Second way is to draw font from atlas with similar way, but using Distance field method. Distance field with simple pixel shader will provide you very smooth and scalable fonts.

At this point I achieved this: my distance field font

Upvotes: 0

josephthomas
josephthomas

Reputation: 3276

You could create a bitmap font render, which can ranged from "very simple" to "very complicated".

For a simple way, there is this example, that although is in Managed DirectX, can easily be done in C++/DirectX 9. Bitmap Fonts. You can also easily create bitmap font sheets with this free app Bitmap Font Generator (there is also links to how to create bitmap renders in here).

Then there is more complex ways to do fonts, such as using signed distanced fields as described at Improved Alpha-Tested Magnification for Vector Textures.

Upvotes: 0

Rick Brewster
Rick Brewster

Reputation: 3494

DirectWrite doesn't actually require Direct2D, and can be used on its own (IDWriteBitmapRenderTarget). It's just much, much easier to use Direct2D to render DirectWrite text into an IWICBitmap (via ID2D1Factory::CreateWicBitmapRenderTarget()), and then draw that bitmap using DX (maybe by copying to a DX surface, or using some shared surface approach; I'm not familiar with the specifics here). You can create an IWICBitmap via IWICImagingFactory::CreateBitmap().

Metro doesn't appear to use ClearType, so grayscale should be just fine. Proper ClearType text would actually require per-component alpha and as such it generally doesn't work to render it into a bitmap with an alpha channel.

Are you using DX9 so that you can run on XP, or are you using it for another reason? If you are able to require Win7 or Vista SP2 + Platform Update as your minimum, then I highly recommend looking into using D2D+DW to render text into a bitmap and then use DX to draw the bitmap.

Upvotes: 1

Related Questions