FLTK
Fl_Gl_Window.H
1 //
2 // OpenGL header file for the Fast Light Tool Kit (FLTK).
3 //
4 // Copyright 1998-2016 by Bill Spitzak and others.
5 //
6 // This library is free software. Distribution and use rights are outlined in
7 // the file "COPYING" which should have been included with this file. If this
8 // file is missing or damaged, see the license at:
9 //
10 // https://www.fltk.org/COPYING.php
11 //
12 // Please see the following page on how to report bugs and issues:
13 //
14 // https://www.fltk.org/bugs.php
15 //
16 
17 /* \file
18  Fl_Gl_Window widget . */
19 
20 #ifndef Fl_Gl_Window_H
21 #define Fl_Gl_Window_H
22 
23 #include "Fl_Window.H"
24 
25 class Fl_Gl_Choice; // structure to hold result of glXChooseVisual
26 class Fl_Gl_Window_Driver;
51 class FL_EXPORT Fl_Gl_Window : public Fl_Window {
52  friend class Fl_Gl_Window_Driver;
53  Fl_Gl_Window_Driver *pGlWindowDriver;
54 
55  int mode_;
56  const int *alist;
57  Fl_Gl_Choice *g;
58  GLContext context_;
59  char valid_f_;
60  char damage1_; // damage() of back buffer
61  virtual void draw_overlay();
62  void init();
63 
64  void *overlay;
65 
66  static int can_do(int, const int *);
67  int mode(int, const int *);
68  static int gl_plugin_linkage();
69 protected:
70  virtual void draw();
71 
72 public:
73  void show();
75  void show(int a, char **b) {Fl_Window::show(a,b);}
76  void flush();
77  void hide();
78  void resize(int,int,int,int);
79  int handle(int);
81  Fl_Gl_Window_Driver *gl_driver() {return pGlWindowDriver;}
82 
107  char valid() const {return valid_f_ & 1;}
111  void valid(char v) {if (v) valid_f_ |= 1; else valid_f_ &= 0xfe;}
112  void invalidate();
113 
120  char context_valid() const {return valid_f_ & 2;}
124  void context_valid(char v) {if (v) valid_f_ |= 2; else valid_f_ &= 0xfd;}
125 
127  static int can_do(int m) {return can_do(m,0);}
130  static int can_do(const int *m) {return can_do(0, m);}
132  int can_do() {return can_do(mode_,alist);}
136  Fl_Mode mode() const {return (Fl_Mode)mode_;}
177  int mode(int a) {return mode(a,0);}
189  int mode(const int *a) {return mode(0, a);}
192  GLContext context() const {return context_;}
193  void context(GLContext, int destroy_flag = 0);
194  void make_current();
195  void swap_buffers();
196  void ortho();
197 
198  int can_do_overlay();
199  void redraw_overlay();
200  void hide_overlay();
201  void make_overlay_current();
202 
203  // Note: Doxygen docs in Fl_Widget.H to avoid redundancy.
204  virtual Fl_Gl_Window* as_gl_window() {return this;}
205 
206  float pixels_per_unit();
216  int pixel_w() { return int(pixels_per_unit() * w() + 0.5f); }
226  int pixel_h() { return int(pixels_per_unit() * h() + 0.5f); }
227 
228  ~Fl_Gl_Window();
233  Fl_Gl_Window(int W, int H, const char *l=0) : Fl_Window(W,H,l) {init();}
240  Fl_Gl_Window(int X, int Y, int W, int H, const char *l=0)
241  : Fl_Window(X,Y,W,H,l) {init();}
242 };
243 
244 #endif // Fl_Gl_Window_H
opaque GLContext
an OpenGL graphics context, into which all OpenGL calls are rendered
Definition: platform_types.h:39
virtual Fl_Gl_Window * as_gl_window()
Returns an Fl_Gl_Window pointer if this widget is an Fl_Gl_Window.
Definition: Fl_Gl_Window.H:204
This widget produces an actual window.
Definition: Fl_Window.H:53
int h() const
Gets the widget height.
Definition: Fl_Widget.H:286
void draw()
Draws the widget.
Definition: Fl_Window.cxx:482
GLContext context() const
Returns a pointer to the GLContext that this window is using.
Definition: Fl_Gl_Window.H:192
int mode(int a)
Set or change the OpenGL capabilites of the window.
Definition: Fl_Gl_Window.H:177
static int can_do(const int *m)
Returns non-zero if the hardware supports the given OpenGL mode.
Definition: Fl_Gl_Window.H:130
Fl_Gl_Window(int X, int Y, int W, int H, const char *l=0)
Creates a new Fl_Gl_Window widget using the given position, size, and label string.
Definition: Fl_Gl_Window.H:240
virtual void resize(int X, int Y, int W, int H)
Changes the size and position of the window.
Definition: Fl_Window.cxx:545
Fl_Mode
visual types and Fl_Gl_Window::mode() (values match Glut)
Definition: Enumerations.H:1192
virtual int handle(int)
Handles the specified event.
Definition: Fl_Window.cxx:561
char valid() const
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.
Definition: Fl_Gl_Window.H:107
virtual void show()
Puts the window on the screen.
Definition: Fl_Window.cxx:533
int pixel_h()
Gives the window height in OpenGL pixels.
Definition: Fl_Gl_Window.H:226
void show(int a, char **b)
Same as Fl_Window::show(int a, char **b)
Definition: Fl_Gl_Window.H:75
int can_do()
Returns non-zero if the hardware supports the current OpenGL mode.
Definition: Fl_Gl_Window.H:132
Fl_Window widget .
Definition: Fl_Gl_Choice.H:70
Fl_Gl_Window_Driver * gl_driver()
Returns a pointer to the window's Fl_Gl_Window_Driver object.
Definition: Fl_Gl_Window.H:81
Fl_Gl_Window(int W, int H, const char *l=0)
Creates a new Fl_Gl_Window widget using the given size, and label string.
Definition: Fl_Gl_Window.H:233
void make_current()
Sets things up so that the drawing functions in <FL/fl_draw.H> will go into this window.
Definition: Fl_Window.cxx:521
The Fl_Gl_Window widget sets things up so OpenGL works.
Definition: Fl_Gl_Window.H:51
int mode(const int *a)
Set the OpenGL capabilites of the window using platform-specific data.
Definition: Fl_Gl_Window.H:189
void context_valid(char v)
See char Fl_Gl_Window::context_valid() const.
Definition: Fl_Gl_Window.H:124
virtual void flush()
Forces the window to be drawn, this window is also made current and calls draw(). ...
Definition: Fl_Window.cxx:472
static int can_do(int m)
Returns non-zero if the hardware supports the given OpenGL mode.
Definition: Fl_Gl_Window.H:127
int pixel_w()
Gives the window width in OpenGL pixels.
Definition: Fl_Gl_Window.H:216
Fl_Mode mode() const
Returns the current OpenGL capabilites of the window.
Definition: Fl_Gl_Window.H:136
int w() const
Gets the widget width.
Definition: Fl_Widget.H:281
char context_valid() const
Will only be set if the OpenGL context is created or recreated.
Definition: Fl_Gl_Window.H:120
void valid(char v)
See char Fl_Gl_Window::valid() const.
Definition: Fl_Gl_Window.H:111
virtual void hide()
Removes the window from the screen.
Definition: Fl_Window.cxx:549