Fltk Glut compatability

#include <FL/glut.H>

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.

Known Problems

Mixing Glut code and Fltk code

You can make your Glut window a child of a Fl_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 Fl_Window parent window must already be show()n.

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.

class Fl_Glut_Window : public Fl_Gl_Window

Each Glut window is an instance of this class, which is a subclass of Fl_Gl_Window. You may find it useful to manipulate instances directly rather than use glut window id's. These may be created without opening the display, and thus can fit better into FL's method of creating windows.

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().

(back to contents)