can glutSpecialkeys() interrupt other functions??

Say you have the following setup:


void specialKeys()
{
//pressing a key updates paramters for an object in the scene
}

void display()
{
//update object positions and draw the scene
}

void main()
{
//set up window etc…
glutSpecialKeysFunc(specialKeys);
}


I’m doing a gravity/space physics simulation and the above setup works ok. The “player” can control a ship, when a key is pressed it alters the velocity of the chosen ship. But…

When I really hammer the keys a lot some stuff starts going weird. My question is…when exactly does the “specialKeys” function update objects?? Can it interrupt the display function? If so, it can screw up partially calculated velocity vectors etc…

Anybody know any specifics on this? Or a better way to handle user input in general? I’m using glut and c++.

For Windows, things like keystrokes, window resizing, etc. are all placed on a message queue. (Look in MSDN at the WM_* messages for details on all the possible messages)

Every Windows program then has a “message pump” that grabs those messages and calls a callback function generally called a “message handler” or WindowProc. For the typical single threaded app, the WindowProc function will finish handling the message it recieved before the message pump can grab another. (In a single threaded app, the message pump calls the WindowProc function and won’t return from it until it’s done its thing.)

Glut does this same thing, but hides the details of it from you, so to give you a short answer to your question, No. glutSpecialFunc will NOT interrupt your diplay function unless you are doing something like bypassing the display callback and running the display function in another thread, which brings up a whole other set if issues…

[This message has been edited by Deiussum (edited 06-24-2003).]