forked from bsl/GLFW-b
/
window.c
1005 lines (831 loc) · 29.1 KB
/
window.c
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
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
//========================================================================
// GLFW - An OpenGL framework
// Platform: Any
// API version: 2.7
// WWW: http://www.glfw.org/
//------------------------------------------------------------------------
// Copyright (c) 2002-2006 Marcus Geelnard
// Copyright (c) 2006-2010 Camilla Berglund <elmindreda@elmindreda.org>
//
// This software is provided 'as-is', without any express or implied
// warranty. In no event will the authors be held liable for any damages
// arising from the use of this software.
//
// Permission is granted to anyone to use this software for any purpose,
// including commercial applications, and to alter it and redistribute it
// freely, subject to the following restrictions:
//
// 1. The origin of this software must not be misrepresented; you must not
// claim that you wrote the original software. If you use this software
// in a product, an acknowledgment in the product documentation would
// be appreciated but is not required.
//
// 2. Altered source versions must be plainly marked as such, and must not
// be misrepresented as being the original software.
//
// 3. This notice may not be removed or altered from any source
// distribution.
//
//========================================================================
#include "internal.h"
#include <limits.h>
#ifndef GL_VERSION_3_2
#define GL_CONTEXT_CORE_PROFILE_BIT 0x00000001
#define GL_CONTEXT_COMPATIBILITY_PROFILE_BIT 0x00000002
#define GL_CONTEXT_PROFILE_MASK 0x9126
#endif /*GL_VERSION_3_2*/
//************************************************************************
//**** GLFW internal functions ****
//************************************************************************
static int Max(int a, int b)
{
return (a > b) ? a : b;
}
//========================================================================
// Clear all open window hints
//========================================================================
void _glfwClearWindowHints( void )
{
memset( &_glfwLibrary.hints, 0, sizeof( _glfwLibrary.hints ) );
_glfwLibrary.hints.glMajor = 1;
}
//========================================================================
// Handle the input tracking part of window deactivation
//========================================================================
void _glfwInputDeactivation( void )
{
int i;
// Release all keyboard keys
for( i = 0; i <= GLFW_KEY_LAST; i ++ )
{
if( _glfwInput.Key[ i ] == GLFW_PRESS )
{
_glfwInputKey( i, GLFW_RELEASE );
}
}
// Release all mouse buttons
for( i = 0; i <= GLFW_MOUSE_BUTTON_LAST; i ++ )
{
if( _glfwInput.MouseButton[ i ] == GLFW_PRESS )
{
_glfwInputMouseClick( i, GLFW_RELEASE );
}
}
}
//========================================================================
// Clear all input state
//========================================================================
void _glfwClearInput( void )
{
int i;
// Release all keyboard keys
for( i = 0; i <= GLFW_KEY_LAST; i ++ )
{
_glfwInput.Key[ i ] = GLFW_RELEASE;
}
// Clear last character
_glfwInput.LastChar = 0;
// Release all mouse buttons
for( i = 0; i <= GLFW_MOUSE_BUTTON_LAST; i ++ )
{
_glfwInput.MouseButton[ i ] = GLFW_RELEASE;
}
// Set mouse position to (0,0)
_glfwInput.MousePosX = 0;
_glfwInput.MousePosY = 0;
// Set mouse wheel position to 0
_glfwInput.WheelPos = 0;
// The default is to use non sticky keys and mouse buttons
_glfwInput.StickyKeys = GL_FALSE;
_glfwInput.StickyMouseButtons = GL_FALSE;
// The default is to disable key repeat
_glfwInput.KeyRepeat = GL_FALSE;
}
//========================================================================
// Register keyboard activity
//========================================================================
void _glfwInputKey( int key, int action )
{
int keyrepeat = 0;
if( key < 0 || key > GLFW_KEY_LAST )
{
return;
}
// Are we trying to release an already released key?
if( action == GLFW_RELEASE && _glfwInput.Key[ key ] != GLFW_PRESS )
{
return;
}
// Register key action
if( action == GLFW_RELEASE && _glfwInput.StickyKeys )
{
_glfwInput.Key[ key ] = GLFW_STICK;
}
else
{
keyrepeat = (_glfwInput.Key[ key ] == GLFW_PRESS) &&
(action == GLFW_PRESS);
_glfwInput.Key[ key ] = (char) action;
}
// Call user callback function
if( _glfwWin.keyCallback && (_glfwInput.KeyRepeat || !keyrepeat) )
{
_glfwWin.keyCallback( key, action );
}
}
//========================================================================
// Register (keyboard) character activity
//========================================================================
void _glfwInputChar( int character, int action )
{
int keyrepeat = 0;
// Valid Unicode (ISO 10646) character?
if( !( (character >= 32 && character <= 126) || character >= 160 ) )
{
return;
}
// Is this a key repeat?
if( action == GLFW_PRESS && _glfwInput.LastChar == character )
{
keyrepeat = 1;
}
// Store this character as last character (or clear it, if released)
if( action == GLFW_PRESS )
{
_glfwInput.LastChar = character;
}
else
{
_glfwInput.LastChar = 0;
}
// if( action != GLFW_PRESS )
// {
// This intentionally breaks release notifications for Unicode
// characters, partly to see if anyone cares but mostly because it's
// a nonsensical concept to begin with
//
// It will remain broken either until its removal in the 3.0 API or
// until someone explains, in a way that makes sense to people outside
// the US and Scandinavia, what "Unicode character up" actually means
//
// If what you want is "physical key up" then you should be using the
// key functions and/or the key callback, NOT the Unicode input
//
// However, if your particular application uses this misfeature for...
// something, you can re-enable it by removing this if-statement
// return;
// }
if( _glfwWin.charCallback && (_glfwInput.KeyRepeat || !keyrepeat) )
{
_glfwWin.charCallback( character, action );
}
}
//========================================================================
// Register mouse button clicks
//========================================================================
void _glfwInputMouseClick( int button, int action )
{
if( button >= 0 && button <= GLFW_MOUSE_BUTTON_LAST )
{
// Register mouse button action
if( action == GLFW_RELEASE && _glfwInput.StickyMouseButtons )
{
_glfwInput.MouseButton[ button ] = GLFW_STICK;
}
else
{
_glfwInput.MouseButton[ button ] = (char) action;
}
// Call user callback function
if( _glfwWin.mouseButtonCallback )
{
_glfwWin.mouseButtonCallback( button, action );
}
}
}
//========================================================================
// Return the available framebuffer config closest to the desired values
// This is based on the manual GLX Visual selection from 2.6
//========================================================================
const _GLFWfbconfig *_glfwChooseFBConfig( const _GLFWfbconfig *desired,
const _GLFWfbconfig *alternatives,
unsigned int count )
{
unsigned int i;
unsigned int missing, leastMissing = UINT_MAX;
unsigned int colorDiff, leastColorDiff = UINT_MAX;
unsigned int extraDiff, leastExtraDiff = UINT_MAX;
const _GLFWfbconfig *current;
const _GLFWfbconfig *closest = NULL;
for( i = 0; i < count; i++ )
{
current = alternatives + i;
if( desired->stereo > 0 && current->stereo == 0 )
{
// Stereo is a hard constraint
continue;
}
// Count number of missing buffers
{
missing = 0;
if( desired->alphaBits > 0 && current->alphaBits == 0 )
{
missing++;
}
if( desired->depthBits > 0 && current->depthBits == 0 )
{
missing++;
}
if( desired->stencilBits > 0 && current->stencilBits == 0 )
{
missing++;
}
if( desired->auxBuffers > 0 && current->auxBuffers < desired->auxBuffers )
{
missing += desired->auxBuffers - current->auxBuffers;
}
if( desired->samples > 0 && current->samples == 0 )
{
// Technically, several multisampling buffers could be
// involved, but that's a lower level implementation detail and
// not important to us here, so we count them as one
missing++;
}
}
// These polynomials make many small channel size differences matter
// less than one large channel size difference
// Calculate color channel size difference value
{
colorDiff = 0;
if ( desired->redBits > 0 )
{
colorDiff += ( desired->redBits - current->redBits ) *
( desired->redBits - current->redBits );
}
if ( desired->greenBits > 0 )
{
colorDiff += ( desired->greenBits - current->greenBits ) *
( desired->greenBits - current->greenBits );
}
if ( desired->blueBits > 0 )
{
colorDiff += ( desired->blueBits - current->blueBits ) *
( desired->blueBits - current->blueBits );
}
}
// Calculate non-color channel size difference value
{
extraDiff = 0;
if( desired->alphaBits > 0 )
{
extraDiff += ( desired->alphaBits - current->alphaBits ) *
( desired->alphaBits - current->alphaBits );
}
if( desired->depthBits > 0 )
{
extraDiff += ( desired->depthBits - current->depthBits ) *
( desired->depthBits - current->depthBits );
}
if( desired->stencilBits > 0 )
{
extraDiff += ( desired->stencilBits - current->stencilBits ) *
( desired->stencilBits - current->stencilBits );
}
if( desired->accumRedBits > 0 )
{
extraDiff += ( desired->accumRedBits - current->accumRedBits ) *
( desired->accumRedBits - current->accumRedBits );
}
if( desired->accumGreenBits > 0 )
{
extraDiff += ( desired->accumGreenBits - current->accumGreenBits ) *
( desired->accumGreenBits - current->accumGreenBits );
}
if( desired->accumBlueBits > 0 )
{
extraDiff += ( desired->accumBlueBits - current->accumBlueBits ) *
( desired->accumBlueBits - current->accumBlueBits );
}
if( desired->accumAlphaBits > 0 )
{
extraDiff += ( desired->accumAlphaBits - current->accumAlphaBits ) *
( desired->accumAlphaBits - current->accumAlphaBits );
}
if( desired->samples > 0 )
{
extraDiff += ( desired->samples - current->samples ) *
( desired->samples - current->samples );
}
}
// Figure out if the current one is better than the best one found so far
if( missing < leastMissing )
{
closest = current;
}
else if( missing == leastMissing )
{
if( ( colorDiff < leastColorDiff ) ||
( colorDiff == leastColorDiff && extraDiff < leastExtraDiff ) )
{
closest = current;
}
}
if( current == closest )
{
leastMissing = missing;
leastColorDiff = colorDiff;
leastExtraDiff = extraDiff;
}
}
return closest;
}
//************************************************************************
//**** GLFW user functions ****
//************************************************************************
//========================================================================
// Create the GLFW window and its associated context
//========================================================================
GLFWAPI int GLFWAPIENTRY glfwOpenWindow( int width, int height,
int redbits, int greenbits, int bluebits, int alphabits,
int depthbits, int stencilbits, int mode )
{
_GLFWfbconfig fbconfig;
_GLFWwndconfig wndconfig;
if( !_glfwInitialized || _glfwWin.opened )
{
return GL_FALSE;
}
// Set up desired framebuffer config
fbconfig.redBits = Max( redbits, 0 );
fbconfig.greenBits = Max( greenbits, 0 );
fbconfig.blueBits = Max( bluebits, 0 );
fbconfig.alphaBits = Max( alphabits, 0 );
fbconfig.depthBits = Max( depthbits, 0 );
fbconfig.stencilBits = Max( stencilbits, 0 );
fbconfig.accumRedBits = Max( _glfwLibrary.hints.accumRedBits, 0 );
fbconfig.accumGreenBits = Max( _glfwLibrary.hints.accumGreenBits, 0 );
fbconfig.accumBlueBits = Max( _glfwLibrary.hints.accumBlueBits, 0 );
fbconfig.accumAlphaBits = Max( _glfwLibrary.hints.accumAlphaBits, 0 );
fbconfig.auxBuffers = Max( _glfwLibrary.hints.auxBuffers, 0 );
fbconfig.stereo = _glfwLibrary.hints.stereo ? GL_TRUE : GL_FALSE;
fbconfig.samples = Max( _glfwLibrary.hints.samples, 0 );
// Set up desired window config
wndconfig.mode = mode;
wndconfig.refreshRate = Max( _glfwLibrary.hints.refreshRate, 0 );
wndconfig.windowNoResize = _glfwLibrary.hints.windowNoResize ? GL_TRUE : GL_FALSE;
wndconfig.glMajor = Max( _glfwLibrary.hints.glMajor, 1 );
wndconfig.glMinor = Max( _glfwLibrary.hints.glMinor, 0 );
wndconfig.glForward = _glfwLibrary.hints.glForward ? GL_TRUE : GL_FALSE;
wndconfig.glDebug = _glfwLibrary.hints.glDebug ? GL_TRUE : GL_FALSE;
wndconfig.glProfile = _glfwLibrary.hints.glProfile;
if( wndconfig.glMajor == 1 && wndconfig.glMinor > 5 )
{
// OpenGL 1.x series ended with version 1.5
return GL_FALSE;
}
else if( wndconfig.glMajor == 2 && wndconfig.glMinor > 1 )
{
// OpenGL 2.x series ended with version 2.1
return GL_FALSE;
}
else if( wndconfig.glMajor == 3 && wndconfig.glMinor > 3 )
{
// OpenGL 3.x series ended with version 3.3
return GL_FALSE;
}
else
{
// For now, let everything else through
}
if( wndconfig.glProfile &&
( wndconfig.glMajor < 3 || ( wndconfig.glMajor == 3 && wndconfig.glMinor < 2 ) ) )
{
// Context profiles are only defined for OpenGL version 3.2 and above
return GL_FALSE;
}
if( wndconfig.glForward && wndconfig.glMajor < 3 )
{
// Forward-compatible contexts are only defined for OpenGL version 3.0 and above
return GL_FALSE;
}
// Clear for next open call
_glfwClearWindowHints();
// Check input arguments
if( mode != GLFW_WINDOW && mode != GLFW_FULLSCREEN )
{
return GL_FALSE;
}
// Clear GLFW window state
_glfwWin.active = GL_TRUE;
_glfwWin.iconified = GL_FALSE;
_glfwWin.mouseLock = GL_FALSE;
_glfwWin.autoPollEvents = GL_TRUE;
_glfwClearInput();
// Unregister all callback functions
_glfwWin.windowSizeCallback = NULL;
_glfwWin.windowCloseCallback = NULL;
_glfwWin.windowRefreshCallback = NULL;
_glfwWin.keyCallback = NULL;
_glfwWin.charCallback = NULL;
_glfwWin.mousePosCallback = NULL;
_glfwWin.mouseButtonCallback = NULL;
_glfwWin.mouseWheelCallback = NULL;
// Check width & height
if( width > 0 && height <= 0 )
{
// Set the window aspect ratio to 4:3
height = (width * 3) / 4;
}
else if( width <= 0 && height > 0 )
{
// Set the window aspect ratio to 4:3
width = (height * 4) / 3;
}
else if( width <= 0 && height <= 0 )
{
// Default window size
width = 640;
height = 480;
}
// Remember window settings
_glfwWin.width = width;
_glfwWin.height = height;
_glfwWin.fullscreen = (mode == GLFW_FULLSCREEN ? GL_TRUE : GL_FALSE);
// Platform specific window opening routine
if( !_glfwPlatformOpenWindow( width, height, &wndconfig, &fbconfig ) )
{
glfwCloseWindow();
return GL_FALSE;
}
// Flag that window is now opened
_glfwWin.opened = GL_TRUE;
// Read back window and context parameters
_glfwPlatformRefreshWindowParams();
_glfwRefreshContextParams();
if( _glfwWin.glMajor < wndconfig.glMajor ||
( _glfwWin.glMajor == wndconfig.glMajor &&
_glfwWin.glMinor < wndconfig.glMinor ) )
{
glfwCloseWindow();
return GL_FALSE;
}
// Do we have non-power-of-two textures (added to core in version 2.0)?
_glfwWin.has_GL_ARB_texture_non_power_of_two =
( _glfwWin.glMajor >= 2 ) ||
glfwExtensionSupported( "GL_ARB_texture_non_power_of_two" );
// Do we have automatic mipmap generation (added to core in version 1.4)?
_glfwWin.has_GL_SGIS_generate_mipmap =
( _glfwWin.glMajor >= 2 ) || ( _glfwWin.glMinor >= 4 ) ||
glfwExtensionSupported( "GL_SGIS_generate_mipmap" );
if( _glfwWin.glMajor > 2 )
{
_glfwWin.GetStringi = (PFNGLGETSTRINGIPROC) glfwGetProcAddress( "glGetStringi" );
if( !_glfwWin.GetStringi )
{
// This is a very common problem among people who compile GLFW
// on X11/GLX using custom build systems, as it needs explicit
// configuration in order to work
//
// See readme.html section 2.2 for details
glfwCloseWindow();
return GL_FALSE;
}
}
// If full-screen mode was requested, disable mouse cursor
if( mode == GLFW_FULLSCREEN )
{
glfwDisable( GLFW_MOUSE_CURSOR );
}
// Start by clearing the front buffer to black (avoid ugly desktop
// remains in our OpenGL window)
glClear( GL_COLOR_BUFFER_BIT );
_glfwPlatformSwapBuffers();
return GL_TRUE;
}
//========================================================================
// Set hints for opening the window
//========================================================================
GLFWAPI void GLFWAPIENTRY glfwOpenWindowHint( int target, int hint )
{
if( !_glfwInitialized )
{
return;
}
switch( target )
{
case GLFW_REFRESH_RATE:
_glfwLibrary.hints.refreshRate = hint;
break;
case GLFW_ACCUM_RED_BITS:
_glfwLibrary.hints.accumRedBits = hint;
break;
case GLFW_ACCUM_GREEN_BITS:
_glfwLibrary.hints.accumGreenBits = hint;
break;
case GLFW_ACCUM_BLUE_BITS:
_glfwLibrary.hints.accumBlueBits = hint;
break;
case GLFW_ACCUM_ALPHA_BITS:
_glfwLibrary.hints.accumAlphaBits = hint;
break;
case GLFW_AUX_BUFFERS:
_glfwLibrary.hints.auxBuffers = hint;
break;
case GLFW_STEREO:
_glfwLibrary.hints.stereo = hint;
break;
case GLFW_WINDOW_NO_RESIZE:
_glfwLibrary.hints.windowNoResize = hint;
break;
case GLFW_FSAA_SAMPLES:
_glfwLibrary.hints.samples = hint;
break;
case GLFW_OPENGL_VERSION_MAJOR:
_glfwLibrary.hints.glMajor = hint;
break;
case GLFW_OPENGL_VERSION_MINOR:
_glfwLibrary.hints.glMinor = hint;
break;
case GLFW_OPENGL_FORWARD_COMPAT:
_glfwLibrary.hints.glForward = hint;
break;
case GLFW_OPENGL_DEBUG_CONTEXT:
_glfwLibrary.hints.glDebug = hint;
break;
case GLFW_OPENGL_PROFILE:
_glfwLibrary.hints.glProfile = hint;
break;
default:
break;
}
}
//========================================================================
// Properly kill the window / video display
//========================================================================
GLFWAPI void GLFWAPIENTRY glfwCloseWindow( void )
{
if( !_glfwInitialized )
{
return;
}
// Show mouse pointer again (if hidden)
glfwEnable( GLFW_MOUSE_CURSOR );
_glfwPlatformCloseWindow();
memset( &_glfwWin, 0, sizeof(_glfwWin) );
}
//========================================================================
// Set the window title
//========================================================================
GLFWAPI void GLFWAPIENTRY glfwSetWindowTitle( const char *title )
{
if( !_glfwInitialized || !_glfwWin.opened )
{
return;
}
// Set window title
_glfwPlatformSetWindowTitle( title );
}
//========================================================================
// Get the window size
//========================================================================
GLFWAPI void GLFWAPIENTRY glfwGetWindowSize( int *width, int *height )
{
if( !_glfwInitialized || !_glfwWin.opened )
{
return;
}
if( width != NULL )
{
*width = _glfwWin.width;
}
if( height != NULL )
{
*height = _glfwWin.height;
}
}
//========================================================================
// Set the window size
//========================================================================
GLFWAPI void GLFWAPIENTRY glfwSetWindowSize( int width, int height )
{
if( !_glfwInitialized || !_glfwWin.opened || _glfwWin.iconified )
{
return;
}
// Don't do anything if the window size did not change
if( width == _glfwWin.width && height == _glfwWin.height )
{
return;
}
// Change window size
_glfwPlatformSetWindowSize( width, height );
// Refresh window parameters (may have changed due to changed video
// modes)
_glfwPlatformRefreshWindowParams();
}
//========================================================================
// Set the window position
//========================================================================
GLFWAPI void GLFWAPIENTRY glfwSetWindowPos( int x, int y )
{
if( !_glfwInitialized || !_glfwWin.opened || _glfwWin.fullscreen ||
_glfwWin.iconified )
{
return;
}
// Set window position
_glfwPlatformSetWindowPos( x, y );
}
//========================================================================
// Window iconification
//========================================================================
GLFWAPI void GLFWAPIENTRY glfwIconifyWindow( void )
{
if( !_glfwInitialized || !_glfwWin.opened || _glfwWin.iconified )
{
return;
}
// Iconify window
_glfwPlatformIconifyWindow();
}
//========================================================================
// Window un-iconification
//========================================================================
GLFWAPI void GLFWAPIENTRY glfwRestoreWindow( void )
{
if( !_glfwInitialized || !_glfwWin.opened || !_glfwWin.iconified )
{
return;
}
// Restore iconified window
_glfwPlatformRestoreWindow();
// Refresh window parameters
_glfwPlatformRefreshWindowParams();
}
//========================================================================
// Swap buffers (double-buffering) and poll any new events
//========================================================================
GLFWAPI void GLFWAPIENTRY glfwSwapBuffers( void )
{
if( !_glfwInitialized || !_glfwWin.opened )
{
return;
}
_glfwPlatformSwapBuffers();
// Check for window messages
if( _glfwWin.autoPollEvents )
{
glfwPollEvents();
}
}
//========================================================================
// Set double buffering swap interval (0 = vsync off)
//========================================================================
GLFWAPI void GLFWAPIENTRY glfwSwapInterval( int interval )
{
if( !_glfwInitialized || !_glfwWin.opened )
{
return;
}
// Set double buffering swap interval
_glfwPlatformSwapInterval( interval );
}
//========================================================================
// Get window parameter
//========================================================================
GLFWAPI int GLFWAPIENTRY glfwGetWindowParam( int param )
{
if( !_glfwInitialized )
{
return 0;
}
// Is the window opened?
if( !_glfwWin.opened )
{
if( param == GLFW_OPENED )
{
return GL_FALSE;
}
return 0;
}
// Window parameters
switch( param )
{
case GLFW_OPENED:
return GL_TRUE;
case GLFW_ACTIVE:
return _glfwWin.active;
case GLFW_ICONIFIED:
return _glfwWin.iconified;
case GLFW_ACCELERATED:
return _glfwWin.accelerated;
case GLFW_RED_BITS:
return _glfwWin.redBits;
case GLFW_GREEN_BITS:
return _glfwWin.greenBits;
case GLFW_BLUE_BITS:
return _glfwWin.blueBits;
case GLFW_ALPHA_BITS:
return _glfwWin.alphaBits;
case GLFW_DEPTH_BITS:
return _glfwWin.depthBits;
case GLFW_STENCIL_BITS:
return _glfwWin.stencilBits;
case GLFW_ACCUM_RED_BITS:
return _glfwWin.accumRedBits;
case GLFW_ACCUM_GREEN_BITS:
return _glfwWin.accumGreenBits;
case GLFW_ACCUM_BLUE_BITS:
return _glfwWin.accumBlueBits;
case GLFW_ACCUM_ALPHA_BITS:
return _glfwWin.accumAlphaBits;
case GLFW_AUX_BUFFERS:
return _glfwWin.auxBuffers;
case GLFW_STEREO:
return _glfwWin.stereo;
case GLFW_REFRESH_RATE:
return _glfwWin.refreshRate;
case GLFW_WINDOW_NO_RESIZE:
return _glfwWin.windowNoResize;
case GLFW_FSAA_SAMPLES:
return _glfwWin.samples;
case GLFW_OPENGL_VERSION_MAJOR:
return _glfwWin.glMajor;
case GLFW_OPENGL_VERSION_MINOR:
return _glfwWin.glMinor;
case GLFW_OPENGL_FORWARD_COMPAT:
return _glfwWin.glForward;
case GLFW_OPENGL_DEBUG_CONTEXT:
return _glfwWin.glDebug;
case GLFW_OPENGL_PROFILE:
return _glfwWin.glProfile;
default:
return 0;
}
}
//========================================================================
// Set callback function for window size changes
//========================================================================
GLFWAPI void GLFWAPIENTRY glfwSetWindowSizeCallback( GLFWwindowsizefun cbfun )
{
if( !_glfwInitialized || !_glfwWin.opened )
{
return;
}
// Set callback function
_glfwWin.windowSizeCallback = cbfun;
// Call the callback function to let the application know the current
// window size
if( cbfun )
{
cbfun( _glfwWin.width, _glfwWin.height );
}
}
//========================================================================
// Set callback function for window close events
//========================================================================
GLFWAPI void GLFWAPIENTRY glfwSetWindowCloseCallback( GLFWwindowclosefun cbfun )
{
if( !_glfwInitialized || !_glfwWin.opened )
{
return;
}
// Set callback function
_glfwWin.windowCloseCallback = cbfun;
}
//========================================================================
// Set callback function for window refresh events
//========================================================================
GLFWAPI void GLFWAPIENTRY glfwSetWindowRefreshCallback( GLFWwindowrefreshfun cbfun )
{
if( !_glfwInitialized || !_glfwWin.opened )
{
return;
}
// Set callback function
_glfwWin.windowRefreshCallback = cbfun;
}
//========================================================================
// Poll for new window and input events
//========================================================================
GLFWAPI void GLFWAPIENTRY glfwPollEvents( void )
{
if( !_glfwInitialized || !_glfwWin.opened )
{
return;
}
// Poll for new events
_glfwPlatformPollEvents();
}
//========================================================================
// Wait for new window and input events
//========================================================================
GLFWAPI void GLFWAPIENTRY glfwWaitEvents( void )
{
if( !_glfwInitialized || !_glfwWin.opened )
{
return;
}