fltk 1.3.0rc3
About: FLTK (Fast Light Tool Kit) is a cross-platform C++ GUI toolkit for UNIX/Linux (X11), Microsoft Windows, and MacOS X. Release candidate.
  SfR Fresh Dox: fltk-1.3.0rc3-source.tar.gz ("inofficial" and yet experimental doxygen-generated source code documentation)  

Fl_Gl_Window Class Reference

#include <Fl_Gl_Window.H>

Inheritance diagram for Fl_Gl_Window:
Collaboration diagram for Fl_Gl_Window:

List of all members.

Public Member Functions

void show ()
void show (int a, char **b)
void flush ()
void hide ()
void resize (int, int, int, int)
int handle (int)
char valid () const
void valid (char v)
void invalidate ()
char context_valid () const
void context_valid (char v)
int can_do ()
Fl_Mode mode () const
int mode (int a)
int mode (const int *a)
void * context () const
void context (void *, int destroy_flag=0)
void make_current ()
void swap_buffers ()
void ortho ()
int can_do_overlay ()
void redraw_overlay ()
void hide_overlay ()
void make_overlay_current ()
virtual Fl_Gl_Windowas_gl_window ()
 ~Fl_Gl_Window ()
 Fl_Gl_Window (int W, int H, const char *l=0)
 Fl_Gl_Window (int X, int Y, int W, int H, const char *l=0)

Static Public Member Functions

static int can_do (int m)
static int can_do (const int *m)

Protected Member Functions

virtual void draw ()

Friends

class _Fl_Gl_Overlay

Detailed Description

The Fl_Gl_Window widget sets things up so OpenGL works.

It also keeps an OpenGL "context" for that window, so that changes to the lighting and projection may be reused between redraws. Fl_Gl_Window also flushes the OpenGL streams and swaps buffers after draw() returns.

OpenGL hardware typically provides some overlay bit planes, which are very useful for drawing UI controls atop your 3D graphics. If the overlay hardware is not provided, FLTK tries to simulate the overlay. This works pretty well if your graphics are double buffered, but not very well for single-buffered.

Please note that the FLTK drawing and clipping functions will not work inside an Fl_Gl_Window. All drawing should be done using OpenGL calls exclusively. Even though Fl_Gl_Window is derived from Fl_Group, it is not useful to add other FLTK Widgets as children, unless those widgets are modified to draw using OpenGL calls.

Definition at line 65 of file Fl_Gl_Window.H.


Constructor & Destructor Documentation

Fl_Gl_Window::~Fl_Gl_Window ( )
Fl_Gl_Window::Fl_Gl_Window ( int  W,
int  H,
const char *  l = 0 
) [inline]

Creates a new Fl_Gl_Window widget using the given size, and label string. The default boxtype is FL_NO_BOX. The default mode is FL_RGB|FL_DOUBLE|FL_DEPTH.

Definition at line 217 of file Fl_Gl_Window.H.

Fl_Gl_Window::Fl_Gl_Window ( int  X,
int  Y,
int  W,
int  H,
const char *  l = 0 
) [inline]

Creates a new Fl_Gl_Window widget using the given position, size, and label string. The default boxtype is FL_NO_BOX. The default mode is FL_RGB|FL_DOUBLE|FL_DEPTH.

Definition at line 224 of file Fl_Gl_Window.H.


Member Function Documentation

virtual Fl_Gl_Window* Fl_Gl_Window::as_gl_window ( ) [inline, virtual]

Returns an Fl_Gl_Window pointer if this widget is an Fl_Gl_Window.

Use this method if you have a widget (pointer) and need to know whether this widget is derived from Fl_Gl_Window. If it returns non-NULL, then the widget in question is derived from Fl_Gl_Window.

Return values:
NULLif this widget is not derived from Fl_Gl_Window.
Note:
This method is provided to avoid dynamic_cast.
See also:
Fl_Widget::as_group(), Fl_Widget::as_window()

Reimplemented from Fl_Widget.

Definition at line 210 of file Fl_Gl_Window.H.

static int Fl_Gl_Window::can_do ( int  m) [inline, static]

Returns non-zero if the hardware supports the given or current OpenGL mode.

Definition at line 136 of file Fl_Gl_Window.H.

References can_do().

Referenced by can_do().

static int Fl_Gl_Window::can_do ( const int *  m) [inline, static]

Returns non-zero if the hardware supports the given or current OpenGL mode.

Definition at line 138 of file Fl_Gl_Window.H.

References can_do().

Referenced by can_do().

int Fl_Gl_Window::can_do ( ) [inline]

Returns non-zero if the hardware supports the given or current OpenGL mode.

Definition at line 140 of file Fl_Gl_Window.H.

References can_do().

Referenced by can_do().

int Fl_Gl_Window::can_do_overlay ( )

Returns true if the hardware overlay is possible. If this is false, FLTK will try to simulate the overlay, with significant loss of update speed. Calling this will cause FLTK to open the display.

void Fl_Gl_Window::context ( void *  ,
int  destroy_flag = 0 
)
void* Fl_Gl_Window::context ( ) const [inline]

void See void context(void* v, int destroy_flag)

Definition at line 180 of file Fl_Gl_Window.H.

Referenced by handle().

void Fl_Gl_Window::context_valid ( char  v) [inline]

See char Fl_Gl_Window::context_valid() const

Definition at line 133 of file Fl_Gl_Window.H.

char Fl_Gl_Window::context_valid ( ) const [inline]

Will only be set if the OpenGL context is created or recreated. It differs from Fl_Gl_Window::valid() which is also set whenever the context changes size.

Definition at line 129 of file Fl_Gl_Window.H.

void Fl_Gl_Window::draw ( void  ) [protected, virtual]

Draws the Fl_Gl_Window.

You must override the draw() method.

You must subclass Fl_Gl_Window and provide an implementation for draw(). You may also provide an implementation of draw_overlay() if you want to draw into the overlay planes. You can avoid reinitializing the viewport and lights and other things by checking valid() at the start of draw() and only doing the initialization if it is false.

The draw() method can only use OpenGL calls. Do not attempt to call X, any of the functions in <FL/fl_draw.H>, or glX directly. Do not call gl_start() or gl_finish().

If double-buffering is enabled in the window, the back and front buffers are swapped after this function is completed.

Reimplemented from Fl_Window.

Reimplemented in Fl_Glut_Window.

Definition at line 527 of file Fl_Gl_Window.cxx.

References Fl::fatal.

void Fl_Gl_Window::flush ( ) [virtual]

Forces the window to be drawn, this window is also made current and calls draw().

Reimplemented from Fl_Window.

int Fl_Gl_Window::handle ( int  event) [virtual]

Handle some FLTK events as needed.

Reimplemented from Fl_Window.

Reimplemented in Fl_Glut_Window.

Definition at line 535 of file Fl_Gl_Window.cxx.

References context(), FL_HIDE, FL_SHOW, show(), and Fl_Widget::visible_r().

void Fl_Gl_Window::hide ( ) [virtual]

Removes the window from the screen. If the window is already hidden or has not been shown then this does nothing and is harmless.

Reimplemented from Fl_Window.

Referenced by glutHideWindow().

void Fl_Gl_Window::hide_overlay ( )
void Fl_Gl_Window::invalidate ( )
void Fl_Gl_Window::make_current ( )

Sets things up so that the drawing functions in <FL/fl_draw.H> will go into this window. This is useful for incremental update of windows, such as in an idle callback, which will make your program behave much better if it draws a slow graphic. Danger: incremental update is very hard to debug and maintain!

This method only works for the Fl_Window and Fl_Gl_Window derived classes.

make all drawing go into this window (called by subclass flush() impl.)

Reimplemented from Fl_Window.

Reimplemented in Fl_Glut_Window.

void Fl_Gl_Window::make_overlay_current ( )

The make_overlay_current() method selects the OpenGL context for the widget's overlay. It is called automatically prior to the draw_overlay() method being called and can also be used to implement feedback and/or selection within the handle() method.

Referenced by glutEstablishOverlay(), and glutUseLayer().

int Fl_Gl_Window::mode ( const int *  a) [inline]

See Fl_Mode mode() const

Definition at line 178 of file Fl_Gl_Window.H.

References mode().

Referenced by mode().

int Fl_Gl_Window::mode ( int  a) [inline]

See Fl_Mode mode() const

Definition at line 176 of file Fl_Gl_Window.H.

References mode().

Referenced by mode().

Fl_Mode Fl_Gl_Window::mode ( ) const [inline]

Set or change the OpenGL capabilites of the window. The value can be any of the following OR'd together:

  • FL_RGB - RGB color (not indexed)
  • FL_RGB8 - RGB color with at least 8 bits of each color
  • FL_INDEX - Indexed mode
  • FL_SINGLE - not double buffered
  • FL_DOUBLE - double buffered
  • FL_ACCUM - accumulation buffer
  • FL_ALPHA - alpha channel in color
  • FL_DEPTH - depth buffer
  • FL_STENCIL - stencil buffer
  • FL_MULTISAMPLE - multisample antialiasing

FL_RGB and FL_SINGLE have a value of zero, so they are "on" unless you give FL_INDEX or FL_DOUBLE.

If the desired combination cannot be done, FLTK will try turning off FL_MULTISAMPLE. If this also fails the show() will call Fl::error() and not show the window.

You can change the mode while the window is displayed. This is most useful for turning double-buffering on and off. Under X this will cause the old X window to be destroyed and a new one to be created. If this is a top-level window this will unfortunately also cause the window to blink, raise to the top, and be de-iconized, and the xid() will change, possibly breaking other code. It is best to make the GL window a child of another window if you wish to do this!

mode() must not be called within draw() since it changes the current context.

Definition at line 174 of file Fl_Gl_Window.H.

void Fl_Gl_Window::ortho ( )
void Fl_Gl_Window::redraw_overlay ( )

This method causes draw_overlay() to be called at a later time. Initially the overlay is clear. If you want the window to display something in the overlay when it first appears, you must call this immediately after you show() your window.

Referenced by glutPostOverlayRedisplay(), and glutShowOverlay().

void Fl_Gl_Window::resize ( int  X,
int  Y,
int  W,
int  H 
) [virtual]

Changes the size and position of the window. If shown() is true, these changes are communicated to the window server (which may refuse that size and cause a further resize). If shown() is false, the size and position are used when show() is called. See Fl_Group for the effect of resizing on the child widgets.

You can also call the Fl_Widget methods size(x,y) and position(w,h), which are inline wrappers for this virtual function.

A top-level window can not force, but merely suggest a position and size to the operating system. The window manager may not be willing or able to display a window at the desired position or with the given dimensions. It is up to the application developer to verify window parameters after the resize request.

resize a window

Reimplemented from Fl_Window.

void Fl_Gl_Window::show ( ) [virtual]

Puts the window on the screen. Usually (on X) this has the side effect of opening the display.

If the window is already shown then it is restored and raised to the top. This is really convenient because your program can call show() at any time, even if the window is already up. It also means that show() serves the purpose of raise() in other toolkits.

Fl_Window::show(int argc, char **argv) is used for top-level windows and allows standard arguments to be parsed from the command-line.

See also:
Fl_Window::show(int argc, char **argv)

make a window visible

Reimplemented from Fl_Window.

Referenced by glutPopWindow(), glutShowWindow(), and handle().

void Fl_Gl_Window::show ( int  argc,
char **  argv 
) [inline]

Puts the window on the screen and parses command-line arguments.

Usually (on X) this has the side effect of opening the display.

This form should be used for top-level windows, at least for the first (main) window. It allows standard arguments to be parsed from the command-line. You can use argc and argv from main(int argc, char **argv) for this call.

The first call also sets up some system-specific internal variables like the system colors.

Todo:
explain which system parameters are set up.
Parameters:
argccommand-line argument count, usually from main()
argvcommand-line argument vector, usually from main()
See also:
virtual void Fl_Window::show()

Reimplemented from Fl_Window.

Definition at line 86 of file Fl_Gl_Window.H.

References Fl_Window::show().

void Fl_Gl_Window::swap_buffers ( )
char Fl_Gl_Window::valid ( ) const [inline]

Is turned off when FLTK creates a new context for this window or when the window resizes, and is turned on after draw() is called. You can use this inside your draw() method to avoid unnecessarily initializing the OpenGL context. Just do this:

    void mywindow::draw() {
     if (!valid()) {
       glViewport(0,0,w(),h());
       glFrustum(...);
       ...other initialization...
     }
     if (!context_valid()) {
       ...load textures, etc. ...
     }
     ... draw your geometry here ...
    }

You can turn valid() on by calling valid(1). You should only do this after fixing the transformation inside a draw() or after make_current(). This is done automatically after draw() returns.

Definition at line 116 of file Fl_Gl_Window.H.

void Fl_Gl_Window::valid ( char  v) [inline]

See char Fl_Gl_Window::valid() const

Definition at line 120 of file Fl_Gl_Window.H.


Friends And Related Function Documentation

friend class _Fl_Gl_Overlay [friend]

Definition at line 78 of file Fl_Gl_Window.H.


The documentation for this class was generated from the following files: