tags:

views:

1088

answers:

4

Does anyone have any tutorials/info for creating and rendering fonts in native directx 9 that doesn't use GDI? (eg doesn't use ID3DXFont).
I'm reading that this isn't the best solution (due to accessing GDI) but what is the 'right' way to render fonts in dx?

+1  A: 

Why this isn't a good solution?

Mixing GDI rendering and D3D rendering into the same window is a bad idea.

However, ID3DXFont does not use that. It uses GDI to rasterize the glyphs into a texture. And uses that texture to render the actual text.

About the only alternative would be using another library (e.g. FreeType) to rasterize glyphs into a texture, but I'm not sure if that would result in any substantial benefits.

Of course, for simple (e.g. non-Asian) fonts you could rasterize all glyphs into a texture beforehand, then use that texture to draw text at runtime. This way runtime does not need to use any font rendering library, it just draws quads using the texture. This approach does not scale well with large font sizes or fonts with lots of characters. Also would not handle complex typography very well (e.g. where letters have to be joined etc.)

NeARAZ
A: 

With DirectX, the correct way to render standard fonts is with GDI.

However, IF

  • You want to support cross platform font rendering
  • with proper support for internationalization - including far eastern languages where maintaining a glyph for every character in a font is impractical
  • and/or You want to distribute your own fonts and render them without "installing" them...

Then libfreetype might be what you are looking for. I don't claim its easy: Its a lot more complex than using the native font api.

Chris Becke
A: 

ID3DXFont is a great thing for easy to use, early, debug output. However, it does use the GDI for font rasterization (not hardware accelerated) and there is a significant performance hit (try it, its actually very noticable). As of DirectX 11, though, fonts will be rendered with Direct2D and be hardware accelerated.

The fastest way to render text is using what's called "Bitmap Fonts". I would explain how to do this, except that there is a lot of different ways to do implement this technique, each differing in complexity and capability. It can be as simple as a system that loads a pre-created texture and draws the letters from that, or a system that silently registers a font with Windows and creates a texture in memory at load-time (The engine I developed with a friend did this, it was very slick). Either way, you should see a very noticable performance increase with bitmap fonts.

Eric
A: 

Personally I think that ID3DXFont is the way to go. If you really wanted to make your own font routines, I suggest you look at: http://creators.xna.com/en-us/utilities/bitmapfontmaker

You can use this to create a bitmap with all the characters printed on it. Then its just a matter or loading the texture and blitting the relevant chars onto the screen at the right place. (This is what XNA uses for its font drawing)

Its a lot more work, but you don't need the font to be installed on the target PC, and you have the advantage to being able to go into photoshop and edit the font appearance there.

Mark Gossage