From 2d6a98560e1f3f027180be34cfc625eabfb32f05 Mon Sep 17 00:00:00 2001
From: Michael R Sweet This chapter discusses using FLTK for your OpenGL applications.
+
The easiest way to make an OpenGL display is to subclass Fl_Gl_Window.
+Your subclass must implement a draw() method which uses
+OpenGL calls to draw the display. Your main program should call
+redraw() when the display needs to change, and
(somewhat later) FLTK will call draw().
- With a bit of care you can also use OpenGL to draw into normal FLTK
-windows. This allows you to use Gouraud shading for
-drawing your widgets. To do this you use the
-gl_start() and gl_finish()
-functions around your OpenGL code. You must include FLTK's <FL/gl.h> header file. It will
-include the file <GL/gl.h>, define some extra drawing
-functions provided by FLTK, and include the <windows.h> header
-file needed by WIN32 applications. With a bit of care you can also use OpenGL to draw into
+normal FLTK windows. This allows you to use Gouraud shading for
+drawing your widgets. To do this you use the gl_start() and gl_finish() functions around your
+OpenGL code. You must include FLTK's <FL/gl.h> header
+file. It will include the file <GL/gl.h>, define
+some extra drawing functions provided by FLTK, and include the
+<windows.h> header file needed by WIN32
+applications. To make a subclass of Fl_Gl_Window, you must provide:
+
If your subclass provides static controls in the window, they
+must be redrawn whenever the FL_DAMAGE_ALL bit is set
+in the value returned by damage(). For double-buffered
+windows you will need to surround the drawing code with the
+following code to make sure that both buffers are redrawn:
+
+ If you are using the Mesa graphics library, the call
+ to glDrawBuffer() is not required and will slow
+ down drawing considerably. The preprocessor instructions
+ shown above will optimize your code based upon the
+ graphics library used.
+
+ To define the subclass you just subclass the
+Fl_Gl_Window class:
+
+ The draw() and handle() methods are
+described below. Like any widget, you can include additional
+private and public data in your class (such as scene graph
+information, etc.)
+
The draw() method is where you actually do your
+OpenGL drawing:
+
+ The handle() method handles mouse and keyboard
+events for the window:
+
+ When handle() is called, the OpenGL context is not
+set up! If your display changes, you should call
+redraw() and let draw() do the work. Don't
+call any OpenGL drawing functions from inside handle()!
+
You can call some OpenGL stuff like hit detection and texture
loading functions by doing: 8 - Programming with FLUID
+9 - Programming with FLUID
This chapter shows how to use the Fast Light User-Interface Designer
("FLUID") to create your GUIs.
diff --git a/documentation/fluid.man b/documentation/fluid.man
index 0b69440e9..39a8e28fc 100644
--- a/documentation/fluid.man
+++ b/documentation/fluid.man
@@ -1,27 +1,32 @@
-.TH fluid 1 "Fast Light Tool Kit" "27 January 2001"
+.TH fluid 1 "Fast Light Tool Kit" "6 January 2002"
.SH NAME
fluid \- the fast light user-interface designer
.sp
.SH SYNOPSIS
-.nf
-fluid \fI[-c [-o code-filename -h header-filename]] [filename.fl]\fR
+fluid [ -c [ -o
+.I code-filename
+-h
+.I header-filename
+] ] [
+.I filename.fl
+]
.fi
.SH DESCRIPTION
-\fIfluid\fR is an interactive GUI designer for FLTK. When run with no arguments
-or with a filename, \fIfluid\fR will display the GUI hierarchy and any windows
-defined in the file. Functions, classes, windows, and GUI components can be
+\fIfluid\fR is an interactive GUI designer for FLTK. When run
+with no arguments or with a filename, \fIfluid\fR will display
+the GUI hierarchy and any windows defined in the file.
+Functions, classes, windows, and GUI components can be
manipulated as needed.
.LP
-When used with the \fI-c\fR option, \fIfluid\fR will create the necessary C++
-header and code files in the current directory. You can override the default
-extensions, filenames, and directories using the \fI-o\fR and \fI-h\fR options.
+When used with the \fI-c\fR option, \fIfluid\fR will create the
+necessary C++ header and code files in the current directory.
+You can override the default extensions, filenames, and
+directories using the \fI-o\fR and \fI-h\fR options.
.SH SEE ALSO
-.nf
-FLTK Programming Manual, chapter 8.
-file:/usr/local/share/doc/fltk/fluid.html
-.PP
-http://www.fltk.org
-.PP
-.BR fltk (3)
-.SH AUTHOR
+fltk-config(1), fltk(3)
+.br
+FLTK Programming Manual, Chapter 9
+.br
+FLTK Web Site, http://www.fltk.org/
+.SH AUTHORS
Bill Spitzak and others.
diff --git a/documentation/opengl.html b/documentation/opengl.html
index b390e46b9..ee2a2e08f 100644
--- a/documentation/opengl.html
+++ b/documentation/opengl.html
@@ -1,35 +1,53 @@
-
-9 - Using OpenGL
- This chapter discusses using FLTK for your OpenGL applications.
+
+
+8 - Using OpenGL
+
+Using OpenGL in FLTK
-The easiest way to make an OpenGL display is to subclass
-Fl_Gl_Window. Your subclass must implement a draw()
-method which uses OpenGL calls to draw the display. Your main program
-should call redraw() when the display needs to change, and
+
+Making a Subclass of Fl_Gl_Window
-To make a subclass of Fl_Gl_Window, you must provide:
+
+
-
-If your subclass provides static controls in the window, they must be
-redrawn whenever the FL_DAMAGE_ALL bit is set in the value
-returned by damage(). For double-buffered windows you will
-need to surround the drawing code with the following code to make sure
-that both buffers are redrawn:
-
+
+
#ifndef MESA
glDrawBuffer(GL_FRONT_AND_BACK);
#endif // !MESA
@@ -37,15 +55,29 @@ glDrawBuffer(GL_FRONT_AND_BACK);
#ifndef MESA
glDrawBuffer(GL_BACK);
#endif // !MESA
-
-Note: If you are using the Mesa graphics library, the call to
-glDrawBuffer() is not required and will slow down drawing
-considerably. The preprocessor instructions shown above will optimize
-your code based upon the graphics library used.
+
+
+
+
+
+Note:
+
+
+
+Defining the Subclass
-To define the subclass you just subclass the Fl_Gl_Window class:
-
-
+
+
class MyWindow : public Fl_Gl_Window {
void draw();
int handle(int);
@@ -54,16 +86,19 @@ public:
MyWindow(int X, int Y, int W, int H, const char *L)
: Fl_Gl_Window(X, Y, W, H, L) {}
};
-
-
- The draw() and handle() methods are described below.
- Like any widget, you can include additional private and public data in
-your class (such as scene graph information, etc.)
+
+
+The draw() Method
- The draw() method is where you actually do your OpenGL
-drawing:
-
-
+
+
void MyWindow::draw() {
if (!valid()) {
... set up projection, viewport, etc ...
@@ -72,13 +107,14 @@ void MyWindow::draw() {
}
... draw ...
}
-
-
+
+
The handle() Method
- The handle() method handles mouse and keyboard events for the
-window:
-
-
+
+
int MyWindow::handle(int event) {
switch(event) {
case FL_PUSH:
@@ -108,16 +144,17 @@ int MyWindow::handle(int event) {
return Fl_Gl_Window::handle(event);
}
}
-
-
-When handle() is called, the OpenGL context is not set up!
-If your display changes, you should call redraw() and let
-draw() do the work. Don't call any OpenGL drawing functions from
-inside handle()!
+
+
+
-
+
+
case FL_PUSH:
make_current(); // make OpenGL context current
if (!valid()) {
@@ -126,155 +163,205 @@ loading functions by doing:
Your main program can now create one of your windows by doing +new MyWindow(...). You can also use FLUID by: +
You must put glwindow->show() in your main code +after calling show() on the window containing the +OpenGL window. +
Most importantly, before you show any windows (including those -that don't have OpenGL drawing) you must initialize FLTK so that it -knows it is going to use OpenGL. You may use any of the symbols -described for -Fl_Gl_Window::mode() to describe how you intend to use OpenGL:
-+ +You can put OpenGL code into an Fl_Widget::draw() +method or into the code for a boxtype or other places with some +care. + +
Most importantly, before you show any windows, +including those that don't have OpenGL drawing, you must +initialize FLTK so that it knows it is going to use OpenGL. You +may use any of the symbols described for Fl_Gl_Window::mode() +to describe how you intend to use OpenGL:
+ +
Fl::gl_visual(FL_RGB); -- -You can then put OpenGL drawing code anywhere you can draw normally by -surrounding it with: -
++ +
You can then put OpenGL drawing code anywhere you can draw +normally by surrounding it with: + +
gl_start(); ... put your OpenGL code here ... gl_finish(); -- -gl_start() and -gl_finish() set up an OpenGL context with an orthographic -projection so that 0,0 is the lower-left corner of the window and each -pixel is one unit. The current clipping is reproduced with OpenGL -glScissor() commands. These also synchronize the OpenGL graphics -stream with the drawing done by other X, WIN32, or FLTK functions. -
The same context is reused each time. If your code changes the -projection transformation or anything else you should use -glPushMatrix() and glPopMatrix() functions to put the -state back before calling gl_finish().
-You may want to use Fl_Window::current()->h() to get the -drawable height so that you can flip the Y coordinates.
-Unfortunately, there are a bunch of limitations you must adhere to -for maximum portability:
+ + +gl_start() and gl_finish() set up an OpenGL +context with an orthographic projection so that 0,0 is the +lower-left corner of the window and each pixel is one unit. The +current clipping is reproduced with OpenGL glScissor() +commands. These functions also synchronize the OpenGL graphics stream +with the drawing done by other X, WIN32, or FLTK functions. + +
The same context is reused each time. If your code changes +the projection transformation or anything else you should use +glPushMatrix() and glPopMatrix() functions to +put the state back before calling gl_finish().
+ +You may want to use Fl_Window::current()->h() to +get the drawable height so that you can flip the Y +coordinates.
+ +Unfortunately, there are a bunch of limitations you must +adhere to for maximum portability:
+Do not call gl_start() or +gl_finish() when drawing into an Fl_Gl_Window! +
FLTK provides some useful OpenGL drawing functions. They can +be freely mixed with any OpenGL calls, and are defined by +including <FL/gl.H> which you should include +instead of the OpenGL header <GL/gl.h>. +
Sets the current OpenGL color to a FLTK color. For +color-index modes it will use fl_xpixel(c), which is +only right if this window uses the default colormap! +
Outlines or fills a rectangle with the current color. If Fl_Gl_Window::ortho() has been called, then the rectangle will exactly fill the pixel rectangle passed. +
Sets the current OpenGL font to the same font you get by +calling fl_font(). +
Returns information about the current OpenGL font. +
Draws a nul-terminated string or an array of n +characters in the current OpenGL font at the current raster +position. +
Draws a nul-terminated string or an array of n +characters in the current OpenGL font at the given position. +
Draws a string formatted into a box, with newlines and tabs +expanded, other control characters changed to ^X, and aligned +with the edges or center. Exactly the same output as fl_draw().
Performance of Fl_Gl_Window may be improved on some types of +OpenGL implementations, in particular MESA and other software +emulators, by setting the GL_SWAP_TYPE environment +variable. This variable declares what is in the backbuffer after +you do a swapbuffers.
This indicates that the back buffer is copied to the front buffer, -and still contains it's old data. This is true of many hardware -implementations. Setting this will speed up emulation of -overlays, and widgets that can do partial update can take -advantage of this as damage() will not be cleared to -1. -
+
This indicates that the back buffer is copied to the + front buffer, and still contains it's old data. This is + true of many hardware implementations. Setting this + will speed up emulation of overlays, and widgets that + can do partial update can take advantage of this as + damage() will not be cleared to -1.
-
This indicates that nothing changes the back buffer except drawing -into it. This is true of MESA and Win32 software emulation and -perhaps some hardware emulation on systems with lots of memory. -
+
This indicates that nothing changes the back buffer + except drawing into it. This is true of MESA and Win32 + software emulation and perhaps some hardware emulation + on systems with lots of memory.
-
This is easily tested by running the gl_overlay demo program and -seeing if the display is correct when you drag another window over -it or if you drag the window off the screen and back on. You have to -exit and run the program again for it to see any changes to the -environment variable. +
This is easily tested by running the gl_overlay demo +program and seeing if the display is correct when you drag +another window over it or if you drag the window off the screen +and back on. You have to exit and run the program again for it +to see any changes to the environment variable.
OpenGL +Optimizer is a scene graph toolkit for OpenGL available from +Silicon Graphics for IRIX and Microsoft Windows. It allows you +to view large scenes without writing a lot of OpenGL code. +
+ +To use OpenGL Optimizer with FLTK you'll need to create a +subclass of Fl_Gl_Widget that includes several state +variables: + +
class OptimizerWindow : public Fl_Gl_Window {
csContext *context_; // Initialized to 0 and set by draw()...
csDrawAction *draw_action_; // Draw action...
@@ -303,18 +390,20 @@ public:
}
}
};
-
-
+
The camera() method sets the camera (projection and viewpoint) to use when drawing the scene. The scene is redrawn after this call. +
The draw() method performs the needed initialization and does the actual drawing: -
+ +
void OptimizerWindow::draw() {
if (!context_) {
// This is the first time we've been asked to draw; create the
@@ -353,7 +442,6 @@ void OptimizerWindow::draw() {
}
// Clear the window...
-
context_->clear(csContext::COLOR_CLEAR | csContext::DEPTH_CLEAR,
0.0f, // Red
0.0f, // Green
@@ -361,13 +449,16 @@ void OptimizerWindow::draw() {
1.0f); // Alpha
// Then draw the scene (if any)...
-
if (scene_)
draw_action_->apply(scene_);
}
-
-
+
+
The scene() method sets the scene to be drawn. The scene is a collection of 3D objects in a csGroup. The scene is redrawn -after this call. +after this call. + + + diff --git a/fltk.list.in b/fltk.list.in index 49d2a2320..6b499f937 100644 --- a/fltk.list.in +++ b/fltk.list.in @@ -1,5 +1,5 @@ # -# "$Id: fltk.list.in,v 1.1.2.2 2002/01/01 15:11:27 easysw Exp $" +# "$Id: fltk.list.in,v 1.1.2.3 2002/01/06 13:40:28 easysw Exp $" # # EPM product list file for the Fast Light Tool Kit (FLTK). # @@ -44,39 +44,57 @@ $mandir=@mandir@ $CAT1EXT=@CAT1EXT@ $CAT3EXT=@CAT3EXT@ +$DSONAME=@DSONAME@ +$GLDSONAME=@GLDSONAME@ +$GLLIBNAME=@GLLIBNAME@ + # FLUID f 0555 root sys $bindir/fluid fluid/fluid f 0555 root sys $bindir/fltk-config fltk-config # Man pages -f 0444 root sys $mandir/cat1/fluid.$CAT1EXT documentation/fluid.$CAT3EXT +f 0444 root sys $mandir/cat1/fluid.$CAT1EXT documentation/fluid.$CAT1EXT +f 0444 root sys $mandir/cat1/fltk-config.$CAT1EXT documentation/fltk-config.$CAT1EXT f 0444 root sys $mandir/cat3/fltk.$CAT3EXT documentation/fltk.$CAT3EXT f 0444 root sys $mandir/man1/fluid.1 documentation/fluid.man +f 0444 root sys $mandir/man1/fltk-config.1 documentation/fltk-config.man f 0444 root sys $mandir/man3/fltk.3 documentation/fltk.man # Library files f 0444 root sys $libdir/libfltk.a lib/libfltk.a +%if GLLIBNAME f 0444 root sys $libdir/libfltk_gl.a lib/libfltk_gl.a +%endif +%if DSONAME %system aix f 0555 root sys $libdir/libfltk_s.a src/libfltk_s.a -f 0555 root sys $libdir/libfltk_gl_s.a src/libfltk_gl_s.a %system hpux f 0555 root sys $libdir/libfltk.sl.@FL_API_VERSION@ src/libfltk.sl.@FL_API_VERSION@ l 0000 root sys $libdir/libfltk.sl libfltk.sl.@FL_API_VERSION@ -f 0555 root sys $libdir/libfltk_gl.sl.@FL_API_VERSION@ src/libfltk_gl.sl.@FL_API_VERSION@ -l 0000 root sys $libdir/libfltk_gl.sl libfltk_gl.sl.@FL_API_VERSION@ %system darwin freebsd openbsd netbsd f 0555 root sys $libdir/libfltk.dylib.@FL_API_VERSION@ src/libfltk.dylib.@FL_API_VERSION@ l 0000 root sys $libdir/libfltk.dylib libfltk.dylib.@FL_API_VERSION@ -f 0555 root sys $libdir/libfltk_gl.dylib.@FL_API_VERSION@ src/libfltk_gl.dylib.@FL_API_VERSION@ -l 0000 root sys $libdir/libfltk_gl.dylib libfltk_gl.dylib.@FL_API_VERSION@ %system !aix !darwin !freebsd !openbsd !netbsd !hpux f 0555 root sys $libdir/libfltk.so.@FL_API_VERSION@ src/libfltk.so.@FL_API_VERSION@ l 0000 root sys $libdir/libfltk.so libfltk.so.@FL_API_VERSION@ +%system all +%endif + +%if GLDSONAME +%system aix +f 0555 root sys $libdir/libfltk_gl_s.a src/libfltk_gl_s.a +%system hpux +f 0555 root sys $libdir/libfltk_gl.sl.@FL_API_VERSION@ src/libfltk_gl.sl.@FL_API_VERSION@ +l 0000 root sys $libdir/libfltk_gl.sl libfltk_gl.sl.@FL_API_VERSION@ +%system darwin freebsd openbsd netbsd +f 0555 root sys $libdir/libfltk_gl.dylib.@FL_API_VERSION@ src/libfltk_gl.dylib.@FL_API_VERSION@ +l 0000 root sys $libdir/libfltk_gl.dylib libfltk_gl.dylib.@FL_API_VERSION@ +%system !aix !darwin !freebsd !openbsd !netbsd !hpux f 0555 root sys $libdir/libfltk_gl.so.@FL_API_VERSION@ src/libfltk_gl.so.@FL_API_VERSION@ l 0000 root sys $libdir/libfltk_gl.so libfltk_gl.so.@FL_API_VERSION@ %system all +%endif # Header files f 0444 root sys $includedir/FL/ FL/*.[hH] @@ -198,5 +216,5 @@ f 0444 root sys $datadir/doc/fltk/COPYING COPYING f 0444 root sys $datadir/doc/fltk/CHANGES CHANGES # -# End of "$Id: fltk.list.in,v 1.1.2.2 2002/01/01 15:11:27 easysw Exp $". +# End of "$Id: fltk.list.in,v 1.1.2.3 2002/01/06 13:40:28 easysw Exp $". # diff --git a/fluid/Makefile b/fluid/Makefile index b5cab8eb1..2fdb28dae 100644 --- a/fluid/Makefile +++ b/fluid/Makefile @@ -1,5 +1,5 @@ # -# "$Id: Makefile,v 1.10.2.6.2.9 2002/01/01 15:11:29 easysw Exp $" +# "$Id: Makefile,v 1.10.2.6.2.10 2002/01/06 13:40:32 easysw Exp $" # # FLUID makefile for the Fast Light Tool Kit (FLTK). # @@ -69,7 +69,7 @@ install: $(PROGRAM) echo "Installing FLUID..." strip $(PROGRAM) -mkdir -p $(bindir) - cp $(PROGRAM) $(bindir)/$(PROGRAM) + cp $(PROGRAM) $(bindir) chmod 755 $(bindir)/$(PROGRAM) uninstall: @@ -87,5 +87,5 @@ rebuild: ./fluid -c widget_panel.fl # -# End of "$Id: Makefile,v 1.10.2.6.2.9 2002/01/01 15:11:29 easysw Exp $". +# End of "$Id: Makefile,v 1.10.2.6.2.10 2002/01/06 13:40:32 easysw Exp $". # diff --git a/src/Makefile b/src/Makefile index f9d16c88d..3b57a6242 100644 --- a/src/Makefile +++ b/src/Makefile @@ -1,5 +1,5 @@ # -# "$Id: Makefile,v 1.18.2.14.2.28 2002/01/01 15:11:31 easysw Exp $" +# "$Id: Makefile,v 1.18.2.14.2.29 2002/01/06 13:40:32 easysw Exp $" # # Library makefile for the Fast Light Tool Kit (FLTK). # @@ -290,30 +290,36 @@ install: $(LIBNAME) $(DSONAME) $(GLLIBNAME) $(GLDSONAME) if test x$(DSONAME) = xlibfltk.so.1.1; then\ rm -f $(libdir)/libfltk.so*;\ cp libfltk.so.1.1 $(libdir); \ + chmod 755 $(libdir)/libfltk.so.1.1; \ ln -s libfltk.so.1.1 $(libdir)/libfltk.so;\ fi if test x$(DSONAME) = xlibfltk.sl.1.1; then\ rm -f $(libdir)/libfltk.sl*;\ cp libfltk.sl.1.1 $(libdir); \ + chmod 755 $(libdir)/libfltk.sl.1.1; \ ln -s libfltk.sl.1.1 $(libdir)/libfltk.sl;\ fi if test x$(DSONAME) = xlibfltk_s.a; then\ rm -f $(libdir)/libfltk_s.a;\ cp libfltk_s.a $(libdir); \ + chmod 755 $(libdir)/libfltk_s.a; \ fi if test x$(GLDSONAME) = xlibfltk_gl.so.1.1; then\ rm -f $(libdir)/libfltk_gl.so*;\ cp libfltk_gl.so.1.1 $(libdir); \ + chmod 755 $(libdir)/libfltk_gl.so.1.1; \ ln -s libfltk_gl.so.1.1 $(libdir)/libfltk_gl.so;\ fi if test x$(GLDSONAME) = xlibfltk_gl.sl.1.1; then\ rm -f $(libdir)/libfltk_gl.sl*;\ cp libfltk_gl.sl.1.1 $(libdir); \ + chmod 755 $(libdir)/libfltk_gl.sl.1.1; \ ln -s libfltk_gl.sl.1.1 $(libdir)/libfltk_gl.sl;\ fi if test x$(GLDSONAME) = xlibfltk_gl_s.a; then\ rm -f $(libdir)/libfltk_gl_s.a;\ cp libfltk_gl_s.a $(libdir); \ + chmod 755 $(libdir)/libfltk_gl.a; \ fi @@ -344,5 +350,5 @@ uninstall: # -# End of "$Id: Makefile,v 1.18.2.14.2.28 2002/01/01 15:11:31 easysw Exp $". +# End of "$Id: Makefile,v 1.18.2.14.2.29 2002/01/06 13:40:32 easysw Exp $". # -- cgit v1.2.3