I was experimenting with various portable methods for providing a modern GL context. I've been quite content with various context creation toolkits like SDL and SFML. SDL has for awhile been actually quite good, and I can still give it credit because it fills a need that other toolkits simply cannot compare to. It's portable, efficent C code that has its merits of being usable in C unlike the C++ toolkits. However the amount of overhead to get a working SDL context up is unfavorable when doing small demos in comparison to some of the lightweight toolkits like glfw and glut. So I decided to give glut a go after seeing how incredibly simple it is to use. Much to my surprise with that simplicity comes dissappointment.
One of the most annoying things about glut is that there are conflicting implementations of it.
There is the standard glut implementation that you can obtain with google, but the version on
unix OSes is called freeglut. The headers are named differently, but the API mostly matches.
However freeglut has additional useful api functions to return from glutMainLoop()
and register
cleanup callbacks. This is a tremendous pain because those functions are actually useful in
most cases.
If it isn't already obvious GLUT isn't that well maintained, the original GLUT hasn't had many changes to it since 1997. While freeglut does have a more active development than GLUT it isn't that impressive. Most of the changes are to target newer GL versions and not fix or provide any new functionality. For what it's worth the latest version hasn't seen a change in a couple of months, despite a new GL version appearing and display servers being actively improved, e.g wayland.
In most callback driven api designs there is almost always a way to pass control structures as void-pointer-casted values. Allowing the callback to be called with that pointer, effectively allowing someone to cast it back to its original control structure type as a pointer and access any of the members of that control structure type. GLUT simply chooses to ignore this, meaning all the state for the renderer, input, and window handling must be global. This is simply detesting and doesn't work in modular designs where the renderer can be swapped out during runtime for instance.
glutMainLoop()
, the function which never returns cannot be portably escaped from, some versions
of freeglut have a glutLeaveMainLoop()
, but plain glut doesn't. Some versions of freeglut allow
you to create your own main loop and call glutMainLoopEvent()
, but plain glut doesn't. The only
two ways you can cleanup is by either registering a new display callback which is really a cleanup
function, or to use atexit()
handlers. However these methods are simply detesting because both
of them don't have a way to pass around control structures for the functions you can register as callbacks.
The only method I've been capable of using is setjmp()/longjmp()
; a horrendous hack which
upon execution kills newborns. What if this was C++ code that threw exceptions?
In some versions of freeglut using glutWarpPointer
causes some strange behaviour when
being used with less popular window managers, interestingly even Windows operates differently, infact
the function is simply inconsistent everywhere and isn't even supported in some versions of GLUT.
On the systems I tested here are my results:
Operating System: | Window manager: | Effect: |
Windows 7 | native | Capture with no way to release |
Windows XP SP3 | native | Cannot capture at all |
Archlinux | pekwm | Can capture and release |
Debian | openbox | Capture with no way to release |
FreeBSD | none | Segmentation fault |
So in the grande scheme of things I can attest that GLUT and any implementation of it simply sucks. It doesn't allow you to pass control structures to callbacks, it has no sane portable effective method for cleaning up resources. It has various conflicting implementations across versions. Perhaps the worst is the sheer lack of consistency in something as simple as mouse capturing. But what can one expect from an illmaintained library that surfaced from the 90s? I'd like to speak on behalf of everyone, when I say that for the best interest of everyone, we should ignore GLUT like the plague.