 |
|
GLUT Tutorial
Index
Setup
Basics Initialization Resizing the Window Animation
Input Keyboard Moving the Camera Advanced Keyboard Moving the Camera II Mouse
Pop-up Menus Basics Sub Menus Modifying a Menu Swapping Menus
Fonts Bitmap Fonts Bitmaps and the Ortho View Stroke Fonts
Extras Frames per Second GLUT Game Mode
Subwindows Creating and Destroying Subwindows Resizing SubWindows Rendering to SubWindows
OpenGLTutorials @ Lighthouse3d.com
Led Shader
View Frustum Culling
GLSL Tutorial
Maths Tutorial
Billboarding Tutorial
Picking Tutorial
Terrain Tutorial
Display Lists Tutorial
GLUT Tutorial
|
|
 |
|
GLUT Tutorial
Stroke Fonts
A stroke font is a 3D font. As opposed to bitmap fonts these can be rotated, scaled, and translated.
In this section we'll present the GLUT functions to put some stroke text on the screen. Basically, you just need one function: glutStrokeCharacter. The syntax is as follows:
void glutStrokeCharacter(void *font, int character)
Parameters:
-
font - the name of the font to use (see bellow for a list of what's available
-
character - what to render, a letter, symbol, number, etc...
The font options available are:
GLUT_STROKE_ROMAN
GLUT_STROKE_MONO_ROMAN (fixed width font: 104.76 units wide).
The following line of text exemplifies a call to the glutStrokeCharacter function to output a single character at the current local coordinates:
glutStrokeCharacter(GLUT_STROKE_ROMAN,'3');
As opposed to bitmap fonts the render location for stroke fonts is specified in the same way as for any graphical primitive, i.e. using translations, rotations and scales.
The following function renders a string starting at the specified position in local world coordinates:
void renderStrokeFontString(
float x,
float y,
float z,
void *font,
char *string) {
char *c;
glPushMatrix();
glTranslatef(x, y,z);
for (c=string; *c != '\0'; c++) {
glutStrokeCharacter(font, *c);
}
glPopMatrix();
}
Note: GLUT uses lines to draw stroke fonts, therefore we can specify the width of the line with the function glLineWidth. This function takes a float specifying the width as the only parameter.
A Visual C project can be found here. A GLUT pop-up menu is provided for font selection.
As for bitmap fonts, GLUT provides a function that returns the width of a character. The function is glutStrokeWidth and the syntax is as follows:
int glutStrokeWidth(void *font, int character);
Parameters:
-
font - one of the pre defined fonts in GLUT, see above.
-
character - the character which we want to know the width
|