This file provides GLUT compatibility in FLTK 2.0.
GLUT is/was a popular toolkit for making single-window OpenGL applications. GLUT is Copyright© Mark J. Kilgard, 1994, 1995, 1996. FLTK's emulation is not based on any GLUT code and is not subject to any license other than FLTK's.
Most glut emulation is done by the GlutWindow class, and inline functions in this header file that turn GLUT calls into instances and methods on those instances. You should take a look at it (and maybe at
test/glpuzzle.cxx in the FLTK source) if you are having trouble porting your GLUT program.
This has been tested with most of the demo programs that come with the GLUT 3.3 distribution.
You should be able to compile existing GLUT source code by including
<fltk/glut.h> instead of
<GL/glut.h>. This can be done by editing the source, by changing the
-I switches to the compiler, or by providing a symbolic link from
All files calling GLUT procedures must be compiled with C++. You may have to alter them slightly to get them to compile without warnings, and you may have to rename them to get make to use the C++ compiler.
You must link with the FLTK library. If you call any GLUT drawing functions that FLTK does not emulate (
glutStroke*()), you will also have to link with the GLUT library (after the FLTK library!)
The following functions and/or arguments to functions are missing, and you will have to replace them or comment them out for your code to compile:
glutSetColor(), glutGetColor(), glutCopyColormap()
Most of the symbols/enumerations have different values than GLUT uses. This will break code that relies on the actual values. The only symbols guaranteed to have the same values are true/false pairs like
GLUT_UP, mouse buttons
GLUT_LEFT_BUTTON, GLUT_MIDDLE_BUTTON, GLUT_RIGHT_BUTTON, and
The strings passed as menu labels are not copied.
glutPostRedisplay() does not work if called from inside a display function. You must use
glutIdleFunc() if you want your display to update continuously.
glutSwapBuffers() does not work from inside a display function. This is on purpose, because FLTK swaps the buffers for you.
glutUseLayer() does not work well, and should only be used to initialize transformations inside a resize callback. You should redraw overlays by using
Overlays are cleared before the overlay display function is called.
glutLayerGet(GLUT_OVERLAY_DAMAGED) always returns true for compatibility with some GLUT overlay programs. You must rewrite your code so that
gl_color() is used to choose colors in an overlay, or you will get random overlay colors.
glutSetCursor(GLUT_CURSOR_FULL_CROSSHAIR) just results in a small crosshair.
The fonts used by
glutBitmapCharacter() and glutBitmapWidth() may be different.
glutInit(argc,argv) will consume different switches than GLUT does. It accepts the switches recognized by
fltk::args(), and will accept any abbreviation of these switches (such as "-di" for "-display").
You can make your GLUT window a child of a Window with the following scheme. The biggest trick is that GLUT insists on
show() 'ing the window at the point it is created, which means the
fltk::Window parent window must already be shown.
Create your Window, and any FLTK widgets. Leave a blank area in the window for your GLUT window.
Window::show() the new Window. Perhaps call Window::show(argc,argv).
Call Window::begin() so that the GLUT window will be automatically added to it.
glutInitWindowPosition() to set the location in the parent window to put the GLUT window.
Put your GLUT code next. It probably does not need many changes. Call Window::end() immediately after the
You can call either
glutMainLoop(), or the FLTK run(), or loop calling the FLTK wait() to run the program.