Part of the Khronos Group

NOTE: This page contains old archived material and may not be relevant anymore.

Survey Of OpenGL Font Technology

Survey Of OpenGL Font Technology
Contents

Introduction
    This document describes the known methods for displaying text inside an OpenGL program.

    There is no native font support in OpenGL.

    Why use fonts? For presentation of textual information in an OpenGL scene. Examples:

    • ID of planes in Air Traffic Control display
    • Geographic place names on a map
    • Games - aircraft Heads-Up Display, vehicle speedometer, high-score
    • Video titling

    There are three approaches to rendering fonts in OpenGL: bitmap, outline (polygonal), and texture mapped. Each method has its own advantages and disadvantages.

    Bitmap Fonts

      Bitmap fonts are ideally suited for scale and rotation-independent labeling of items within a scene. Since bitmap fonts are by nature pre-rasterized, they render very quickly, making them a good choice where speed is important.

      The location of a bitmap font is determined by glRasterPos(). Thus you will experience the usual problem of bitmaps disappearing when the raster pos is outside the view volume (even though the rest of the bitmap is inside the view volume).

      This example shows bitmap fonts being used to label the atoms in a molecule.

      Figure 1-1

      Figure 1-1

    Outline Fonts

      Outline fonts describe the character outlines with a combination of control points and curves. The underlying approach will help you convert the characters into polygons which you can render either as filled polygons or as outlines. These polygons can be manipulated in the same way as any other polygon in OpenGL. This includes:

      • Rotate, translate, scale
      • Color, material, lighting
      • Antialiasing
      • Texture mapping

      The font outlines are particularly useful as contours for extrusion effects. This example shows an extruded, texture mapped, and lit rendering of a text string.

      Figure 1-2

      Figure 1-2

    Texture Mapped Text

    This method represents text characters with texels; as such, text strings can be manipulated the same as any OpenGL texture. This technique is particularly effective for decaling labels onto the surfaces of objects such as street signs, water towers, etc.

GLX
    Access the font using the normal X method, XLoadQueryFont().

    Use glXUseXFont(), which creates a set of display lists, one per glyph.

    Advantages

    • Can use any X font on your system. Use xlsfonts to list fonts currently on your system. Use xfd to preview the fonts already on your system.
    • Can easily add fonts for your personal use by just adding the directory containing your font to your font path with
      % xset fp+ /usr/people/gerard/fonts
      % xset fp rehash

    Disadvantages

    • Bitmap only. No 3D capability.
    • Only available on Unix/X systems.

    Example Program

    Example Output

    Figure 2-1

    Figure 2-1


GLC
    This is a library which uses Adobe Type1 fonts. It provides bitmap, line, and triangle rendering styles. This library is only available on SGI workstations, under IRIX 6.2 and later.

    Do a man glcintro for more info.

    The spec is located at http://trant.sgi.com/opengl/docs/Specs/glcspec.ps. There is some evidence that the ARB was aware of this, but there is no record of discussion in any of the ARB's minutes.

    Advantages

    • Uses Adobe Type1 fonts. These are fairly easy to come by, or at least you can convert your favorite font to this format using a font conversion utility.
    • Can draw bitmap fonts with rotation (but this capability is is imperfect - see below).

    Disadvantages

    Example Program

    • This program demonstrates rotation, scaling, and translation of an outline font.
    • Requires GLUT.
    • Download: glclogo.tar.gz

    Example Output

    Figure 3-1

    Figure 3-1

    Notes

      Also, look in /usr/share/src/OpenGL/teach/glc for examples. test2.c is a particularly good example.

      Here are two screendumps of GLC's test2 demo program in action. In the first picture, notice how inaccurately GLC rotates bitmapped text string "0123456789". This text should fit precisely inside the aqua-colored box. In the second picture (which uses an outline version of the font), notice how GLC correctly rotates the filled representation of the text.

      Figure 3-2

      Figure 3-2

      Figure 3-3

      Figure 3-3

      See also the GLUT distribution, progs/glc/glcdemo.c.


GLUT
    There are two options for drawing fonts in GLUT:
    • Bitmap - glutBitmapCharacter()
    • Stroke - glutStrokeCharacter()

    Advantages

    • Very easy to use.

    Disadvantages

    • Limited in choice of fonts. Hard to add new fonts.
    • What if you're not using GLUT? Then you have to link with GLUT.

    Example Program

    Example Output

    Figure 4-1

    Figure 4-1


Texture Mapped Text
    See Mark Kilgard's paper, A Simple OpenGL-based API for Texture Mapped Text. This is an exceptionally clever application of texture mapping, and it offers a good balance between performance, ability to apply 3D transforms, and compactness of implementation.

    See also Brad Fish's glFont API. The distribution provides a program for generating a texture containing the characters. The API contains routines for loading a texture and for drawing strings using the texture.

    Figure 5-1

    Figure 5-1

    See also NeHe's lesson 15.

    See also Steve Baker's FNT library. This uses fonts in the same TXF format as described in Mark Kilgard's paper.

    Advantages

    • Fast when running on texture mapping hardware.
    • Same advantages as with GLX - easy to create new fonts to use, but you don't have to add them to the system.
    • Can decal text onto any surface using the usual texture mapping techniques.

    Disadvantages

    • Poor quality when scaled, due to over-sampling.
    • Most implementations do not provide correct metrics or kerning.

    Example Program

    Example Output

    Figure 5-2

    Figure 5-2


GLTT
    See the GLTT home page at http://gltt.sourceforge.net.

    GLTT is a wrapper around the FreeType library. FreeType is a "free, quality, and portable TrueType engine." GLTT uses Freetype to extract contours and for rasterization, and provides a simple but powerful API for rendering text. GLTT supports the following rendering types:

    • Bitmapped
    • Antialiased pixmapped
    • Outline
    • Polygonized

    GLTT also provides an API to access the vectorized font outline contours, which you can then manipulate directly to achieve some really neat special effects (such as warping and extrusion).

    There is a very impressive demonstration program (demo.C) included in the GLTT distribution which shows all the various GLTT capabilities.

    Advantages

    • Very easy to use.
    • Powerful and versatile.
    • Cross platform (Unix and Windows).
    • Can use any TrueType font.
    • Easily accessible metrics - very important for "typesetting".

    Disadvantages

    • Slower than the texture mapped text technique, but even so, GLTT would be very useful for generating the font texture images.

    Example Program

    • This program shows how to use GLTT to access the font countours and tessellation information for use in extruding. This example is based heavily on the logo.C demo program from the GLTT distribution.
    • Requires GLUT, GLTT, and FreeType.
    • Download (Unix) - extrude.tar.gz.
    • Download (Windows) - extrude.zip.

    Example Output

    Figure 6-1

    Figure 6-1


FTGL

WGL
    This is specifically for the Windows platform.

    There are two options:

    • Bitmap - wglUseFontBitmaps()
    • Outline - wglUseFontOutlines()

    There is plentiful information on the Microsoft MSDN web site. For example, read this article.

    See also NeHe's lessons 13 and 14.

    Advantages

    • Very easy to use.
    • Can use any Windows font, including TrueType.

    Disadvantages

    • Not cross platform - Windows only.
    • Doesn't provide access to font contours directly.
    • Access to font metrics via Win32 API.

    Example Program

    • This demonstrates how to use both bitmap and outline fonts in an OpenGL program in Microsoft Windows. This program is based on the examples given in Ron Fosner's book, OpenGL Programming for Windows 95 and Windows NT (aka, "The White Book").
    • Download - WglFontDemo.zip

    Example Output

    Figure 8-1

    Figure 8-1

    Example Program

    • This is an example program in The OpenGL SuperBible (1st edition) by Richard Wright and Michael Sweet which demonstrates the rudimentary extrusion capability of wglUseFontOutlines().

    Example Output

    Figure 8-2

    Figure 8-2


GLF
    Roman Podobedov (aka 'Romka') has created the GLF font rendering library. This library supports numerous techniques for text rendering including bitmapped, outline, and texture mapped. With GLF, outline font rendering can display wire frame, solid, and both extruded wireframe and extruded solid.

    The GLF API is concise, straightforward, yet very roboust.

    Advantages

    • Very simple to build and use.
    • Feature-rich API.
    • Multi-platform.

    Disadvantages

    • The .glf font file format is currently undocumented. No known way to convert fonts to the .glf format.

    Example Program

    • The demos subdirectory of the GLF distribution contains 13 example programs which demonstrate the GLF library.

    Example Output

    Figure 9-1

    Figure 9-1


Links
Page Link
La Fonte 3D Text Maker http://www.aptrio.com/Multimedia/Fonts/lafonte-1798.html
Font Magic http://www.mattcawley.com/fontmagic/
TrueType Typography http://www.lorp.org/truetype/
Type1 Font Tools http://www.lcdf.org/~eddietwo/type/
Softy Font Editor http://users.breathe.com/l-emmett/
Column Header
Column Footer