fltk/documentation/glut.html

195 lines
6.7 KiB
HTML
Raw Normal View History

<HTML>
<BODY>
<H1 ALIGN=RIGHT><A NAME="glut">D - GLUT Compatibility</A></H1>
This appendix describes the GLUT compatibility header file supplied with
FLTK.
<H2>Using the GLUT Compatibility Header File</H2>
You should be able to compile existing GLUT source code by including
<tt>&lt;FL/glut.H></tt> instead of <tt>&lt;GL/glut.h></tt>. This can
be done by editing the source, by changing the <tt>-I</tt> switches to
the compiler, or by providing a symbolic link from <tt>GL/glut.h</tt>
to <tt>FL/glut.H</tt>.
<p><i>All files calling GLUT procedures must be compiled with C++</i>. 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.
<p>You must link with the FLTK library. If you call any GLUT drawing
functions that FLTK does not emulate
(<tt>glutExtensionsSupported()</tt>, <tt>glutWire*()</tt>,
<tt>glutSolid*()</tt>, and <tt>glutStroke*()</tt>), you will also have
to link with the GLUT library (<i>after</i> the FLTK library!)
<p>Most of <tt>FL/glut.H</tt> is inline functions. You should take a
look at it (and maybe at <tt>test/glut.cxx</tt> in the FLTK source) if
you are having trouble porting your GLUT program.
<p>This has been tested with most of the demo programs that come with
the GLUT 3.3 distribution.
<h2>Known Problems</h2>
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:
<ul>
<li><tt>glutLayerGet(GLUT_LAYER_IN_USE)</tt>
<li><tt>glutLayerGet(GLUT_HAS_OVERLAY)</tt>
<li><tt>glutSetColor(), glutGetColor(), glutCopyColormap()</tt>
<li><tt>glutInitDisplayMode(GLUT_STEREO)</tt>
<li><tt>glutInitDisplayMode(GLUT_LUMINANCE)</tt>
<li><tt>glutPushWindow()</tt>
<li><tt>glutWarpPointer()</tt>
<li>Spaceball, buttonbox, dials, tablet functions,
<tt>glutDeviceGet()</tt>
<li><tt>glutWindowStatusFunc()</tt>
<li><tt>glutGet(GLUT_WINDOW_NUM_CHILDREN)</tt>
<li><tt>glutGet(GLUT_SCREEN_WIDTH_MM)</tt>
<li><tt>glutGet(GLUT_SCREEN_HEIGHT_MM)</tt>
<li><tt>glutGet(GLUT_ELAPSED_TIME)</tt>
<li><tt>glutVideoResize()</tt> missing.
</ul>
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 <tt>GLUT_DOWN</tt> and <tt>GLUT_UP</tt>, mouse
buttons <tt>GLUT_LEFT_BUTTON, GLUT_MIDDLE_BUTTON,
GLUT_RIGHT_BUTTON</tt>, and <tt>GLUT_KEY_F1</tt> thru
<tt>F12</tt>.
<p>The strings passed as menu labels are not copied.
<p><tt>glutPostRedisplay()</tt> does not work if called from
inside a display function. You must use <tt>glutIdleFunc()</tt>
if you want your display to update continuously.
<p><tt>glutSwapBuffers()</tt> does not work from inside a display
function. This is on purpose, because FLTK swaps the buffers for you.
<p><tt>glutUseLayer()</tt> does not work well, and should only be
used to initialize transformations inside a resize callback. You
should redraw overlays by using <tt>glutOverlayDisplayFunc()</tt>.
<p>Overlays are cleared before the overlay display function is called.
<tt>glutLayerGet(GLUT_OVERLAY_DAMAGED)</tt> always returns true for
compatibility with some GLUT overlay programs. You must rewrite your
code so that <tt>gl_color()</tt> is used to choose colors in an
overlay, or you will get random overlay colors.
<p><tt>glutSetCursor(GLUT_CURSOR_FULL_CROSSHAIR)</tt> just
results in a small crosshair.
<p>The fonts used by <tt>glutBitmapCharacter() and
glutBitmapWidth()</tt> may be different.
<p><tt>glutInit(argc,argv)</tt> will consume different switches than GLUT
does. It accepts the switches recognized by <a
href="#args"><tt>Fl::args()</tt></a>, and will accept any
abbreviation of these switches (such as "-di" for "-display").
<h2>Mixing GLUT and FLTK Code</h2>
You can make your GLUT window a child of a <tt>Fl_Window</tt> with the
following scheme. The biggest trick is that GLUT insists on
<tt>show()</tt>'ing the window at the point it is created, which means the
<tt>Fl_Window</tt> parent window must already be shown.
<ul>
<li>Don't call <tt>glutInit()</tt>.
<li>Create your <tt>Fl_Window</tt>, and any FLTK widgets.
Leave a blank area in the window for your GLUT window.
<li><tt>show()</tt> the <tt>Fl_Window</tt>. Perhaps call
<tt>show(argc,argv)</tt>.
<li>Call <tt>window->begin()</tt> so that the GLUT window will
be automatically added to it.
<li>Use <tt>glutInitWindowSize()</tt> and
<tt>glutInitWindowPosition()</tt> to set the location in the
parent window to put the GLUT window.
<li>Put your GLUT code next. It probably does not need many changes.
Call <tt>window->end()</tt> immediately after the <tt>glutCreateWindow()</tt>!
<li>You can call either <tt>glutMainLoop()</tt>,
<tt>Fl::run()</tt>, or loop calling <tt>Fl::wait()</tt> to run
the program.
</ul>
<hr break>
<h2><a name="Fl_Glut_Window">class Fl_Glut_Window</a></h2>
<hr>
<h3>Class Hierarchy</h3>
<ul><pre>
<a href="#Fl_Gl_Window">Fl_Gl_Window</a>
|
+----<b>Fl_Glut_Window</b>
</pre></ul>
<h3>Include Files</h3>
<ul><pre>
#include &lt;FL/glut.H>
</pre></ul>
<h3>Description</h3>
Each GLUT window is an instance of this class. 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 FLTK's method of creating windows.
<p>The current GLUT window is available in the global variable
<tt>glut_window</tt>.
<p><tt>new Fl_Glut_Window(...)</tt> is the same as
<tt>glutCreateWindow()</tt> except it does not <tt>show()</tt> the window
or make the window current.
<p><tt>window->make_current()</tt> is the same as
<tt>glutSetWindow(number)</tt>. If the window has not had
<tt>show()</tt> called on it yet, some functions that assumme an OpenGL
context will not work. If you do <tt>show()</tt> the window, call
<tt>make_current()</tt> again to set the context.
<p><tt>~Fl_Glut_Window()</tt> is the same as
<tt>glutDestroyWindow()</tt>.
<h3>Methods</h3>
<ul>
<li><a href="#Fl_Glut_Window.Fl_Glut_Window">Fl_Glut_Window</a>
<li><a href="#Fl_Glut_Window.~Fl_Glut_Window">~Fl_Glut_Window</a>
</ul>
<h4><a name="Fl_Glut_Window.Fl_Glut_Window">Fl_Glut_Window::Fl_Glut_Window(int x, int y, int w, int h, const char *title = 0)<br>
Fl_Glut_Window::Fl_Glut_Window(int w, int h, const char *title = 0)</a></h4>
The first constructor takes 4 int arguments to create the window with
a preset position and size. The second constructor with 2 arguments
will create the window with a preset size, but the window manager
will choose the position according to it's own whims.
<h4><a name="Fl_Glut_Window.~Fl_Glut_Window">virtual Fl_Glut_Window::~Fl_Glut_Window()</a></h4>
Destroys the GLUT window.
</BODY>
</HTML>