Fltk Glut compatability |
You should be able to compile existing Glut source code by including <FL/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 GL/glut.h to FL/glut.H.
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. I was unable to get some calls to glu to compile without adding some casts, apparently due to errors in the glu header files.
You must link with -lFl. If you call any glut drawing functions
that fltk does not emulate (glutExtensionsSupported(), glutWire*(),
glutSolid*(), and glutStroke*()
), you will also have to link with
-lglut, after -lFl.
Most of glut.H is inline functions. You should take a look at it (and maybe at glut.C 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.
glutLayerGet(GLUT_LAYER_IN_USE)
glutLayerGet(GLUT_HAS_OVERLAY)
glutSetColor(), glutGetColor(), glutCopyColormap()
glutInitDisplayMode(GLUT_STEREO)
glutInitDisplayMode(GLUT_LUMINANCE)
glutPushWindow()
glutWarpPointer()
glutDeviceGet()
glutWindowStatusFunc()
glutGet(GLUT_WINDOW_NUM_CHILDREN)
glutGet(GLUT_SCREEN_WIDTH_MM)
glutGet(GLUT_SCREEN_HEIGHT_MM)
glutGet(GLUT_ELAPSED_TIME)
glutVideoResize()
missing.
GLUT_DOWN
and GLUT_UP
, mouse
buttons GLUT_LEFT_BUTTON, GLUT_MIDDLE_BUTTON,
GLUT_RIGHT_BUTTON
, and GLUT_KEY_F1
thru
F12
.
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 glutOverlayDisplayFunc()
.
glutLayerGet(GLUT_OVERLAY_DAMAGED)
always
returns true, this fixed 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.
glutBitmapCharacter() and
glutBitmapWidth()
may be different.
glutInit(argc,argv)
will consume different switches than glut
does. It accepts the switches recognized by Fl_Window::arg(), and will accept any
abbreviation of these switches (such as -d for -display).
Don't call glutInit().
Create your Fl_Window, and any fltk widgets. Leave a blank area in the window for your glut window.
show() the Fl_Window. Perhaps call show(argc,argv).
Call window->begin() so the glut window will be automatically added to it.
Use glutInitWindowSize() and 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 glutCreateWindow()!
You can call either glutMainLoop() or Fl::run() or loop calling Fl::wait() to run the program.
The current glut window is available in Fl_Glut_Window
*glut_window
.
new Fl_Glut_Window(...)
is the same as
glutCreateWindow()
except it does not show() the window
or make the window current.
window->make_current()
is the same as
glutSetWindow(number)
. If the window has not had show()
called on it yet, some functions that assumme a gl context will not
work. If you do show() the window, call make_current() again to set
the context.
~Fl_Glut_Window()
is the same as
glutDestroyWindow()
.