2

I've been using GLUT for menu'es in openGl programs for some time now, but have a hard time coming to terms with it being so hard to get text into the gl-scene. Is there no way do use the text system GLUT uses for menus inside the scene?

if so how is it done?

Martin Kristiansen
  • 9,875
  • 10
  • 51
  • 83

3 Answers3

4

Printing x coords of mouse location

char gMouseXLoc[25];
void drawString (void * font, char *s, float x, float y, float z){
     unsigned int i;
     glRasterPos3f(x, y, z);

     for (i = 0; i < strlen (s); i++)
          glutBitmapCharacter (font, s[i]);
}

void displayMethodName {
     ...
     drawString(GLUT_BITMAP_HELVETICA_18, gMouseXLoc, 0, 0, 0); 
}

void mouseMotionForGlut(int x, int y){
     double xloc = x;
     sprintf(gMouseXLoc, "%2.15f", xloc);
}
John Riselvato
  • 12,854
  • 5
  • 62
  • 89
2

There are some other libraries that may be of interest here, such as freeglut (in particular look at the font rendering functions). Alternatively it shouldn't be too hard to write your own function that simply prints a string.

See this question for more alternatives.

Community
  • 1
  • 1
Matt
  • 7,100
  • 3
  • 28
  • 58
2

If you can bother to translate the page and perhaps the comments, this class was done by a student at my school and it's incredibly easy to use. Basically all you have to do is load the font you want to use and then use the print function. 2 lines and it works extremely well. I've used it in some openGL applications and it's really easy to use.

Link: http://4.eepp.ca/?p=phont (Tutorial + code example, in french)

Download: http://4.eepp.ca/files/phont-1.zip

Ps. It uses GL.h and GLU.h

Chris911
  • 4,131
  • 1
  • 23
  • 33