1

I'm using openGL using GLUT. I'm making my own header file with some functions. One of them is a rectangle where you can enter digits and save them. the problem here is that the if I want to know wich key is pressed, I need to put the function in de keyboardFunc callback, but I also want to display the rectangle, so I also need to put it in the display callback because you can't draw anything in the keyboard callback function.

I can make two functions: one for to display the rectangle and one for the keys, but I want one function for both. How can I do this?

Yaz
  • 492
  • 1
  • 6
  • 20
abcdef
  • 236
  • 1
  • 5
  • 17

2 Answers2

1

You can't, as you say yourself. You have to use one function to handle the keyboard events, and one for doing the drawing.

What you can do, is save all valid key-presses in a global variable, and in the display function simply draw them.

If you want to tell GLUT to redisplay as soon as possible, you can call glutPostRedisplay in the keyboard callback function.

Some programmer dude
  • 400,186
  • 35
  • 402
  • 621
1

GLFW is almost the same as GLUT for everything you want but it doesnt make everything a nightmare like GLUT does. You get to control your display function! In GLFW you can define your own call back when a key is pressed. That callback can then save the char pressed into a vector or char array if its fixed length. You will then be able to render the text in your display loop. Be careful with accessing the text array you may need some control over that.

Andrew
  • 1,764
  • 3
  • 24
  • 38
  • +1 for GLFW .Also in GLFW you can define MSAA samples ,color ,stencil,depth bits amount.GLUT is a way too old :) – Michael IV Jan 21 '13 at 19:20