From 09daf20b81cdae78772f07c0af22a571d7cc73eb Mon Sep 17 00:00:00 2001
From: Michael R Sweet With a bit of care you can also use OpenGL to draw into normal FLTK
-windows. This allows you to use Gouraud shading for
+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
+ 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. You can call some OpenGL stuff like hit detection and texture
+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: 9 - Using OpenGL
- This chapter discusses using FLTK for your OpenGL applications.
+ This chapter discusses using FLTK for your OpenGL applications.
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
-(somewhat later) FLTK will call draw().
-Making a Subclass of Fl_Gl_Window
-To make a subclass of Fl_Gl_Window, you must provide:
+To make a subclass of Fl_Gl_Window, you must provide:
If your subclass provides static controls in the window, they must be
@@ -43,7 +43,7 @@ glDrawBuffer(GL_BACK);
considerably. The preprocessor instructions shown above will optimize
your code based upon the graphics library used.
Defining the Subclass
-To define the subclass you just subclass the Fl_Gl_Window class:
+To define the subclass you just subclass the Fl_Gl_Window class:
class MyWindow : public Fl_Gl_Window {
@@ -56,12 +56,12 @@ public:
};
- 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() 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:
+ The draw() method is where you actually do your OpenGL
+drawing:
void MyWindow::draw() {
@@ -75,8 +75,8 @@ void MyWindow::draw() {
The handle() Method
- The handle() method handles mouse and keyboard events for the
-window:
+ The handle() method handles mouse and keyboard events for the
+window:
int MyWindow::handle(int event) {
@@ -88,7 +88,7 @@ int MyWindow::handle(int event) {
case FL_DRAG:
... mouse moved while down event ...
return 1;
- case FL_RELEASE:
+ case FL_RELEASE:
... mouse up event ...
return 1;
case FL_FOCUS :
@@ -110,11 +110,11 @@ int MyWindow::handle(int event) {
}
-When handle() is called, the OpenGL context is not set up!
+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()!
-
@@ -128,26 +128,26 @@ loading functions by doing:
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 +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:
gl_start(); @@ -165,18 +165,18 @@ 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 +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 +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 +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 +
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 +
Unfortunately, there are a bunch of limitations you must adhere to for maximum portability:
class OptimizerWindow : public Fl_Gl_Window {
@@ -307,12 +307,12 @@ public:
The camera() Method
- The camera() method sets the camera (projection and
-viewpoint) to use when drawing the scene. The scene is redrawn after
-this call.
+ 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
- The draw() method performs the needed initialization and does
-the actual drawing:
+ The draw() method performs the needed initialization and does
+the actual drawing:
void OptimizerWindow::draw() {
@@ -330,7 +330,7 @@ void OptimizerWindow::draw() {
context_->makeCurrent(fl_display, fl_window);
#endif // WIN32
- ... perform other context setup as desired ...
+ ... perform other context setup as desired ...
// Then create the draw action to handle drawing things...
@@ -368,6 +368,6 @@ void OptimizerWindow::draw() {