Visualization Library 2.1.0

A lightweight C++ OpenGL middleware for 2D/3D graphics

VL     Star     Watch     Fork     Issue

[Download] [Tutorials] [All Classes] [Grouped Classes]
GLUTWindow.hpp
Go to the documentation of this file.
1 /**************************************************************************************/
2 /* */
3 /* Visualization Library */
4 /* http://visualizationlibrary.org */
5 /* */
6 /* Copyright (c) 2005-2020, Michele Bosi */
7 /* All rights reserved. */
8 /* */
9 /* Redistribution and use in source and binary forms, with or without modification, */
10 /* are permitted provided that the following conditions are met: */
11 /* */
12 /* - Redistributions of source code must retain the above copyright notice, this */
13 /* list of conditions and the following disclaimer. */
14 /* */
15 /* - Redistributions in binary form must reproduce the above copyright notice, this */
16 /* list of conditions and the following disclaimer in the documentation and/or */
17 /* other materials provided with the distribution. */
18 /* */
19 /* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND */
20 /* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED */
21 /* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE */
22 /* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR */
23 /* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES */
24 /* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; */
25 /* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON */
26 /* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT */
27 /* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS */
28 /* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */
29 /* */
30 /**************************************************************************************/
31 
32 #ifndef GLUT_Window_INCLUDE_ONCE
33 #define GLUT_Window_INCLUDE_ONCE
34 
35 #include <vlGLUT/link_config.hpp>
36 #include <vlCore/Vector4.hpp>
38 #include <map>
39 #include <cstdlib> // exit()
40 #if defined(__APPLE__)
41  #include <GLUT/glut.h>
42 #else
43  #include <GL/freeglut.h>
44 #endif
45 
46 namespace vlut
47 {
48  class Applet;
49 }
50 
51 namespace vlGLUT
52 {
53 //-----------------------------------------------------------------------------
54 // GLUTWindow
55 //-----------------------------------------------------------------------------
60  {
61  public:
62  GLUTWindow();
63 
64  GLUTWindow(const vl::String& title, const vl::OpenGLContextFormat& info, int x, int y, int width, int height);
65 
67  bool initGLUTWindow(const vl::String& title, const vl::OpenGLContextFormat& info, int x, int y, int width, int height);
68 
70  {
71  destroyWindow();
72  }
73 
74  virtual void setMouseVisible(bool visible);
75 
76  virtual void setMousePosition(int x, int y);
77 
79  void quitApplication() { eraseAllEventListeners(); exit(0); }
80 
81  void update();
82 
83  bool setFullscreen(bool fs);
84 
85  void makeCurrent();
86 
87  void updateOverlay();
88 
89  void swapBuffers();
90 
91  void setWindowTitle(const vl::String& title) ;
92 
93  void setPosition(int x, int y) ;
94 
95  void setSize(int w, int h) ;
96 
97  vl::ivec2 position() const;
98 
99  vl::ivec2 size() const;
100 
101  void show();
102 
103  void hide();
104 
105  void getFocus();
106 
107  // ---
108 
109  int handle() const { return mHandle; }
110 
111  protected:
112  void destroyWindow();
113  void initKeymap();
114 
115  vl::EKey mapAsciiKey(unsigned char ascii);
116 
117  static vl::EKey mapSpecialKey(int special_key);
118 
119  void updateModifiers();
120 
121  static void glut_keyboard_func(unsigned char ch, int x, int y);
122 
123  static void glut_keyboard_up_func(unsigned char ch, int x, int y);
124 
125  static void glut_special_func(int key, int x, int y);
126 
127  static void glut_special_up_func(int key, int x, int y);
128 
129  static void glut_mouse_func(int button, int state, int x, int y);
130 
131  static void glut_motion_func(int x, int y);
132 
133  static void glut_passive_motion_func(int x, int y);
134 
135  static void glut_mouse_wheel_func(int a, int rotation, int c, int d);
136 
137  static void glut_visibility_func(int visibility);
138 
139  static void glut_reshape_func(int w, int h);
140 
141  static void glut_display_func();
142 
143  static void glut_close_func();
144 
145  static void glut_wmclose_func();
146 
147  // used for continuous update
148  static void glut_idle_func();
149 
150  // static void glut_overlay_display_func();
151 
152  // does not seem to work properly or usefully
153  // static void glut_entry_func(int leave_enter);
154 
155  // not used
156  // static void glut_timer_func(int value);
157 
158  protected:
159  std::map<unsigned char, vl::EKey> mKeymap;
160  int mHandle;
161  bool mInited;
162 
163  static std::map< int, GLUTWindow* > mWinMap;
164  };
165 
167 }
168 
169 #endif
void quitApplication()
Quits the progra calling the C function exit(0).
Definition: GLUTWindow.hpp:79
The GLUTWindow class implements an OpenGLContext using the GLUT API.
Definition: GLUTWindow.hpp:59
The String class implements an advanced UTF16 (Unicode BMP) string manipulation engine.
Definition: String.hpp:62
Represents an OpenGL context, possibly a widget or a pbuffer, which can also respond to keyboard...
The OpenGLContextFormat class encapsulates the settings of an OpenGL rendering context.
std::map< unsigned char, vl::EKey > mKeymap
Definition: GLUTWindow.hpp:159
int handle() const
Definition: GLUTWindow.hpp:109
VLGLUT_EXPORT void atexit_visualization_library_shutdown()
Definition: GLUTWindow.cpp:805
The GLUT bindings namespace.
static std::map< int, GLUTWindow *> mWinMap
Definition: GLUTWindow.hpp:163