From 09daf20b81cdae78772f07c0af22a571d7cc73eb Mon Sep 17 00:00:00 2001 From: Michael R Sweet Date: Thu, 29 Nov 2001 19:24:00 +0000 Subject: Documentation updates galore (up to chapter 7, still need to do chapter 8 and 9, tweek the appendices, and recapture the screenshots...) git-svn-id: file:///fltk/svn/fltk/branches/branch-1.1@1786 ea41ed52-d2ee-0310-a9c1-e6b18d33e121 --- documentation/opengl.html | 144 +++++++++++++++++++++++----------------------- 1 file changed, 72 insertions(+), 72 deletions(-) (limited to 'documentation/opengl.html') diff --git a/documentation/opengl.html b/documentation/opengl.html index a5336af42..b390e46b9 100644 --- a/documentation/opengl.html +++ b/documentation/opengl.html @@ -1,27 +1,27 @@

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

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.

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: - 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:

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: -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()! -

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:

-Your main program can now create one of your windows by doing new +Your main program can now create one of your windows by doing new MyWindow(...). You can also use FLUID -by: +by:
  1. Putting your class definition in a MyWindow.H file.
  2. Creating a Fl_Box widget in FLUID.
  3. -
  4. In the widget panel fill in the "class" field with MyWindow. +
  5. In the widget panel fill in the "class" field with MyWindow. This will make FLUID produce constructors for your new class.
  6. -
  7. In the "Extra Code" field put #include "MyWindow.H", so that +
  8. In the "Extra Code" field put #include "MyWindow.H", so that the FLUID output file will compile.
You must put glwindow->show() in your main code after calling -show() on the window containing the OpenGL window. +show()
on the window containing the OpenGL window.

Using OpenGL in Normal FLTK Windows

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 +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:

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

-Do not call gl_start() or gl_finish() when +Do not call gl_start() or gl_finish() when drawing into an Fl_Gl_Window!

OpenGL Drawing Functions

-FLTK provides some useful OpenGL drawing functions. They can be +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>). +<GL/gl.h>).

void gl_color(Fl_Color)

-Set the current color to a FLTK color. For color-index modes -it will use fl_xpixel(c), which is only right if this window +Set the current 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!

void gl_rect(int x, int y, int w, int h)
void gl_rectf(int x, int y, int w, int h)

Outline or fill a rectangle with the current color. If
Fl_Gl_Window::ortho() -has been called, then the rectangle will exactly fill the pixel -rectangle passed. +has been called, then the rectangle will exactly fill the pixel +rectangle passed.

void gl_font(Fl_Font fontid, int size)

Set the current OpenGL font to the same font you get by calling -fl_font(). +fl_font().

int gl_height()
int gl_descent()
float gl_width(const char *)
float gl_width(const char *, int n)
float gl_width(uchar)

- Return information about the current OpenGL font. + Return information about the current OpenGL font.

void gl_draw(const char *)
void gl_draw(const char *, int n)

-Draw a nul-terminated string or an array of n characters in +Draw a nul-terminated string or an array of n characters in the current OpenGL font at the current raster position.

void gl_draw(const char *, int x, int y)
void gl_draw(const char *, int n, int x, int y)
void gl_draw(const char *, float x, float y)
void gl_draw(const char *, int n, float x, float y)

- Draw a nul-terminated string or an array of n characters in -the current OpenGL font at the given position. + Draw a nul-terminated string or an array of n characters in +the current OpenGL font at the given position.

void gl_draw(const char *, int x, int y, int w, int h, Fl_Align)

- Draw a string formatted into a box, with newlines and tabs expanded, -other control characters changed to ^X, and aligned with the edges or + Draw 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() -. +.

Speeding up OpenGL

@@ -265,14 +265,14 @@ exit and run the program again for it to see any changes to the environment variable.

Using OpenGL Optimizer with FLTK

-OpenGL Optimizer is a -scene graph toolkit for OpenGL available from Silicon Graphics for IRIX -and Microsoft Windows. Versions are in the works for Solaris and -HP-UX. It allows you to view large scenes without writing a lot of -OpenGL code. +OpenGL Optimizer is a +scene graph toolkit for OpenGL available from Silicon Graphics for IRIX +and Microsoft Windows. Versions are in the works for Solaris and +HP-UX. It allows you to view large scenes without writing a lot of +OpenGL code.

OptimizerWindow Class Definition

To use OpenGL Optimizer with FLTK you'll need to create a subclass of -Fl_Gl_Widget that includes several state variables: +Fl_Gl_Widget that includes several state variables:

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:

The scene() Method

- The scene() method sets the scene to be drawn. The scene is -a collection of 3D objects in a csGroup. The scene is redrawn + 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. -- cgit v1.2.3