Cafu Engine
OpenGLWindow.hpp
1 /*
2 Cafu Engine, http://www.cafu.de/
3 Copyright (c) Carsten Fuchs and other contributors.
4 This project is licensed under the terms of the MIT license.
5 */
6 
7 #ifndef CAFU_OPENGL_WINDOW_HPP_INCLUDED
8 #define CAFU_OPENGL_WINDOW_HPP_INCLUDED
9 
10 #if defined(_WIN32) && _MSC_VER<1600
11 #include "pstdint.h" // Paul Hsieh's portable implementation of the stdint.h header.
12 #else
13 #include <stdint.h>
14 #endif
15 
16 #include <string>
17 
18 
19 /// This struct describes a keyboard event.
21 {
22  /// This enum describes the type of the key event.
23  enum TypeT
24  {
25  CKE_KEYDOWN,
26  CKE_CHAR,
27  CKE_KEYUP
28  };
29 
30  /// This enum describes a key in a key event.
31  enum KeyT
32  {
33  CK_ESCAPE =0x01,
34  CK_1 =0x02,
35  CK_2 =0x03,
36  CK_3 =0x04,
37  CK_4 =0x05,
38  CK_5 =0x06,
39  CK_6 =0x07,
40  CK_7 =0x08,
41  CK_8 =0x09,
42  CK_9 =0x0A,
43  CK_0 =0x0B,
44  CK_MINUS =0x0C, ///< \- on main keyboard
45  CK_EQUALS =0x0D,
46  CK_BACKSPACE =0x0E, ///< Backspace
47  CK_TAB =0x0F,
48  CK_Q =0x10,
49  CK_W =0x11,
50  CK_E =0x12,
51  CK_R =0x13,
52  CK_T =0x14,
53  CK_Y =0x15,
54  CK_U =0x16,
55  CK_I =0x17,
56  CK_O =0x18,
57  CK_P =0x19,
58  CK_LBRACKET =0x1A,
59  CK_RBRACKET =0x1B,
60  CK_RETURN =0x1C, ///< Enter on main keyboard
61  CK_LCONTROL =0x1D,
62  CK_A =0x1E,
63  CK_S =0x1F,
64  CK_D =0x20,
65  CK_F =0x21,
66  CK_G =0x22,
67  CK_H =0x23,
68  CK_J =0x24,
69  CK_K =0x25,
70  CK_L =0x26,
71  CK_SEMICOLON =0x27,
72  CK_APOSTROPHE =0x28,
73  CK_GRAVE =0x29, ///< Accent Grave
74  CK_LSHIFT =0x2A,
75  CK_BACKSLASH =0x2B,
76  CK_Z =0x2C,
77  CK_X =0x2D,
78  CK_C =0x2E,
79  CK_V =0x2F,
80  CK_B =0x30,
81  CK_N =0x31,
82  CK_M =0x32,
83  CK_COMMA =0x33,
84  CK_PERIOD =0x34, ///< . on main keyboard
85  CK_SLASH =0x35, ///< / on main keyboard
86  CK_RSHIFT =0x36,
87  CK_MULTIPLY =0x37, ///< * on numeric keypad
88  CK_LMENU =0x38, ///< left Alt
89  CK_SPACE =0x39,
90  CK_CAPITAL =0x3A,
91  CK_F1 =0x3B,
92  CK_F2 =0x3C,
93  CK_F3 =0x3D,
94  CK_F4 =0x3E,
95  CK_F5 =0x3F,
96  CK_F6 =0x40,
97  CK_F7 =0x41,
98  CK_F8 =0x42,
99  CK_F9 =0x43,
100  CK_F10 =0x44,
101  CK_NUMLOCK =0x45,
102  CK_SCROLL =0x46, ///< Scroll Lock
103  CK_NUMPAD7 =0x47,
104  CK_NUMPAD8 =0x48,
105  CK_NUMPAD9 =0x49,
106  CK_SUBTRACT =0x4A, ///< \- on numeric keypad
107  CK_NUMPAD4 =0x4B,
108  CK_NUMPAD5 =0x4C,
109  CK_NUMPAD6 =0x4D,
110  CK_ADD =0x4E, ///< + on numeric keypad
111  CK_NUMPAD1 =0x4F,
112  CK_NUMPAD2 =0x50,
113  CK_NUMPAD3 =0x51,
114  CK_NUMPAD0 =0x52,
115  CK_DECIMAL =0x53, ///< . on numeric keypad
116  CK_OEM_102 =0x56, ///< < > | on UK/Germany keyboards
117  CK_F11 =0x57,
118  CK_F12 =0x58,
119  CK_F13 =0x64, ///< (NEC PC98)
120  CK_F14 =0x65, ///< (NEC PC98)
121  CK_F15 =0x66, ///< (NEC PC98)
122  CK_KANA =0x70, ///< (Japanese keyboard)
123  CK_ABNT_C1 =0x73, ///< / ? on Portugese (Brazilian) keyboards
124  CK_CONVERT =0x79, ///< (Japanese keyboard)
125  CK_NOCONVERT =0x7B, ///< (Japanese keyboard)
126  CK_YEN =0x7D, ///< (Japanese keyboard)
127  CK_ABNT_C2 =0x7E, ///< Numpad . on Portugese (Brazilian) keyboards
128  CK_NUMPADEQUALS=0x8D, ///< = on numeric keypad (NEC PC98)
129  CK_PREVTRACK =0x90, ///< Previous Track (DIK_CIRCUMFLEX on Japanese keyboard)
130  CK_AT =0x91, ///< (NEC PC98)
131  CK_COLON =0x92, ///< (NEC PC98)
132  CK_UNDERLINE =0x93, ///< (NEC PC98)
133  CK_KANJI =0x94, ///< (Japanese keyboard)
134  CK_STOP =0x95, ///< (NEC PC98)
135  CK_AX =0x96, ///< (Japan AX)
136  CK_UNLABELED =0x97, ///< (J3100)
137  CK_NEXTTRACK =0x99, ///< Next Track
138  CK_NUMPADENTER =0x9C, ///< Enter on numeric keypad
139  CK_RCONTROL =0x9D,
140  CK_MUTE =0xA0, ///< Mute
141  CK_CALCULATOR =0xA1, ///< Calculator
142  CK_PLAYPAUSE =0xA2, ///< Play / Pause
143  CK_MEDIASTOP =0xA4, ///< Media Stop
144  CK_VOLUMEDOWN =0xAE, ///< Volume -
145  CK_VOLUMEUP =0xB0, ///< Volume +
146  CK_WEBHOME =0xB2, ///< Web home
147  CK_NUMPADCOMMA =0xB3, ///< , on numeric keypad (NEC PC98)
148  CK_DIVIDE =0xB5, ///< / on numeric keypad
149  CK_SYSRQ =0xB7,
150  CK_RMENU =0xB8, ///< right Alt
151  CK_PAUSE =0xC5, ///< Pause
152  CK_HOME =0xC7, ///< Home on arrow keypad
153  CK_UP =0xC8, ///< UpArrow on arrow keypad
154  CK_PGUP =0xC9, ///< PgUp on arrow keypad
155  CK_LEFT =0xCB, ///< LeftArrow on arrow keypad
156  CK_RIGHT =0xCD, ///< RightArrow on arrow keypad
157  CK_END =0xCF, ///< End on arrow keypad
158  CK_DOWN =0xD0, ///< DownArrow on arrow keypad
159  CK_PGDN =0xD1, ///< PgDn on arrow keypad
160  CK_INSERT =0xD2, ///< Insert on arrow keypad
161  CK_DELETE =0xD3, ///< Delete on arrow keypad
162  CK_LWIN =0xDB, ///< Left Windows key
163  CK_RWIN =0xDC, ///< Right Windows key
164  CK_APPS =0xDD, ///< AppMenu key
165  CK_POWER =0xDE, ///< System Power
166  CK_SLEEP =0xDF, ///< System Sleep
167  CK_WAKE =0xE3, ///< System Wake
168  CK_WEBSEARCH =0xE5, ///< Web Search
169  CK_WEBFAVORITES=0xE6, ///< Web Favorites
170  CK_WEBREFRESH =0xE7, ///< Web Refresh
171  CK_WEBSTOP =0xE8, ///< Web Stop
172  CK_WEBFORWARD =0xE9, ///< Web Forward
173  CK_WEBBACK =0xEA, ///< Web Back
174  CK_MYCOMPUTER =0xEB, ///< My Computer
175  CK_MAIL =0xEC, ///< Mail
176  CK_MEDIASELECT =0xED, ///< Media Select
177  };
178 
179  TypeT Type; ///< The type of this keyboard event.
180  int Key; ///< If Type is one of CKE_KEYDOWN or CKE_KEYUP, this is one of the CK_* keys from the KeyT enum. If Type is CKE_CHAR instead, this is the (ASCII) character code of the key.
181 };
182 
183 
184 /// This struct describes a mouse event.
186 {
187  /// This enum describes the type of the mouse event.
188  enum TypeT
189  {
190  CM_BUTTON0= 0,
191  CM_BUTTON1= 1,
192  CM_BUTTON2= 2,
193  CM_BUTTON3= 3,
194  CM_MOVE_X =200,
195  CM_MOVE_Y =201,
196  CM_MOVE_Z =202, ///< The mouse wheel.
197  };
198 
199  TypeT Type; ///< The type of the mouse event.
200  int Amount; ///< The amount.
201 };
202 
203 
205 {
206  public:
207 
208  /// Virtual destructor, so that deleting this class through derived-class pointers works right.
209  virtual ~SingleOpenGLWindowT() {}
210 
211  /// This functions opens a new OpenGL window. Only one window can be open at one time.
212  /// Returns 'NULL' on success, or a string with the reason for the failure.
213  /// The global variables are initialized on success, and undefined otherwise.
214  /// Notes:
215  /// a) An 8 BPP stencil buffer is always requested.
216  /// b) The far clip plane is always located at infinity, in order to facilitate stencil shadows (and arbitrary large levels :-).
217  virtual const char* Open(const std::string& Title_, unsigned int Width_, unsigned int Height_, char BPP_, bool FullScreen_)=0;
218 
219  /// Retrieves the messages of the window message queue, and deals with them.
220  /// Returns 'true' on receipt of a program quit message, 'false' otherwise.
221  virtual bool HandleWindowMessages()=0;
222 
223  /// Indicates that HandleWindowMessages() should return true anytime soon.
224  virtual void PostQuitMessage()=0;
225 
226  /// Returns the first of 256 OpenGL display list handles of an ASCII font character set.
227  virtual unsigned int GetSystemFontDisplayList(int FontHeight, const char* FontName)=0;
228 
229  /// Swaps the front- and back-buffers.
230  virtual void SwapBuffers()=0;
231 
232  /// Returns a pointer to a copy of the current (back-)frame-buffer, and the width and height of the buffer.
233  /// The returned pointer memory is statically allocated and the caller must not free it.
234  virtual uint32_t* GetFrameBuffer(unsigned int& Width_, unsigned int& Height_)=0;
235 
236  /// Well, this closes and destroys the window.
237  virtual void Close()=0;
238 
239  /// This function retrieves the next keyboard event, and stores it in 'KeyboardEvent'.
240  /// Return values:
241  /// -1 - An error occured, no events read. 'KeyboardEvent' is not touched.
242  /// 0 - The event queue is empty, no events read. 'KeyboardEvent' is not touched.
243  /// 1 - One event successfully read and stored in 'KeyboardEvent'.
244  /// 2 - Same as 1, but events were lost due to buffer overflow.
245  virtual int GetNextKeyboardEvent(CaKeyboardEventT& KeyboardEvent)=0;
246 
247  /// This function retrieves the next mouse event, and stores it in 'MouseEvent'.
248  /// Return values:
249  /// -1 - An error occured, no events read. 'MouseEvent' is not touched.
250  /// 0 - The event queue is empty, no events read. 'MouseEvent' is not touched.
251  /// 1 - One event successfully read and stored in 'MouseEvent'.
252  /// 2 - Same as 1, but events were lost due to buffer overflow.
253  virtual int GetNextMouseEvent(CaMouseEventT& MouseEvent)=0;
254 
255 
256  virtual const std::string& GetTitle()=0;
257  virtual unsigned int GetWidth()=0;
258  virtual unsigned int GetHeight()=0;
259  virtual char GetBPP()=0;
260  virtual bool GetFullScreen()=0;
261  virtual bool GetIsMinimized()=0; ///< Ist das Fenster in der Taskbar (minimiert)?
262  // virtual bool GetWindowIsOpen()=0; ///< 'true' gdw ein erfolgreich geƶffnetes Fenster besteht, sonst 'false'.
263  // virtual unsigned int GetRenderingContextCounter()=0; ///< Wird (ab 0) mit jedem erfolreich geƶffneten OpenGLWindow inkrementiert.
264 
265  ///< The function 'GetNextKeyboardEvent()' stores all keyboard events in this array.
266  ///< It can therefore be used to obtain the current state of the keyboard.
267  ///< Note that the state is current only after 'GetNextKeyboardEvent()' has been
268  ///< called until 0 was returned (i.e. the event queue is empty).
269  ///< The only purpuse of this array is to relieve the application from the book-keeping.
270  virtual bool* GetKeyboardState()=0;
271 
272  ///< The function 'GetNextMouseEvent()' stores all mouse button events in this 'char'.
273  ///< It can therefore be used to obtain the current state of the mouse buttons.
274  ///< Mouse button 'i' is pressed iff bit 'i' is set, and released otherwise.
275  ///< Note that the state is current only after 'GetNextMouseEvent()' has been
276  ///< called until 0 was returned (i.e. the event queue is empty).
277  ///< The only purpuse of this 'char' is to relieve the application from the book-keeping.
278  virtual char GetMouseButtonState()=0;
279 };
280 
281 
282 extern SingleOpenGLWindowT* SingleOpenGLWindow;
283 
284 
285 #endif
Web Refresh.
Definition: OpenGLWindow.hpp:170
Web Forward.
Definition: OpenGLWindow.hpp:172
DownArrow on arrow keypad.
Definition: OpenGLWindow.hpp:158
System Power.
Definition: OpenGLWindow.hpp:165
My Computer.
Definition: OpenGLWindow.hpp:174
Accent Grave.
Definition: OpenGLWindow.hpp:73
Play / Pause.
Definition: OpenGLWindow.hpp:142
Previous Track (DIK_CIRCUMFLEX on Japanese keyboard)
Definition: OpenGLWindow.hpp:129
(Japan AX)
Definition: OpenGLWindow.hpp:135
Media Select.
Definition: OpenGLWindow.hpp:176
The mouse wheel.
Definition: OpenGLWindow.hpp:196
Numpad . on Portugese (Brazilian) keyboards.
Definition: OpenGLWindow.hpp:127
Web Favorites.
Definition: OpenGLWindow.hpp:169
. on main keyboard
Definition: OpenGLWindow.hpp:84
Enter on numeric keypad.
Definition: OpenGLWindow.hpp:138
(NEC PC98)
Definition: OpenGLWindow.hpp:134
(Japanese keyboard)
Definition: OpenGLWindow.hpp:122
(NEC PC98)
Definition: OpenGLWindow.hpp:121
/ on numeric keypad
Definition: OpenGLWindow.hpp:148
This struct describes a mouse event.
Definition: OpenGLWindow.hpp:185
virtual void Close()=0
Well, this closes and destroys the window.
Right Windows key.
Definition: OpenGLWindow.hpp:163
Volume -.
Definition: OpenGLWindow.hpp:144
Definition: OpenGLWindow.hpp:204
Calculator.
Definition: OpenGLWindow.hpp:141
/ ? on Portugese (Brazilian) keyboards
Definition: OpenGLWindow.hpp:123
End on arrow keypad.
Definition: OpenGLWindow.hpp:157
(Japanese keyboard)
Definition: OpenGLWindow.hpp:125
on numeric keypad
Definition: OpenGLWindow.hpp:106
virtual uint32_t * GetFrameBuffer(unsigned int &Width_, unsigned int &Height_)=0
Returns a pointer to a copy of the current (back-)frame-buffer, and the width and height of the buffe...
virtual void SwapBuffers()=0
Swaps the front- and back-buffers.
virtual bool GetIsMinimized()=0
Ist das Fenster in der Taskbar (minimiert)?
(Japanese keyboard)
Definition: OpenGLWindow.hpp:124
Home on arrow keypad.
Definition: OpenGLWindow.hpp:152
LeftArrow on arrow keypad.
Definition: OpenGLWindow.hpp:155
(NEC PC98)
Definition: OpenGLWindow.hpp:130
Web home.
Definition: OpenGLWindow.hpp:146
Volume +.
Definition: OpenGLWindow.hpp:145
System Sleep.
Definition: OpenGLWindow.hpp:166
(NEC PC98)
Definition: OpenGLWindow.hpp:119
(NEC PC98)
Definition: OpenGLWindow.hpp:132
TypeT Type
The type of this keyboard event.
Definition: OpenGLWindow.hpp:179
(Japanese keyboard)
Definition: OpenGLWindow.hpp:133
virtual bool * GetKeyboardState()=0
< The function 'GetNextKeyboardEvent()' stores all keyboard events in this array.
Enter on main keyboard.
Definition: OpenGLWindow.hpp:60
Pause.
Definition: OpenGLWindow.hpp:151
= on numeric keypad (NEC PC98)
Definition: OpenGLWindow.hpp:128
Delete on arrow keypad.
Definition: OpenGLWindow.hpp:161
right Alt
Definition: OpenGLWindow.hpp:150
, on numeric keypad (NEC PC98)
Definition: OpenGLWindow.hpp:147
virtual int GetNextMouseEvent(CaMouseEventT &MouseEvent)=0
This function retrieves the next mouse event, and stores it in 'MouseEvent'.
PgDn on arrow keypad.
Definition: OpenGLWindow.hpp:159
Scroll Lock.
Definition: OpenGLWindow.hpp:102
Definition: OpenGLWindow.hpp:110
UpArrow on arrow keypad.
Definition: OpenGLWindow.hpp:153
System Wake.
Definition: OpenGLWindow.hpp:167
TypeT Type
The type of the mouse event.
Definition: OpenGLWindow.hpp:199
(Japanese keyboard)
Definition: OpenGLWindow.hpp:126
Web Stop.
Definition: OpenGLWindow.hpp:171
virtual unsigned int GetSystemFontDisplayList(int FontHeight, const char *FontName)=0
Returns the first of 256 OpenGL display list handles of an ASCII font character set.
This struct describes a keyboard event.
Definition: OpenGLWindow.hpp:20
PgUp on arrow keypad.
Definition: OpenGLWindow.hpp:154
virtual const char * Open(const std::string &Title_, unsigned int Width_, unsigned int Height_, char BPP_, bool FullScreen_)=0
This functions opens a new OpenGL window.
Insert on arrow keypad.
Definition: OpenGLWindow.hpp:160
Left Windows key.
Definition: OpenGLWindow.hpp:162
Web Back.
Definition: OpenGLWindow.hpp:173
. on numeric keypad
Definition: OpenGLWindow.hpp:115
< > | on UK/Germany keyboards
Definition: OpenGLWindow.hpp:116
(J3100)
Definition: OpenGLWindow.hpp:136
Media Stop.
Definition: OpenGLWindow.hpp:143
int Key
If Type is one of CKE_KEYDOWN or CKE_KEYUP, this is one of the CK_* keys from the KeyT enum...
Definition: OpenGLWindow.hpp:180
int Amount
The amount.
Definition: OpenGLWindow.hpp:200
Mail.
Definition: OpenGLWindow.hpp:175
Mute.
Definition: OpenGLWindow.hpp:140
virtual int GetNextKeyboardEvent(CaKeyboardEventT &KeyboardEvent)=0
This function retrieves the next keyboard event, and stores it in 'KeyboardEvent'.
(NEC PC98)
Definition: OpenGLWindow.hpp:131
AppMenu key.
Definition: OpenGLWindow.hpp:164
Definition: OpenGLWindow.hpp:87
virtual void PostQuitMessage()=0
Indicates that HandleWindowMessages() should return true anytime soon.
KeyT
This enum describes a key in a key event.
Definition: OpenGLWindow.hpp:31
Web Search.
Definition: OpenGLWindow.hpp:168
virtual bool HandleWindowMessages()=0
Retrieves the messages of the window message queue, and deals with them.
left Alt
Definition: OpenGLWindow.hpp:88
/ on main keyboard
Definition: OpenGLWindow.hpp:85
RightArrow on arrow keypad.
Definition: OpenGLWindow.hpp:156
Next Track.
Definition: OpenGLWindow.hpp:137
(NEC PC98)
Definition: OpenGLWindow.hpp:120
virtual ~SingleOpenGLWindowT()
Virtual destructor, so that deleting this class through derived-class pointers works right...
Definition: OpenGLWindow.hpp:209
Backspace.
Definition: OpenGLWindow.hpp:46
TypeT
This enum describes the type of the key event.
Definition: OpenGLWindow.hpp:23
TypeT
This enum describes the type of the mouse event.
Definition: OpenGLWindow.hpp:188
on main keyboard
Definition: OpenGLWindow.hpp:44