views:

9516

answers:

4

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:

http://students.cs.byu.edu/~bfish/glfontdl.php

notnot
+7  A: 
epatel
Please note that you will need [freeglut][1], as opposed to glut, to use glutBitmapString. [1]: http://freeglut.sourceforge.net/
superjoe30
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
@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
@epatel thanks ! that solved my puzzle
Jonathan
+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
+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