The FreeType library supports the loading of a wide range of font files (TrueType, PostScript and more). The FreeType engine can load fonts and render to bitmap, but it can also return detailed glyph information.
You can use the FT_Outline_Decompose
function to take an FT_Outline
and decompose it into its constituent lines, arcs and curves. You simply provide a series of function pointers in an FT_Outline_Funcs
struct which will be invoked during the outline processing. These functions are defined by you, so you can simply convert them to whatever format suits your app best (eg. polylines).
The API reference:
Note that if you are rendering large blocks of text which don't change frequently, rendering and filling a series of curves at each frame is quite expensive. The usual solution is to choose a point size, render all the required glyphs into a texture and use a texture atlas to render strings into a quad.
Some useful information is posted here in one of the OpenGL FAQs on fonts, although they also talk about using FreeType. The texture atlas technique is worth reading up: