1

I am making a racing game and I would like to print some information such as speed, lap, key bindings etc. on the screen of my scene. I want them to be flat on the screen, having a position lets say fixed in front of the camera (like speedometers in real games) not inside my scene - if that's not possible then I ll print them inside my scene.

Do you know what functions can I use (glutBitmapCharacter?)I tried printw but my program doesn't compile. What do you propose?

There will be multiple messages printed from various routines

I have already tried this (nothing displays on screen)

glPushMatrix();
                 glRasterPos2f(100, 100);
                 glColor3f(0.0,0.5,0.1);
                sprintf(message,"\nLap(User):%d",lapsB);
                len = (int) strlen(message);
                for (int i = 0; i < len; i++) {
                    glutBitmapCharacter(GLUT_BITMAP_HELVETICA_18, message[i]);
                }
                glPopMatrix();

One more thing how can I create a menu - is there any method I can use, user will have to chose between 3 entries, input by pressing 1 or 2 or 3 on keyboard only

George Panic
  • 431
  • 1
  • 8
  • 20
  • Rendering text in openGL is a complicated matter with various solutions. It has been asked before in this site many times. Refer to this question for detailed answers: http://stackoverflow.com/questions/5262951/what-is-state-of-the-art-for-text-rendering-in-opengl-as-of-version-4-1 Also depends on your version of openGL, so it would be nice to tell us what openGL version you are using and what OS you are targeting – Lefteris Feb 15 '12 at 15:05
  • It's version 4.2 under windows 7, fellow Greek! – George Panic Feb 15 '12 at 15:23
  • Found something about menus: glutCreateMenu(MenuSelect); glutAddMenuEntry("Red",RED); // attach the menu to the right button glutAttachMenu(GLUT_RIGHT_BUTTON); I'll just use the mouse I don't have any time – George Panic Feb 15 '12 at 15:40
  • this doesn't word either : glutStrokeCharacter(GLUT_STROKE_ROMAN,str[i]); – George Panic Feb 15 '12 at 15:54
  • Are you using a core or compatibility context? – Nicol Bolas Feb 15 '12 at 16:30
  • After all the comments we seem to have exchanged he most probably is not using a core context. He is just trying to render some text using the default context given by windows. – Lefteris Feb 15 '12 at 16:38
  • Not sure what that is, I was wrong glutStrokeCharacter works just like all other glut functions. I just didn't use it properly :( . This is pretty much what I needed thank you all for the interest! – George Panic Feb 15 '12 at 16:39

3 Answers3

0

nothing displays on your screen because glutBitmapCharacter is expecting the ASCII code of the character you are sending. you are sending the int value of the character for digits

instead you need to send the ascii value of each character in your char buffer message

Eg if you want to display '1', send 1 + 48, as 48 is ascii code for 0 glutBitmapCharacter(GLUT_BITMAP_HELVETICA_18, 1+48)

Mr Bat Lee
  • 122
  • 5
0

I have the feeling you are passing too big values for glRasterPos2f(100, 100); Here is a good post where you can see how to display text using GLUT printing text with glut.

Ivaylo Strandjev
  • 69,226
  • 18
  • 123
  • 176
  • I lowered the values, followed the example still doesn't work. I posted the message in my idle function so that it would flash all the times. My scene's resolution is 720p – George Panic Feb 15 '12 at 15:35
0

Are you sure you are succesfully creating an openGL 4.2 core context under Windows? (Needs some explicit work to achieve it) Just having a card that supports openGL 4 does not mean you are working with an openGL 4 core context.

That aside if you ARE working on an openGL 4.2 core context then glutBitmap() would not work since it's deprecated along with glRasterPos()

Refer to the same answer I gave in the comments of the original post where I link to a very good answer already given on how to render openGL text.

Community
  • 1
  • 1
Lefteris
  • 3,196
  • 5
  • 31
  • 52
  • i just typed this: cout << "OpenGL Version : " << glGetString(GL_VERSION) << endl; Don't really know if I have created such a context – George Panic Feb 15 '12 at 15:46
  • yes correct. I will edit the answer to reflect the difference between compatibility and core context – Lefteris Feb 15 '12 at 16:31
  • @NicolBolas For completeness sake I have to say that in my answer I was just trying to determine what the OP's problem was and I posted a possible cause of glutBitmap not working since he said he is working with openGL 4.2. Only later in the comments did it become clear he did not know what a context is which meant it is a compatibility context he is dealing with. – Lefteris Feb 15 '12 at 17:02