Game Development Stack Exchange is a question and answer site for professional and independent game developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have to watch the keyboard during rendering. So, is there a way to force glut to invoke the Keyboard callback immediately?

share|improve this question
What exactly are you trying to do here? Poll the keyboard during rendering? If so, you definitely do not want to go down that route. Separate your fast-as-it-can-go rendering code from your event-triggered input logic. Event logic updates the game state when something happens (like a key is pressed). Rendering logic just draws the game state to the screen. – Bob Somers Feb 27 '11 at 12:08

I'm unclear as to when exactly you think "immediately" is in this context, or what you're actually trying to do by "watching the keyboard during rendering."

But given that you must have known what function is actually being assigned to the keyboard callback (since you had to pass to the glutKeyboardWhatever function), couldn't you just directly invoke the function you passed yourself when you want to?

No flavor of GLUT that I'm aware of has the ability to manually invoke the callback indirectly.

share|improve this answer
I can not do that, because I would not know the received keys (glut gives it to you as the functions arguments) – user5584 Feb 25 '11 at 17:53
Of course. How else do you expect it to work? You can certainly query the OS directly to get the keyboard state and send those keys to your function. This will depend on the OS, and supporting multiple OSs will require some effort on your part. But that's the only way you can do it since GLUT doesn't have an on-demand keyboard state reading method, iirc. – Josh Petrie Feb 25 '11 at 18:21

I have to watch the keyboard during rendering.

Fullstop here. Go over your code again and rethink how stuff works. Logic and rendering should be strictly seperated. There should no situation what-so-ever arise for you to need to check the input during the rendering calls. Rendering doesn't compute input. It just works with what's being given to it.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.