Followers 0

# Font Rendering

## 4 posts in this topic

Hey, I also use that algo

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.

0

##### Share on other sites

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 :)

0

##### Share on other sites

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

1

##### Share on other sites

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.

1

## Create an account

Register a new account