Font Rendering

Started by
3 comments, last by Ryan_001 9 years, 8 months ago

A while ago I wrote for my own uses a font loading/rendering helper library. I posted it on sourceforge because a few people in other forums expressed interest. There's been alot of talk lately on font rendering in games, so I thought I'd post a link in case anyone is interested.

http://sourceforge.net/projects/ttftriangulator/

Unlike most font rendering libraries, this doesn't use or produce a texture/sprite sheet. Rather it triangulates the characters into an actual mesh. There are a couple different choices of triangulators, one that produces very compact representations that uses the technique described here: http://http.developer.nvidia.com/GPUGems3/gpugems3_ch25.html. There are a few others as well.

Its worked well for myself and from what I understand a few others. If any bugs are found I'm happy to fix them.

Advertisement

Hey, I also use that algo cool.png

Thank you for sharing hopefully someone will find it useful. I see it's a pretty broad library in terms of scope as it collects quite some data about the font as well. I'm surprised the triangolator is fast, it looks very simple.

Previously "Krohm"

Ya, after reading the chapter in GPU Gems 3 I was inspired and couldn't think of a better place to use that than with font rendering. Then I realized it could actually be useful and decided to clean it up a bit and post it. But really it was just about having fun :)

This library really needs some kind of docs or at least example code, I wasn't able to figure it out.

Ya I guess it does, when I have some time I will. Really quickly the steps to use it would be...

1) Create a Font object like:


TTF::Font font("fonts/Nexa-Light.otf");

The Font object has all the font data, like bounding rects, kerning info, headers, code point to glyph index conversion, ect...

2) Create a triangulator:


TTF::TriangulatorI triangulator;

Currently there are 3. Each triangulator will have different outputs. TriangulatorI uses the GPU gems 3 vector rendering (ie. requires a pixel shader). TriangulatorII on the other hand is just a standard mesh (no special pixel shader required) but requires you to supply a function to specify how to subdivide the curves.

3) Create a Mesh object to store the glyph:


TTF::MeshSmall mesh;

Mesh small is useful for most fonts, but its theoretically possible that some glyphs might be too large (have too many vertices) to be stored in a MeshSmall object, in which case you can use a MeshLarge object. There's almost no difference from a user standpoint, a MeshLarge just uses a less compact storage.

4) Triangulate the glyph:


font.GetGlyph(CodePoint(text[i]),triangulator,mesh);
In this case text is a std::string. Now you can do whatever you want with the glyph (add it to a vertex buffer perhaps).
5) Optionally get the kerning:

TTF::vec2s t = font.GetKerning(CodePoint(text[i]),CodePoint(text[i+1]));

Kerning is the distance between one glyph and the next.

This topic is closed to new replies.

Advertisement