How do I draw a text string onto the screen using GLUT / OpenGL drawing functions?
Asked
Active
Viewed 9.7k times
2 Answers
26
There are two ways to draw strings with GLUT
glutStrokeString will draw text in 3D
(source: uwa.edu.au)
and glutBitmapString will draw text facing the user
(source: sourceforge.net)

Glorfindel
- 21,988
- 13
- 81
- 109

epatel
- 45,805
- 17
- 110
- 144
-
7Please note that you will need [freeglut][1], as opposed to glut, to use glutBitmapString. [1]: http://freeglut.sourceforge.net/ – andrewrk Sep 09 '09 at 04:49
-
1I know its an old question, I have glut.h it just when I try to use either of the method it will say identifier "glutBitmapString" or "glutStrokeString" is undefined any ideas ? – Jonathan Sep 25 '10 at 22:52
-
@Jonathan superjoe30 is right. glutBitmapString and glutStrokeString are not in the original GLUT implementation. But, if you want to use GLUT I'd suggest looking into using either freeglut or openglut which both have them. If I recall correctly the original GLUT implementation has not been updated since 1998 due to its licensing scheme so freeglut and openglut was started to solve that problem and add new features etc. See http://freeglut.sourceforge.net/ – epatel Sep 26 '10 at 00:04
11
void RenderString(float x, float y, void *font, const char* string, RGB const& rgb)
{
char *c;
glColor3f(rgb.r, rgb.g, rgb.b);
glRasterPos2f(x, y);
glutBitmapString(font, string);
}
And you can call it like;
RenderString(0.0f, 0.0f, GLUT_BITMAP_TIMES_ROMAN_24, "Hello", RGB(1.0f, 0.0f, 0.0f));

Andrew Grant
- 58,260
- 22
- 130
- 143
-
4error: request for member ‘r’ in ‘rgb’, which is of non-class type ‘const int’ – Nitin Garg Nov 26 '11 at 13:11