-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwindow.cpp
463 lines (457 loc) · 14.5 KB
/
window.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
#include "window.hpp"
namespace sre
{
//== Window ==//
/** \class Window
* \brief A class representing a window with an OpenGL context
* \sa GLFWwindow */
//// ctor ////
/** Constructs from pointer from a GLFWwindow \sa glfwCreateWindow */
Window::Window ( GLFWwindow * window ) {
this->window = window;
}
/** Constructs a window given 0 to 5 parameters
* \param[in] width,height width and height of the window in screen coordinates
* \param[in] title The initial title of the window
* \param[in] monitor The monitor to use for full-screen mode. Pass `Monitor(nullptr)` for windowed mode
* \param[in] share The window to context resuources with. Pass `Window(nullptr)` for windowed mode
* \sa glfwCreateWindow(int, int, const char*, GLFWmonitor*, GLFWwindow*) */
Window::Window ( const int width, const int height,
const std::string & title,
const Hints & hints,
const Monitor & monitor,
const Window & share ) {
hints.apply();
this->window = glfwCreateWindow( width, height,
title.c_str(),
monitor.getGLFWMonitor(),
share.window );
}
//// get methods ////
/** \return A pointer to the GLFWwindow represented by this object. */
GLFWwindow * Window::getGLFWwindow() {
return this->window;
}
/** \return A vector containing the size of the Window's framebuffer in pixel.
* \sa glfwGetFamebufferSize */
ivec2 Window::getFramebufferSize() const {
ivec2 size;
glfwGetFramebufferSize( this->window, &size.x, &size.y );
return size;
}
/** \return A vector holding the x and y coordinates of the window in pixels
* \sa setPos(), glfwGetWindowPos()
*/
ivec2 Window::getPos () const {
ivec2 pos;
glfwGetWindowPos( this->window, &pos.x, &pos.y );
return pos;
}
/** \return A vector holding the width and height of the window in pixels
* \sa setSize(), glfwGetWindowPos()
*/
ivec2 Window::getSize () const {
ivec2 size;
glfwGetWindowSize( this->window, &size.x, &size.y );
return size;
}
/** Returns true if window was created successfully
* \return true if window exists, false otherwise
* \sa Window(), glfwCreateWindow()
*/
bool Window::exists () const {
return (window != nullptr);
}
/** checks if window's "should close" flag is set
\return If the window exists/was-created. True if window should close,
false if window should remain open
\sa glfwWindowShouldClose
*/
int Window::shouldClose () const {
return glfwWindowShouldClose( this->window );
}
// set
/** Sets window's title
\param[in] title The window's new title
\sa getTitle(), glfwGetWindowTitle()
*/
void Window::setTitle ( const std::string & title ) {
glfwSetWindowTitle( this->window, title.c_str() );
}
/** Sets window's position
\param[in] width,height The x & y screen coordinate
\sa getPos(), glfwSetWindowPos()
*/
void Window::setPos ( int width, int height ) {
glfwSetWindowPos( this->window, width, height );
}
/** Sets window's position
\param[in] pos Vector of x and y screen coordinates
\sa getPos(), glfwSetWindowPos()
*/
void Window::setPos ( const ivec2 & pos ) {
glfwSetWindowPos( this->window, pos.x, pos.y );
}
/** Sets window's size in pixels
\param[in] xSize Width in pixels
\param[in] ySize Height in pixels
\sa getPos(), glfwSetWindowSize()
*/
void Window::setSize ( int xSize, int ySize ) {
glfwSetWindowSize( this->window, xSize, ySize );
}
/** Sets window's size in pixels
\param[in] size Size in pixels
\sa getPos(), glfwSetWindowSize()
*/
void Window::setSize ( const ivec2 & size ) {
glfwSetWindowSize( this->window, size.x, size.y );
}
// set command
/** Make this window the active OpenGl context */
void Window::makeActive() {
glfwMakeContextCurrent( this->window );
}
/** Swaps the front and back buffers of this window. \sa glfwSwapBuffers */
void Window::swapBuffers() {
glfwSwapBuffers( this->window );
}
/** Iconifies/minimizes window
\sa restore(), glfwIconifyWindow()
*/
void Window::iconify ()
{
glfwIconifyWindow( this->window );
}
/** restores current window
\sa iconify(), glfwRestoreWindow()
*/
void Window::restore ()
{
glfwRestoreWindow( this->window );
}
/** makes window visible if it was hidden
\sa hide(), glfwShowWindow()
*/
void Window::show ()
{
glfwShowWindow( this->window );
}
/** hides window if it was visable
\sa show(), glfwHideWindow()
*/
void Window::hide()
{
glfwHideWindow( this->window );
}
/** Set window's "should close" flag
\param[in] - GL_TRUE if window should close
- GL_FALSE if window should stay open
\param[out] returns value of flag (GL_TRUE or GL_FALSE)
*/
int Window::shouldClose( int gl_tf )
{
glfwSetWindowShouldClose( this->window, gl_tf );
return gl_tf;
}
} // namespace sre
//
//#include "window.hpp"
//#include <iostream>
//
//namespace sre
//{
// /////////////
// //VideoMode//
//
// VideoMode::VideoMode ( Monitor * monitor )
// : VideoMode ( monitor->getVideoMode() )
// {
// }
// VideoMode::VideoMode ( VideoMode * videoMode )
// {
// this->vidMode = videoMode->vidMode;
// }
// VideoMode::VideoMode ( const GLFWvidmode * vidmode)
// {
// *( this->vidMode ) = *vidmode;
// }
//
// void VideoMode::setWidth ( int width ) { vidMode->width = width; }
// void VideoMode::setHeight ( int height ) { vidMode->height = height; }
// void VideoMode::setRedBits ( int redBits ) { vidMode->redBits = redBits; }
// void VideoMode::setGreenBits ( int greenBits ) { vidMode->greenBits = greenBits; }
// void VideoMode::setBlueBits ( int blueBits ) { vidMode->blueBits = blueBits; }
// void VideoMode::setRefreshRate ( int refreshRate ) { vidMode->refreshRate = refreshRate; }
//
// int VideoMode::getWidth () const { return vidMode->width; }
// int VideoMode::getHeight () const { return vidMode->height; }
// int VideoMode::getRedBits () const { return vidMode->redBits; }
// int VideoMode::getGreenBits () const { return vidMode->greenBits; }
// int VideoMode::getBlueBits () const { return vidMode->blueBits; }
// int VideoMode::getRefreshRate () const { return vidMode->refreshRate; }
//
// /////////////
// //GammaRamp//
//
//
// ///////////
// //Monitor//
//
// Monitor::Monitor ()
// {
// monitor = glfwGetPrimaryMonitor();
// }
// Monitor::Monitor (GLFWmonitor * monitor)
// {
// this->monitor = monitor;
// glfwGetMonitorPos( this->monitor, &posXY[0], &posXY[1] );
// glfwGetMonitorPhysicalSize( this->monitor, &physSize[0], &physSize[1] );
// name = glfwGetMonitorName( this->monitor );
// }
// VideoMode Monitor::getVideoMode () const
// {
// return VideoMode( glfwGetVideoMode ( monitor ) );
// }
// int * Monitor::getPos ()
// {
// glfwGetMonitorPos( monitor, &posXY[0], &posXY[1] );
// return posXY;
// }
// int * Monitor::getPhysicalSize ()
// {
// glfwGetMonitorPhysicalSize( monitor, &physSize[0], &physSize[1] );
// return physSize;
// }
// GLFWmonitor * Monitor::getGLFWMonitor () const
// {
// return monitor;
// }
// Monitor Monitor::getPrimary ()
// {
// return Monitor( glfwGetPrimaryMonitor() );
// }
//
// //////////
// //Window//
// Window::Window ( GLFWwindow * window )
// {
// this->window = window;
// }
// Window::Window ( int width, int height, std::string title , Monitor monitor)
// {
// this->width = width;
// this->height = height;
// this->title = title;
// this->monitor = monitor;
// windowSettings = WindowSettings();
// frameBufferSettings = FrameBufferSettings();
// contextSettings = ContextSettings();
// apply(); // apply all GLFW hints
// }
// //set
// void Window::setWindowPos ( int xpos, int ypos )
// {
// glfwSetWindowPos( window, xpos, ypos );
// }
// void Window::setWindowPosX ( int xpos )
// {
// glfwSetWindowPos( window, xpos, this->y );
// }
// void Window::setWindowPosY ( int ypos )
// {
// glfwSetWindowPos( window, this->x, ypos );
// }
// void Window::setWindowSize ( int width, int height)
// {
// glfwSetWindowSize ( window, width, height );
// }
// void Window::setWindowWidth ( int width )
// {
// glfwSetWindowSize ( window, width, this->height );
// }
// void Window::setWindowHeight ( int height )
// {
// glfwSetWindowSize ( window, height, this->height );
// }
// void Window::setWindowShouldClose ( bool tf )
// {
// glfwSetWindowShouldClose ( window , tf );
// }
//
// //get
// bool Window::isFocused () const
// {
// return glfwGetWindowAttrib( window, GLFW_FOCUSED );
// }
// bool Window::isIconified () const
// {
// return glfwGetWindowAttrib( window, GLFW_ICONIFIED );
// }
// bool Window::isResizable () const
// {
// return glfwGetWindowAttrib( window, GLFW_RESIZABLE );
// }
// bool Window::isDecorated () const
// {
// return glfwGetWindowAttrib( window, GLFW_DECORATED );
// }
// int Window::getWindowPosX ()
// {
// glfwGetWindowPos( window, &x, NULL );
// return x;
// }
// int Window::getWindowPosY ()
// {
// glfwGetWindowPos( window, NULL, &y );
// return y;
// }
//
// int Window::getWindowWidth ()
// {
// glfwGetWindowSize( window, &width, NULL );
// return width;
// }
// int Window::getWindowHeight ()
// {
// glfwGetWindowSize( window, NULL, &height );
// }
// int Window::getFrameBufferSizeX ()
// {
// glfwGetFramebufferSize( window, &x, NULL );
// return x;
// }
// int Window::getFrameBufferSizeY ()
// {
// glfwGetFramebufferSize( window, &y, NULL );
// }
//
// bool Window::windowShouldClose () const
// {
// glfwWindowShouldClose( window );
// }
//
// void Window::swapBuffers()
// {
// glfwSwapBuffers( window );
// }
//
// void Window::apply()
// {
// //all other settings
// windowSettings.apply();
// frameBufferSettings.apply();
// contextSettings.apply();
// window = glfwCreateWindow( width, height, title.c_str(), monitor.getGLFWMonitor(), NULL );
// }
// void Window::setActive()
// {
// glfwMakeContextCurrent( window );
// }
//
// Window Window::getActive()
// {
// return Window( glfwGetCurrentContext() );
// }
//
// // settings classes
// void Settings::apply() const
// {
// // bool and GL_TRUE and GL_FALSE don't play nicely: LET ME KNOW!
// if (! ( (int(true) == int(GL_TRUE)) && ( int(false) == int(GL_FALSE) ) ) )
// {
// std::cerr<< "ERROR: bool true, false != GL_TRUE, GL_FALSE!";
// }
// }
//
// void WindowSettings::apply() const
// {
// Settings::apply();
// glfwWindowHint( GLFW_RESIZABLE, isResizable() );
// glfwWindowHint( GLFW_VISIBLE, isVisible() );
// glfwWindowHint( GLFW_DECORATED, isDecorated() );
// }
//
// void FrameBufferSettings::apply() const
// {
// Settings::apply();
// glfwWindowHint( GLFW_RED_BITS, getRedBits() );
// glfwWindowHint( GLFW_GREEN_BITS, getGreenBits() );
// glfwWindowHint( GLFW_BLUE_BITS, getBlueBits() );
// glfwWindowHint( GLFW_ALPHA_BITS, getAlphaBits() );
// glfwWindowHint( GLFW_DEPTH_BITS, getDepthBits() );
// glfwWindowHint( GLFW_STENCIL_BITS, getStencilBits() );
//
// glfwWindowHint( GLFW_ACCUM_RED_BITS, getAccumRedBits() );
// glfwWindowHint( GLFW_ACCUM_GREEN_BITS, getAccumGreenBits() );
// glfwWindowHint( GLFW_ACCUM_BLUE_BITS, getAccumBlueBits() );
// glfwWindowHint( GLFW_ACCUM_ALPHA_BITS, getAccumAlphaBits() );
// glfwWindowHint( GLFW_AUX_BUFFERS, getAuxBuffers() );
// glfwWindowHint( GLFW_SAMPLES, getSamples() );
// glfwWindowHint( GLFW_REFRESH_RATE, getRefreshRate() );
//
// glfwWindowHint( GLFW_STEREO, isStereo() );
// glfwWindowHint( GLFW_SRGB_CAPABLE, isSRGBCapable() );
// }
//
// void ContextSettings::apply() const
// {
// Settings::apply();
// switch (api)
// {
// case GL:
// glfwWindowHint( GLFW_CLIENT_API, GLFW_OPENGL_API );
// break;
// case GL_ES:
// glfwWindowHint( GLFW_CLIENT_API, GLFW_OPENGL_ES_API );
// break;
// default:
// break;
// //enum has no value...
// }
//
// glfwWindowHint( GLFW_CONTEXT_VERSION_MAJOR, getVersionMajor() );
// glfwWindowHint( GLFW_CONTEXT_VERSION_MINOR, getVersionMinor() );
//
// switch (robustness)
// {
// case NO_ROBUSTNESS:
// glfwWindowHint( GLFW_CONTEXT_ROBUSTNESS, GLFW_NO_ROBUSTNESS );
// break;
// case NO_RESET_NOTIFICATION:
// glfwWindowHint( GLFW_CONTEXT_ROBUSTNESS, GLFW_NO_RESET_NOTIFICATION );
// break;
// case LOSE_CONTEXT_ON_RESET:
// glfwWindowHint( GLFW_CONTEXT_ROBUSTNESS, GLFW_LOSE_CONTEXT_ON_RESET );
// break;
// default:
// break;
// //enum has no value...
// }
//
// glfwWindowHint( GLFW_OPENGL_FORWARD_COMPAT, isForwardCompatible() );
// glfwWindowHint( GLFW_OPENGL_DEBUG_CONTEXT, isDebugContext() );
//
// switch (profile)
// {
// case ANY_PROFILE:
// glfwWindowHint( GLFW_OPENGL_PROFILE, GLFW_OPENGL_ANY_PROFILE );
// break;
// case COMPAT_PROFILE:
// glfwWindowHint( GLFW_OPENGL_PROFILE, GLFW_OPENGL_COMPAT_PROFILE );
// break;
// case CORE_PROFILE:
// glfwWindowHint( GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE );
// break;
// default:
// break;
// //enum has no value...
// }
//
// }
//}
//
//
//
//
//