View Full Version : glutSpecialFunc
01-30-2001, 06:56 AM
I have a very long while loop. I want to be able to break out of the while loop by pressing a key on the keyboard. Does anyone know if this is possible with GLUT? So far I have only been able to get the program to recognize the keypress after the entire while loop has finished.
01-30-2001, 07:46 AM
You could put the key detection code in a seperate worker thread, and simply set a flag in memory shared by the threads when a key is detected. Then in your while loop, periodically check the flag. I've never used glut so there may be an easier way.
I know there is an easier way in Windows using the Win32 api.
01-30-2001, 12:13 PM
Glut basically just hides the details of the Win32 API from you right? In your while loop you could probably use things like PeekMessage, or GetInputState just to see if there are any mouse or keyboard events in your message queue. That's probably kind of ugly, though. Does Glut have anything equivalent to VB's DoEvents? I've never really had anything where I've needed to do that in glut, so I'm not sure.
01-30-2001, 03:35 PM
You should probably break your while-loop up into restartable chunks and check for a flag (set by your keypress in the specialfunc callback) between chunks.
Either that or make the keypress flag part of your while-loop's condition. So long as you do not alter the keypress flag in the code with the while-loop you should be okay.
Make sure to tag the keypress flag variable as 'volatile' or you might never get to see it change...
Powered by vBulletin® Version 4.2.2 Copyright © 2015 vBulletin Solutions, Inc. All rights reserved.