Text fonts
In a stroke font, a character is created as a series of linked line segments. Essentially, we can think of this as a GL_LINE_STRIP primitive.
The starting position of a character can be specified in 3D space. The character will be defined in the xy-plane of the modelview coordinate system current at the time of definition. Since stroke characters are line segments, they are also affected by any further the various viewing/modeling transformations.
A bitmap is a rectangular area of pixel values.
The starting position of the character can be specified in 3D space. This is transformed by the viewing/modeling transformation to specify a starting pixel location in the frame buffer. The character itself however, is not affected by any of the transformations; it always appears aligned with the xy-plane of the display screen, i.e. the pixel coordinate system.
The starting position of a character is specified with the following function:
glRasterPos{234}{sifd}(x, y [, z [, w]]); /* set raster position */where curly braces, { and }, indicate the selection of one character, and square brackets, [ and ], indicate optional characters. As in the various formats of the glVertex function, the numeral indicates the dimensionality of the coordinates, and the letter indicates the data type.
OpenGL does not provide any predefined bitmap fonts, but several fonts are defined by GLUT. The following GLUT function draws a single character.
void *font; /* pointer to font */ int c; /* character to draw */ glutBitmapCharacter(font, c); /* draw character */where font is one of the following macro values:
defined in the header file glut.h.
The glutBitmapCharacter function automatically increments the raster position by the width of the displayed character.
Because it is a bit clumsy to have to display character strings one character at a time, the following function draws the entire string.
void bitmapString(void *font, char *s) { int i; /* recall that string s ends with NULL */ for (i=0; s[i]; i++) glutBitmapCharacter(font, s[i]); /* draw one character */ }