How do I draw a text string onto the screen using GLUT / OpenGL drawing functions?
+1
A:
It's generally a bit nasty and not straightforward. Give this tool a try:
notnot
2009-02-11 20:44:46
Please note that you will need [freeglut][1], as opposed to glut, to use glutBitmapString. [1]: http://freeglut.sourceforge.net/
superjoe30
2009-09-09 04:49:21
I 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
2010-09-25 22:52:02
@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
2010-09-26 00:04:32
@epatel thanks ! that solved my puzzle
Jonathan
2010-09-26 05:40:50
+1
A:
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
2009-02-11 20:49:16
+2
A:
If you don't like the built-in stroke font or bitmap font that comes with GLUT as per epatel's answer, you'll have to roll your own solution.
NeHe has some good tutorials (along with fully-working sample code) on this:
Adam Rosenfield
2009-02-11 20:51:22