Font rendering in GLUT using bitmap fonts with Sample example.

GLUT supports two types of font rendering: stroke fonts, meaning each character is rendered as a set of line segments; and bitmap fonts, where each character is a bitmap generated with glBitmap. Stroke fonts have the advantage that because they are geometry, they can be arbitrarily scale and rendered. Bitmap fonts are less ﬂexible since they are rendered as bitmaps but are usually faster than stroke fonts. In this tutorial, I will explain about Bitmap fonts. The function that renders bitmap character using OpenGL is glutBitmapCharacter. The syntax is
glutBitmapCharacter (void *font, int character);
font –> bitmap font to use and character –> Character to render.
For example,
glutBitmapCharacter(GLUT_HELVETICA_10,'a');
outputs a single character ‘a’ at the current raster position.
There are 7 bitmap fonts available in GLUT. They 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
You can render the character in any raster position of the window. The raster position can be set using family of functions glRasterPos from OpenGL library. The syntax of the functions are:

void glRasterPos2f(float x, float y);
void glRasterPos3f(float x, float y, float z);

Source code of Sample Example

Output

SHARE Font rendering in GLUT using bitmap fonts with Sample example.

4 Responses

1. Maria says:

Thank you for bitmap fonts guide! Really helped a lot!

2. Peter says:

Thank you, this was the only example, that I could use! Very helpful!!!

3. can we add new font in GLUT because i need bigger size font for this GLUT_BITMAP_TIMES_ROMAN_24 font