Survey Of OpenGL Font Technology
Contents
Introduction
-
This document describes the known methods for displaying text inside an OpenGL program.
- 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
- Rotate, translate, scale
- Color, material, lighting
- Antialiasing
- Texture mapping
There is no native font support in OpenGL.
Why use fonts? For presentation of textual information in an OpenGL scene. Examples:
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
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:
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
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().
- 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 - Bitmap only. No 3D capability.
- Only available on Unix/X systems.
- Requires GLUT.
- Download (Unix) - glxfont.tar.gz.
Use glXUseXFont(), which creates a set of display lists, one per glyph.
Advantages
Disadvantages
Example Program
Example Output
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.
- 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).
- Only uses .pfa (ASCII-encoded) fonts. But it's easy to convert via pfb2pfa.
- GLC is only available on SGI workstations, however there is currently an effort underway to provide an open (LGPL) implementation of the GLC specification.
- This program demonstrates rotation, scaling, and translation of an outline font.
- Requires GLUT.
- Download: glclogo.tar.gz
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
Disadvantages
Example Program
Example Output
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-3
See also the GLUT distribution, progs/glc/glcdemo.c.
GLUT
-
There are two options for drawing fonts in GLUT:
- Bitmap - glutBitmapCharacter()
- Stroke - glutStrokeCharacter()
- Very easy to use.
- Limited in choice of fonts. Hard to add new fonts.
- What if you're not using GLUT? Then you have to link with GLUT.
- Requires GLUT.
- Download (Unix) - glutfonts.tar.gz.
- Download (Windows) - glutfonts.zip.
Advantages
Disadvantages
Example Program
Example Output
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.
- 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.
- Poor quality when scaled, due to over-sampling.
- Most implementations do not provide correct metrics or kerning.
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
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
Disadvantages
Example Program
Example Output
Figure 5-2
GLTT
-
See the GLTT home page at http://gltt.sourceforge.net.
- Bitmapped
- Antialiased pixmapped
- Outline
- Polygonized
- Very easy to use.
- Powerful and versatile.
- Cross platform (Unix and Windows).
- Can use any TrueType font.
- Easily accessible metrics - very important for "typesetting".
- Slower than the texture mapped text technique, but even so, GLTT would be very useful for generating the font texture images.
- 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.
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:
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
Disadvantages
Example Program
Example Output
Figure 6-1
FTGL
- Outline
- Polygonal
- Texture mapped
- Bitmapped
- Antialiased pixmapped
- Very easy to use.
- Powerful and versatile.
- Cross platform (Unix and Windows).
- Can use any TrueType font.
- Kerning!
- Font loading time.
- This program demonstrates the various text rendering capabilities of FTGL.
- Requires http://homepages.paradise.net.nz/henryj/code/index.html#FTGL, and FreeType.
- Download (Unix) - ftgl-demo.tar.gz.
- Download (Windows) - ftgl-demo.zip.
See http://homepages.paradise.net.nz/henryj/code/index.html#FTGL.
FTGL is the successor to GLTT. FTGL was written against the FreeType2 API. See http://www.freetype.org/
FTGL supports the following rendering types:
Advantages
Disadvantages
Example Program
Example Output
Figure 7-1
WGL
-
This is specifically for the Windows platform.
- Bitmap - wglUseFontBitmaps()
- Outline - wglUseFontOutlines()
- Very easy to use.
- Can use any Windows font, including TrueType.
- Not cross platform - Windows only.
- Doesn't provide access to font contours directly.
- Access to font metrics via Win32 API.
- 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
- 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().
There are two options:
There is plentiful information on the Microsoft MSDN web site. For example, read this article.
See also NeHe's lessons 13 and 14.
Advantages
Disadvantages
Example Program
Example Output
Figure 8-1
Example Program
Example Output
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.
- Very simple to build and use.
- Feature-rich API.
- Multi-platform.
- The .glf font file format is currently undocumented. No known way to convert fonts to the .glf format.
- The demos subdirectory of the GLF distribution contains 13 example programs which demonstrate the GLF library.
The GLF API is concise, straightforward, yet very roboust.
Advantages
Disadvantages
Example Program
Example Output
Figure 9-1
Links
|