Monday, February 07, 2005

Display Font in GLUT - 1

There are two ways to display text in GLUT. The first is using bitmap fonts -- unscalable and doesn’t response to modelview transform. My preferred way is stroke fonts -- fonts that are drawn from OpenGL primitives.

(1) To insert fonts in GLUT (see here for documentation)

void glutStrokeCharacter(void *font, int character);
font:
This method can handle two types of font (first argument), namely
GLUT_STROKE_ROMAN
GLUT_STROKE_MONO_ROMAN
The MONO version is a fixed-width font (like Courier New, etc)

character:

Takes in any ASCII character from 32 through 127

(2) To get the measurement of its length

int glutStrokeLength(void *font, const unsigned char *string);

This method returns the width in units from the unscaled modeling units


This is how to use them:
(3) Define a string generator function
This function serves to render the string being passed to it.

void renderStrokeString( void *font, const string& str )
{
for (int i = 0; i lessThan str.length(); i++)
glutStrokeCharacter(font, str[i]);
}




0 Comments:

Post a Comment

<< Home