user1182183
user1182183

Reputation:

DirectX 9 Font libraries?

I had a look at the Font class in DirectX Documentation and looked at this/these question/answers but they didn't satisdy my need.

I tried searching for "C++ DirectX 9 Font library" yet this didn't yield any useful results.

Are there any DX9 Font libraries available that, for example, can load TTF fonts (eg Arial) and then draw them on the screen?

The current class I am using does satisfy most of my needs but is buggy as hell :( (in terms of, when I alt tab a third party application in which I draw information, it crashes and it's somehow not in my DLL).

Upvotes: 0

Views: 2587

Answers (2)

Drop
Drop

Reputation: 13003

It's time to write your own bitmap font renderer! You will need:

  • Good font loader (FreeType)
  • Texture atlas: a big texture with all letters and a dictionary that holds metadata for each letter
  • some kind of Sprite batch: efficient sprite drawing

Step-by-step:

  1. FreeType: load font file and render each character to small bitmap
  2. Your atlas creation: merge (blit) all small bitmaps into big atlas texture and store attributes (coordinates, size, kerning, other stuff) of each character in "atlas dictionary".
  3. Draw characters from atlas (using dictionary) using sprite batching

Well, for a first time you can start from someting like: take character's bitmap from FreeType and draw it directly, but I think that performance will be very low.

Update: Hard to write a small example on such a topic, but:

  • about font loading libraries you can read its docs
  • about atlases you can look Chad Vernon's blog. It's C# but syntax is easy to understand for C++ coder. BitmapCharacterSet in his code is atlas.
  • about sprite batching: check Frank Luna books and/or source code. In his small utils library he has a font renderer too

Upvotes: 1

Tobias Schlegel
Tobias Schlegel

Reputation: 3970

You may want to have a look at BMFont ( http://www.angelcode.com/products/bmfont/ ) which converts TTF fonts to bitmaps. They can then be rendered with this code: http://www.angelcode.com/dev/bmfonts/

It's not a ready-to-use library though.

Upvotes: 0

Related Questions