I have created a new version of glut to provide:
1. Avoiding glutMainLoop()
This has been done by adding the routine
glutCheckLoop()
This routine was created by chopping up the original glutMainLoop following Steve Bakers original article.
glutCheckLoop() processes the outstanding events/messages and then returns to your program! So, now you are in control and able to craft your own event loop
e.g. for(;;)
glutCheckLoop();
which the smart ones of you will recognise as doing exactly what glutMainLoop() did.
glutMainLoop() still exists, and is implemented as above![Note: the MSVC version still uses the original glutMainLoop()].
All existing source code should behave as before.
2. Registering a Window Close callback
This has been a cause for concern for a while. So, I have created a new call to register a callback for when a window is closed.
void glutWMCloseFunc( void (*func)(void) );
func The new Window Close callback
Description
glutWMCloseFunc sets the window close callback for the current window. If no callback is registered, then a default callback is used which executes the original "close" code and therefore all existing code should continue to work in the same way as before!).
If you create more than one window, then glut sets the current window to the one you just create. It will have the default handler unless you call glutWMCloseFunc() to associate your own handler. There is every reason why you may want different handlers for different windows.
A small test program WMtest.c is also available which open two windows with different handlers - the one for window 0 shuts down, the other for window 1 gives a message and the program continues. It also has glutMainLoop() implemented using glutCheckLoop() and shows how to put a wait into the loop!
I hope you find these changes useful. I don't believe I have broken any code (but I am sure you will correct me if I am wrong).
The Windows implementation needs to be fully checked out. Someone please do this and of course, let me know what changes need to be made.
I have built a version of the above code using BC++ (note NOT builder). The file borlandglut.zip contains:
There is also a new .dll, .lib and .h for the latest version of the Windows code MSglut.zip which contains:
Share and enjoy.