Introduction to OpenGL - L23

Displaying Text

Unfortunately displaying text is not one of the strong points of OpenGL. However, it is possible to display bit mapped text relatively easily, and there are various 3rd party solutions which can provide 3D extruded text and so on. In this lesson we will use the GLUT library text. The available bit mapped fonts are:

GLUT_BITMAP_8_BY_13
GLUT_BITMAP_9_BY_15
GLUT_BITMAP_TIMES_ROMAN_10
GLUT_BITMAP_TIMES_ROMAN_24
GLUT_BITMAP_HELVETICA_10
GLUT_BITMAP_HELVETICA_12
GLUT_BITMAP_HELVETICA_18

and the available stroke fonts are

GLUT_STROKE_ROMAN
GLUT_STROKE_MONO_ROMAN

To render the text on to the scene we use the GLUT library functions

void glutBitmapCharacter(void *font, int character);
void glutStrokeCharacter(void *font, int character);

where font is the bitmap font to use, and character is the character to render.

Notice that each of these functions render a single character. Also, note there is no specification of the location of the character. The characters are drawn at the current raster position. This can be set with the OpenGL funtcion call

glrasterPos2f( x,y );

or one of the variants. It is therefore useful to write a function which will display a string of text starting at a specific scene location.

Now proceed to the next part of the lesson.


(c) 2001 Dr R P Fletcher, Computing Service