/
video.go
1116 lines (929 loc) · 42.2 KB
/
video.go
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
package sdl
/*
#include "sdl_wrapper.h"
static inline Sint32 ShowMessageBox(SDL_MessageBoxData data)
{
Sint32 buttonid;
SDL_ShowMessageBox(&data, &buttonid);
return buttonid;
}
#if !(SDL_VERSION_ATLEAST(2,0,1))
static void SDL_GL_GetDrawableSize(SDL_Window *window, int *w, int *h)
{
*w = 0;
*h = 0;
}
#if defined(WARN_OUTDATED)
#pragma message("SDL_WINDOW_ALLOW_HIGHDPI is not supported before SDL 2.0.1")
#endif
#define SDL_WINDOW_ALLOW_HIGHDPI (0)
#if defined(WARN_OUTDATED)
#pragma message("SDL_GL_FRAMEBUFFER_SRGB_CAPABLE is not supported before SDL 2.0.1")
#endif
#define SDL_GL_FRAMEBUFFER_SRGB_CAPABLE (0)
#endif
#if !(SDL_VERSION_ATLEAST(2,0,4))
#if defined(WARN_OUTDATED)
#pragma message("SDL_WINDOW_MOUSE_CAPTURE is not supported before SDL 2.0.4")
#endif
#define SDL_WINDOW_MOUSE_CAPTURE (0)
#if defined(WARN_OUTDATED)
#pragma message("SDL_GL_CONTEXT_RELEASE_BEHAVIOR is not supported before SDL 2.0.4")
#endif
#define SDL_GL_CONTEXT_RELEASE_BEHAVIOR (0)
#if defined(WARN_OUTDATED)
#pragma message("SDL_GetDisplayDPI is not supported before SDL 2.0.4")
#endif
static int SDL_GetDisplayDPI(int displayIndex, float* ddpi, float* hdpi, float* vdpi)
{
return -1;
}
#endif
#if !(SDL_VERSION_ATLEAST(2,0,5))
#if defined(WARN_OUTDATED)
#pragma message("SDL_SetWindowResizable is not supported before SDL 2.0.5")
#endif
static void SDL_SetWindowResizable(SDL_Window *window, SDL_bool resizable)
{
}
#if defined(WARN_OUTDATED)
#pragma message("SDL_SetWindowOpacity is not supported before SDL 2.0.5")
#endif
static int SDL_SetWindowOpacity(SDL_Window *window, float opacity)
{
return -1;
}
#if defined(WARN_OUTDATED)
#pragma message("SDL_GetWindowOpacity is not supported before SDL 2.0.5")
#endif
static int SDL_GetWindowOpacity(SDL_Window *window, float *opacity)
{
return -1;
}
#if defined(WARN_OUTDATED)
#pragma message("SDL_GetDisplayUsableBounds is not supported before SDL 2.0.5")
#endif
static int SDL_GetDisplayUsableBounds(int displayIndex, SDL_Rect* rect)
{
return -1;
}
#if defined(WARN_OUTDATED)
#pragma message("SDL_WINDOW_ALWAYS_ON_TOP is not supported before SDL 2.0.5")
#endif
#define SDL_WINDOW_ALWAYS_ON_TOP (0)
#if defined(WARN_OUTDATED)
#pragma message("SDL_WINDOW_SKIP_TASKBAR is not supported before SDL 2.0.5")
#endif
#define SDL_WINDOW_SKIP_TASKBAR (0)
#if defined(WARN_OUTDATED)
#pragma message("SDL_WINDOW_UTILITY is not supported before SDL 2.0.5")
#endif
#define SDL_WINDOW_UTILITY (0)
#if defined(WARN_OUTDATED)
#pragma message("SDL_WINDOW_TOOLTIP is not supported before SDL 2.0.5")
#endif
#define SDL_WINDOW_TOOLTIP (0)
#if defined(WARN_OUTDATED)
#pragma message("SDL_WINDOW_POPUP_MENU is not supported before SDL 2.0.5")
#endif
#define SDL_WINDOW_POPUP_MENU (0)
#if defined(WARN_OUTDATED)
#pragma message("SDL_WINDOWEVENT_TAKE_FOCUS is not supported before SDL 2.0.5")
#endif
#define SDL_WINDOWEVENT_TAKE_FOCUS (0)
#if defined(WARN_OUTDATED)
#pragma message("SDL_WINDOWEVENT_HIT_TEST is not supported before SDL 2.0.5")
#endif
#define SDL_WINDOWEVENT_HIT_TEST (0)
#endif
#if !(SDL_VERSION_ATLEAST(2,0,6))
#if defined(WARN_OUTDATED)
#pragma message("SDL_WINDOW_VULKAN is not supported before SDL 2.0.6")
#endif
#define SDL_WINDOW_VULKAN (0)
#if defined(WARN_OUTDATED)
#pragma message("SDL_GL_CONTEXT_RESET_NOTIFICATION is not supported before SDL 2.0.6")
#endif
#define SDL_GL_CONTEXT_RESET_NOTIFICATION (0)
#if defined(WARN_OUTDATED)
#pragma message("SDL_GL_CONTEXT_NO_ERROR is not supported before SDL 2.0.6")
#endif
#define SDL_GL_CONTEXT_NO_ERROR (0)
#endif
#if !(SDL_VERSION_ATLEAST(2,0,16))
#if defined(WARN_OUTDATED)
#pragma message("SDL_FlashWindow is not supported before SDL 2.0.16")
#pragma message("SDL_SetWindowAlwaysOnTop is not supported before SDL 2.0.16")
#pragma message("SDL_SetWindowKeyboardGrab is not supported before SDL 2.0.16")
#endif
typedef enum
{
SDL_FLASH_CANCEL, // Cancel any window flash state
SDL_FLASH_BRIEFLY, // Flash the window briefly to get attention
SDL_FLASH_UNTIL_FOCUSED, // Flash the window until it gets focus
} SDL_FlashOperation;
static int SDL_FlashWindow(SDL_Window * window, SDL_FlashOperation operation)
{
return -1;
}
static void SDL_SetWindowAlwaysOnTop(SDL_Window * window, SDL_bool on_top)
{
return;
}
static void SDL_SetWindowKeyboardGrab(SDL_Window * window, SDL_bool grabbed)
{
return;
}
#endif
#if !(SDL_VERSION_ATLEAST(2,0,18))
#if defined(WARN_OUTDATED)
#pragma message("SDL_GetWindowICCProfile is not supported before SDL 2.0.18")
#pragma message("SDL_SetWindowMouseRect is not supported before SDL 2.0.18")
#pragma message("SDL_GetWindowMouseRect is not supported before SDL 2.0.18")
#endif
#define SDL_WINDOWEVENT_ICCPROF_CHANGED (17) // The ICC profile of the window's display has changed.
#define SDL_WINDOWEVENT_DISPLAY_CHANGED (18) // Window has been moved to display data1.
static void* SDLCALL SDL_GetWindowICCProfile(SDL_Window * window, size_t* size)
{
return NULL;
}
static int SDL_SetWindowMouseRect(SDL_Window * window, const SDL_Rect * rect)
{
return -1;
}
static const SDL_Rect * SDLCALL SDL_GetWindowMouseRect(SDL_Window * window)
{
return NULL;
}
#endif
*/
import "C"
import "unsafe"
// An enumeration of window states.
// (https://wiki.libsdl.org/SDL_WindowFlags)
const (
WINDOW_FULLSCREEN = C.SDL_WINDOW_FULLSCREEN // fullscreen window
WINDOW_OPENGL = C.SDL_WINDOW_OPENGL // window usable with OpenGL context
WINDOW_SHOWN = C.SDL_WINDOW_SHOWN // window is visible
WINDOW_HIDDEN = C.SDL_WINDOW_HIDDEN // window is not visible
WINDOW_BORDERLESS = C.SDL_WINDOW_BORDERLESS // no window decoration
WINDOW_RESIZABLE = C.SDL_WINDOW_RESIZABLE // window can be resized
WINDOW_MINIMIZED = C.SDL_WINDOW_MINIMIZED // window is minimized
WINDOW_MAXIMIZED = C.SDL_WINDOW_MAXIMIZED // window is maximized
WINDOW_INPUT_GRABBED = C.SDL_WINDOW_INPUT_GRABBED // window has grabbed input focus
WINDOW_INPUT_FOCUS = C.SDL_WINDOW_INPUT_FOCUS // window has input focus
WINDOW_MOUSE_FOCUS = C.SDL_WINDOW_MOUSE_FOCUS // window has mouse focus
WINDOW_FULLSCREEN_DESKTOP = C.SDL_WINDOW_FULLSCREEN_DESKTOP // fullscreen window at the current desktop resolution
WINDOW_FOREIGN = C.SDL_WINDOW_FOREIGN // window not created by SDL
WINDOW_ALLOW_HIGHDPI = C.SDL_WINDOW_ALLOW_HIGHDPI // window should be created in high-DPI mode if supported (>= SDL 2.0.1)
WINDOW_MOUSE_CAPTURE = C.SDL_WINDOW_MOUSE_CAPTURE // window has mouse captured (unrelated to INPUT_GRABBED, >= SDL 2.0.4)
WINDOW_ALWAYS_ON_TOP = C.SDL_WINDOW_ALWAYS_ON_TOP // window should always be above others (X11 only, >= SDL 2.0.5)
WINDOW_SKIP_TASKBAR = C.SDL_WINDOW_SKIP_TASKBAR // window should not be added to the taskbar (X11 only, >= SDL 2.0.5)
WINDOW_UTILITY = C.SDL_WINDOW_UTILITY // window should be treated as a utility window (X11 only, >= SDL 2.0.5)
WINDOW_TOOLTIP = C.SDL_WINDOW_TOOLTIP // window should be treated as a tooltip (X11 only, >= SDL 2.0.5)
WINDOW_POPUP_MENU = C.SDL_WINDOW_POPUP_MENU // window should be treated as a popup menu (X11 only, >= SDL 2.0.5)
WINDOW_VULKAN = C.SDL_WINDOW_VULKAN // window usable for Vulkan surface (>= SDL 2.0.6)
)
// An enumeration of window events.
// (https://wiki.libsdl.org/SDL_WindowEventID)
const (
WINDOWEVENT_NONE = C.SDL_WINDOWEVENT_NONE // (never used)
WINDOWEVENT_SHOWN = C.SDL_WINDOWEVENT_SHOWN // window has been shown
WINDOWEVENT_HIDDEN = C.SDL_WINDOWEVENT_HIDDEN // window has been hidden
WINDOWEVENT_EXPOSED = C.SDL_WINDOWEVENT_EXPOSED // window has been exposed and should be redrawn
WINDOWEVENT_MOVED = C.SDL_WINDOWEVENT_MOVED // window has been moved to data1, data2
WINDOWEVENT_RESIZED = C.SDL_WINDOWEVENT_RESIZED // window has been resized to data1xdata2; this event is always preceded by WINDOWEVENT_SIZE_CHANGED
WINDOWEVENT_SIZE_CHANGED = C.SDL_WINDOWEVENT_SIZE_CHANGED // window size has changed, either as a result of an API call or through the system or user changing the window size; this event is followed by WINDOWEVENT_RESIZED if the size was changed by an external event, i.e. the user or the window manager
WINDOWEVENT_MINIMIZED = C.SDL_WINDOWEVENT_MINIMIZED // window has been minimized
WINDOWEVENT_MAXIMIZED = C.SDL_WINDOWEVENT_MAXIMIZED // window has been maximized
WINDOWEVENT_RESTORED = C.SDL_WINDOWEVENT_RESTORED // window has been restored to normal size and position
WINDOWEVENT_ENTER = C.SDL_WINDOWEVENT_ENTER // window has gained mouse focus
WINDOWEVENT_LEAVE = C.SDL_WINDOWEVENT_LEAVE // window has lost mouse focus
WINDOWEVENT_FOCUS_GAINED = C.SDL_WINDOWEVENT_FOCUS_GAINED // window has gained keyboard focus
WINDOWEVENT_FOCUS_LOST = C.SDL_WINDOWEVENT_FOCUS_LOST // window has lost keyboard focus
WINDOWEVENT_CLOSE = C.SDL_WINDOWEVENT_CLOSE // the window manager requests that the window be closed
WINDOWEVENT_TAKE_FOCUS = C.SDL_WINDOWEVENT_TAKE_FOCUS // window is being offered a focus (should SDL_SetWindowInputFocus() on itself or a subwindow, or ignore) (>= SDL 2.0.5)
WINDOWEVENT_HIT_TEST = C.SDL_WINDOWEVENT_HIT_TEST // window had a hit test that wasn't SDL_HITTEST_NORMAL (>= SDL 2.0.5)
WINDOWEVENT_ICCPROF_CHANGED = C.SDL_WINDOWEVENT_ICCPROF_CHANGED // the ICC profile of the window's display has changed
WINDOWEVENT_DISPLAY_CHANGED = C.SDL_WINDOWEVENT_DISPLAY_CHANGED // window has been moved to display data1
)
// Window position flags.
// (https://wiki.libsdl.org/SDL_CreateWindow)
const (
WINDOWPOS_UNDEFINED_MASK = C.SDL_WINDOWPOS_UNDEFINED_MASK // used to indicate that you don't care what the window position is
WINDOWPOS_UNDEFINED = C.SDL_WINDOWPOS_UNDEFINED // used to indicate that you don't care what the window position is
WINDOWPOS_CENTERED_MASK = C.SDL_WINDOWPOS_CENTERED_MASK // used to indicate that the window position should be centered
WINDOWPOS_CENTERED = C.SDL_WINDOWPOS_CENTERED // used to indicate that the window position should be centered
)
// An enumeration of message box flags (e.g. if supported message box will display warning icon).
// (https://wiki.libsdl.org/SDL_MessageBoxFlags)
const (
MESSAGEBOX_ERROR = C.SDL_MESSAGEBOX_ERROR // error dialog
MESSAGEBOX_WARNING = C.SDL_MESSAGEBOX_WARNING // warning dialog
MESSAGEBOX_INFORMATION = C.SDL_MESSAGEBOX_INFORMATION // informational dialog
)
// Flags for MessageBoxButtonData.
const (
MESSAGEBOX_BUTTON_RETURNKEY_DEFAULT = C.SDL_MESSAGEBOX_BUTTON_RETURNKEY_DEFAULT // marks the default button when return is hit
MESSAGEBOX_BUTTON_ESCAPEKEY_DEFAULT = C.SDL_MESSAGEBOX_BUTTON_ESCAPEKEY_DEFAULT // marks the default button when escape is hit
)
// OpenGL configuration attributes.
// (https://wiki.libsdl.org/SDL_GL_SetAttribute)
const (
GL_RED_SIZE = C.SDL_GL_RED_SIZE // the minimum number of bits for the red channel of the color buffer; defaults to 3
GL_GREEN_SIZE = C.SDL_GL_GREEN_SIZE // the minimum number of bits for the green channel of the color buffer; defaults to 3
GL_BLUE_SIZE = C.SDL_GL_BLUE_SIZE // the minimum number of bits for the blue channel of the color buffer; defaults to 2
GL_ALPHA_SIZE = C.SDL_GL_ALPHA_SIZE // the minimum number of bits for the alpha channel of the color buffer; defaults to 0
GL_BUFFER_SIZE = C.SDL_GL_BUFFER_SIZE // the minimum number of bits for frame buffer size; defaults to 0
GL_DOUBLEBUFFER = C.SDL_GL_DOUBLEBUFFER // whether the output is single or double buffered; defaults to double buffering on
GL_DEPTH_SIZE = C.SDL_GL_DEPTH_SIZE // the minimum number of bits in the depth buffer; defaults to 16
GL_STENCIL_SIZE = C.SDL_GL_STENCIL_SIZE // the minimum number of bits in the stencil buffer; defaults to 0
GL_ACCUM_RED_SIZE = C.SDL_GL_ACCUM_RED_SIZE // the minimum number of bits for the red channel of the accumulation buffer; defaults to 0
GL_ACCUM_GREEN_SIZE = C.SDL_GL_ACCUM_GREEN_SIZE // the minimum number of bits for the green channel of the accumulation buffer; defaults to 0
GL_ACCUM_BLUE_SIZE = C.SDL_GL_ACCUM_BLUE_SIZE // the minimum number of bits for the blue channel of the accumulation buffer; defaults to 0
GL_ACCUM_ALPHA_SIZE = C.SDL_GL_ALPHA_SIZE // the minimum number of bits for the alpha channel of the accumulation buffer; defaults to 0
GL_STEREO = C.SDL_GL_STEREO // whether the output is stereo 3D; defaults to off
GL_MULTISAMPLEBUFFERS = C.SDL_GL_MULTISAMPLEBUFFERS // the number of buffers used for multisample anti-aliasing; defaults to 0; see Remarks for details
GL_MULTISAMPLESAMPLES = C.SDL_GL_MULTISAMPLESAMPLES // the number of samples used around the current pixel used for multisample anti-aliasing; defaults to 0; see Remarks for details
GL_ACCELERATED_VISUAL = C.SDL_GL_ACCELERATED_VISUAL // set to 1 to require hardware acceleration, set to 0 to force software rendering; defaults to allow either
GL_RETAINED_BACKING = C.SDL_GL_RETAINED_BACKING // not used (deprecated)
GL_CONTEXT_MAJOR_VERSION = C.SDL_GL_CONTEXT_MAJOR_VERSION // OpenGL context major version
GL_CONTEXT_MINOR_VERSION = C.SDL_GL_CONTEXT_MINOR_VERSION // OpenGL context minor version
GL_CONTEXT_EGL = C.SDL_GL_CONTEXT_EGL // not used (deprecated)
GL_CONTEXT_FLAGS = C.SDL_GL_CONTEXT_FLAGS // some combination of 0 or more of elements of the GLcontextFlag enumeration; defaults to 0 (https://wiki.libsdl.org/SDL_GLcontextFlag)
GL_CONTEXT_PROFILE_MASK = C.SDL_GL_CONTEXT_PROFILE_MASK // type of GL context (Core, Compatibility, ES); default value depends on platform (https://wiki.libsdl.org/SDL_GLprofile)
GL_SHARE_WITH_CURRENT_CONTEXT = C.SDL_GL_SHARE_WITH_CURRENT_CONTEXT // OpenGL context sharing; defaults to 0
GL_FRAMEBUFFER_SRGB_CAPABLE = C.SDL_GL_FRAMEBUFFER_SRGB_CAPABLE // requests sRGB capable visual; defaults to 0 (>= SDL 2.0.1)
GL_CONTEXT_RELEASE_BEHAVIOR = C.SDL_GL_CONTEXT_RELEASE_BEHAVIOR // sets context the release behavior; defaults to 1 (>= SDL 2.0.4)
GL_CONTEXT_RESET_NOTIFICATION = C.SDL_GL_CONTEXT_RESET_NOTIFICATION // (>= SDL 2.0.6)
GL_CONTEXT_NO_ERROR = C.SDL_GL_CONTEXT_NO_ERROR // (>= SDL 2.0.6)
)
// An enumeration of OpenGL profiles.
// (https://wiki.libsdl.org/SDL_GLprofile)
const (
GL_CONTEXT_PROFILE_CORE = C.SDL_GL_CONTEXT_PROFILE_CORE // OpenGL core profile - deprecated functions are disabled
GL_CONTEXT_PROFILE_COMPATIBILITY = C.SDL_GL_CONTEXT_PROFILE_COMPATIBILITY // OpenGL compatibility profile - deprecated functions are allowed
GL_CONTEXT_PROFILE_ES = C.SDL_GL_CONTEXT_PROFILE_ES // OpenGL ES profile - only a subset of the base OpenGL functionality is available
)
// An enumeration of OpenGL context configuration flags.
// (https://wiki.libsdl.org/SDL_GLcontextFlag)
const (
GL_CONTEXT_DEBUG_FLAG = C.SDL_GL_CONTEXT_DEBUG_FLAG // intended to put the GL into a "debug" mode which might offer better developer insights, possibly at a loss of performance
GL_CONTEXT_FORWARD_COMPATIBLE_FLAG = C.SDL_GL_CONTEXT_FORWARD_COMPATIBLE_FLAG // intended to put the GL into a "forward compatible" mode, which means that no deprecated functionality will be supported, possibly at a gain in performance, and only applies to GL 3.0 and later contexts
GL_CONTEXT_ROBUST_ACCESS_FLAG = C.SDL_GL_CONTEXT_ROBUST_ACCESS_FLAG // intended to require a GL context that supports the GL_ARB_robustness extension--a mode that offers a few APIs that are safer than the usual defaults (think snprintf() vs sprintf())
GL_CONTEXT_RESET_ISOLATION_FLAG = C.SDL_GL_CONTEXT_RESET_ISOLATION_FLAG // intended to require the GL to make promises about what to do in the face of driver or hardware failure
)
//
// Window flash operation
//
const (
FLASH_CANCEL FlashOperation = C.SDL_FLASH_CANCEL // Cancel any window flash state
FLASH_BRIEFLY = C.SDL_FLASH_BRIEFLY // Flash the window briefly to get attention
FLASH_UNTIL_FOCUSED = C.SDL_FLASH_UNTIL_FOCUSED // Flash the window until it gets focus
)
type FlashOperation C.SDL_FlashOperation
// DisplayMode contains the description of a display mode.
// (https://wiki.libsdl.org/SDL_DisplayMode)
type DisplayMode struct {
Format uint32 // one of the PixelFormatEnum values (https://wiki.libsdl.org/SDL_PixelFormatEnum)
W int32 // width, in screen coordinates
H int32 // height, in screen coordinates
RefreshRate int32 // refresh rate (in Hz), or 0 for unspecified
DriverData unsafe.Pointer // driver-specific data, initialize to 0
}
type cDisplayMode C.SDL_DisplayMode
// Window is a type used to identify a window.
type Window C.SDL_Window
// GLContext is an opaque handle to an OpenGL context.
type GLContext C.SDL_GLContext
// GLattr is an OpenGL configuration attribute.
//(https://wiki.libsdl.org/SDL_GLattr)
type GLattr C.SDL_GLattr
// MessageBoxColor contains RGB value used in an MessageBoxColorScheme.
// (https://wiki.libsdl.org/SDL_MessageBoxColor)
type MessageBoxColor struct {
R uint8 // the red component in the range 0-255
G uint8 // the green component in the range 0-255
B uint8 // the blue component in the range 0-255
}
type cMessageBoxColor C.SDL_MessageBoxColor
// MessageBoxColorScheme contains a set of colors to use for message box dialogs.
// (https://wiki.libsdl.org/SDL_MessageBoxColorScheme)
type MessageBoxColorScheme struct {
Colors [5]MessageBoxColor // background, text, button border, button background, button selected
}
type cMessageBoxColorScheme C.SDL_MessageBoxColorScheme
// MessageBoxButtonData contains individual button data for a message box.
// (https://wiki.libsdl.org/SDL_MessageBoxButtonData)
type MessageBoxButtonData struct {
Flags uint32 // MESSAGEBOX_BUTTON_RETURNKEY_DEFAULT, MESSAGEBOX_BUTTON_ESCAPEKEY_DEFAULT
ButtonID int32 // user defined button id (value returned via ShowMessageBox())
Text string // the UTF-8 button text
}
// MessageBoxData contains title, text, window and other data for a message box.
// (https://wiki.libsdl.org/SDL_MessageBoxData)
type MessageBoxData struct {
Flags uint32 // MESSAGEBOX_ERROR, MESSAGEBOX_WARNING, MESSAGEBOX_INFORMATION
Window *Window // parent window or nil
Title string
Message string
Buttons []MessageBoxButtonData
ColorScheme *MessageBoxColorScheme // nil to use system settings
}
func (window *Window) cptr() *C.SDL_Window {
return (*C.SDL_Window)(unsafe.Pointer(window))
}
func (dm *DisplayMode) cptr() *C.SDL_DisplayMode {
return (*C.SDL_DisplayMode)(unsafe.Pointer(dm))
}
func (mc *MessageBoxColor) cptr() *C.SDL_MessageBoxColor {
return (*C.SDL_MessageBoxColor)(unsafe.Pointer(mc))
}
func (mcs *MessageBoxColorScheme) cptr() *C.SDL_MessageBoxColorScheme {
return (*C.SDL_MessageBoxColorScheme)(unsafe.Pointer(mcs))
}
func (mbd *MessageBoxButtonData) cptr() *C.SDL_MessageBoxButtonData {
return (*C.SDL_MessageBoxButtonData)(unsafe.Pointer(mbd))
}
func (md *MessageBoxData) cptr() *C.SDL_MessageBoxData {
return (*C.SDL_MessageBoxData)(unsafe.Pointer(md))
}
func (attr GLattr) c() C.SDL_GLattr {
return C.SDL_GLattr(attr)
}
// GetDisplayName returns the name of a display in UTF-8 encoding.
// (https://wiki.libsdl.org/SDL_GetDisplayName)
func GetDisplayName(displayIndex int) (string, error) {
name := C.SDL_GetDisplayName(C.int(displayIndex))
if name == nil {
return "", GetError()
}
return C.GoString(name), nil
}
// GetNumVideoDisplays returns the number of available video displays.
// (https://wiki.libsdl.org/SDL_GetNumVideoDisplays)
func GetNumVideoDisplays() (int, error) {
n := int(C.SDL_GetNumVideoDisplays())
return n, errorFromInt(n)
}
// GetNumVideoDrivers returns the number of video drivers compiled into SDL.
// (https://wiki.libsdl.org/SDL_GetNumVideoDrivers)
func GetNumVideoDrivers() (int, error) {
n := int(C.SDL_GetNumVideoDrivers())
return n, errorFromInt(n)
}
// GetVideoDriver returns the name of a built in video driver.
// (https://wiki.libsdl.org/SDL_GetVideoDriver)
func GetVideoDriver(index int) string {
return string(C.GoString(C.SDL_GetVideoDriver(C.int(index))))
}
// VideoInit initializes the video subsystem, optionally specifying a video driver.
// (https://wiki.libsdl.org/SDL_VideoInit)
func VideoInit(driverName string) error {
return errorFromInt(int(
C.SDL_VideoInit(C.CString(driverName))))
}
// VideoQuit shuts down the video subsystem, if initialized with VideoInit().
// (https://wiki.libsdl.org/SDL_VideoQuit)
func VideoQuit() {
C.SDL_VideoQuit()
}
// GetCurrentVideoDriver returns the name of the currently initialized video driver.
// (https://wiki.libsdl.org/SDL_GetCurrentVideoDriver)
func GetCurrentVideoDriver() (string, error) {
name := C.SDL_GetCurrentVideoDriver()
if name == nil {
return "", GetError()
}
return C.GoString(name), nil
}
// GetNumDisplayModes returns the number of available display modes.
// (https://wiki.libsdl.org/SDL_GetNumDisplayModes)
func GetNumDisplayModes(displayIndex int) (int, error) {
n := int(C.SDL_GetNumDisplayModes(C.int(displayIndex)))
return n, errorFromInt(n)
}
// GetDisplayBounds returns the desktop area represented by a display, with the primary display located at 0,0.
// (https://wiki.libsdl.org/SDL_GetDisplayBounds)
func GetDisplayBounds(displayIndex int) (rect Rect, err error) {
err = errorFromInt(int(
C.SDL_GetDisplayBounds(C.int(displayIndex), (&rect).cptr())))
return
}
// GetDisplayUsableBounds returns the usable desktop area represented by a display, with the primary display located at 0,0.
// (https://wiki.libsdl.org/SDL_GetDisplayUsableBounds)
func GetDisplayUsableBounds(displayIndex int) (rect Rect, err error) {
err = errorFromInt(int(
C.SDL_GetDisplayUsableBounds(C.int(displayIndex), rect.cptr())))
return
}
// GetDisplayMode returns information about a specific display mode.
// (https://wiki.libsdl.org/SDL_GetDisplayMode)
func GetDisplayMode(displayIndex int, modeIndex int) (mode DisplayMode, err error) {
err = errorFromInt(int(
C.SDL_GetDisplayMode(C.int(displayIndex), C.int(modeIndex), (&mode).cptr())))
return
}
// GetDesktopDisplayMode returns information about the desktop display mode.
// (https://wiki.libsdl.org/SDL_GetDesktopDisplayMode)
func GetDesktopDisplayMode(displayIndex int) (mode DisplayMode, err error) {
err = errorFromInt(int(
C.SDL_GetDesktopDisplayMode(C.int(displayIndex), (&mode).cptr())))
return
}
// GetCurrentDisplayMode returns information about the current display mode.
// (https://wiki.libsdl.org/SDL_GetCurrentDisplayMode)
func GetCurrentDisplayMode(displayIndex int) (mode DisplayMode, err error) {
err = errorFromInt(int(
C.SDL_GetCurrentDisplayMode(C.int(displayIndex), (&mode).cptr())))
return
}
// GetClosestDisplayMode returns the closest match to the requested display mode.
// (https://wiki.libsdl.org/SDL_GetClosestDisplayMode)
func GetClosestDisplayMode(displayIndex int, mode *DisplayMode, closest *DisplayMode) (*DisplayMode, error) {
m := (*DisplayMode)(unsafe.Pointer((C.SDL_GetClosestDisplayMode(C.int(displayIndex), mode.cptr(), closest.cptr()))))
if m == nil {
return nil, GetError()
}
return m, nil
}
// GetDisplayDPI returns the dots/pixels-per-inch for a display.
// (https://wiki.libsdl.org/SDL_GetDisplayDPI)
func GetDisplayDPI(displayIndex int) (ddpi, hdpi, vdpi float32, err error) {
err = errorFromInt(int(
C.SDL_GetDisplayDPI(C.int(displayIndex), (*C.float)(unsafe.Pointer(&ddpi)), (*C.float)(unsafe.Pointer(&hdpi)), (*C.float)(unsafe.Pointer(&vdpi)))))
return
}
// GetDisplayIndex returns the index of the display associated with the window.
// (https://wiki.libsdl.org/SDL_GetWindowDisplayIndex)
func (window *Window) GetDisplayIndex() (int, error) {
i := int(C.SDL_GetWindowDisplayIndex(window.cptr()))
return i, errorFromInt(i)
}
// SetDisplayMode sets the display mode to use when the window is visible at fullscreen.
// (https://wiki.libsdl.org/SDL_SetWindowDisplayMode)
func (window *Window) SetDisplayMode(mode *DisplayMode) error {
return errorFromInt(int(
C.SDL_SetWindowDisplayMode(window.cptr(), mode.cptr())))
}
// GetDisplayMode fills in information about the display mode to use when the window is visible at fullscreen.
// (https://wiki.libsdl.org/SDL_GetWindowDisplayMode)
func (window *Window) GetDisplayMode() (mode DisplayMode, err error) {
err = errorFromInt(int(
C.SDL_GetWindowDisplayMode(window.cptr(), (&mode).cptr())))
return
}
// GetPixelFormat returns the pixel format associated with the window.
// (https://wiki.libsdl.org/SDL_GetWindowPixelFormat)
func (window *Window) GetPixelFormat() (uint32, error) {
f := (uint32)(C.SDL_GetWindowPixelFormat(window.cptr()))
if f == PIXELFORMAT_UNKNOWN {
return f, GetError()
}
return f, nil
}
// CreateWindow creates a window with the specified position, dimensions, and flags.
// (https://wiki.libsdl.org/SDL_CreateWindow)
func CreateWindow(title string, x, y, w, h int32, flags uint32) (*Window, error) {
var _window = C.SDL_CreateWindow(C.CString(title), C.int(x), C.int(y), C.int(w), C.int(h), C.Uint32(flags))
if _window == nil {
return nil, GetError()
}
return (*Window)(unsafe.Pointer(_window)), nil
}
// CreateWindowFrom creates an SDL window from an existing native window.
// (https://wiki.libsdl.org/SDL_CreateWindowFrom)
func CreateWindowFrom(data unsafe.Pointer) (*Window, error) {
_window := C.SDL_CreateWindowFrom(data)
if _window == nil {
return nil, GetError()
}
return (*Window)(unsafe.Pointer(_window)), nil
}
// Destroy destroys the window.
// (https://wiki.libsdl.org/SDL_DestroyWindow)
func (window *Window) Destroy() error {
lastErr := GetError()
ClearError()
C.SDL_DestroyWindow(window.cptr())
err := GetError()
if err != nil {
return err
}
SetError(lastErr)
return nil
}
// GetID returns the numeric ID of the window, for logging purposes.
// (https://wiki.libsdl.org/SDL_GetWindowID)
func (window *Window) GetID() (uint32, error) {
id := uint32(C.SDL_GetWindowID(window.cptr()))
if id == 0 {
return 0, GetError()
}
return id, nil
}
// GetWindowFromID returns a window from a stored ID.
// (https://wiki.libsdl.org/SDL_GetWindowFromID)
func GetWindowFromID(id uint32) (*Window, error) {
_window := C.SDL_GetWindowFromID(C.Uint32(id))
if _window == nil {
return nil, GetError()
}
return (*Window)(unsafe.Pointer((_window))), nil
}
// GetFlags returns the window flags.
// (https://wiki.libsdl.org/SDL_GetWindowFlags)
func (window *Window) GetFlags() uint32 {
return (uint32)(C.SDL_GetWindowFlags(window.cptr()))
}
// SetTitle sets the title of the window.
// (https://wiki.libsdl.org/SDL_SetWindowTitle)
func (window *Window) SetTitle(title string) {
C.SDL_SetWindowTitle(window.cptr(), C.CString(title))
}
// GetTitle returns the title of the window.
// (https://wiki.libsdl.org/SDL_GetWindowTitle)
func (window *Window) GetTitle() string {
return C.GoString(C.SDL_GetWindowTitle(window.cptr()))
}
// SetIcon sets the icon for the window.
// (https://wiki.libsdl.org/SDL_SetWindowIcon)
func (window *Window) SetIcon(icon *Surface) {
C.SDL_SetWindowIcon(window.cptr(), icon.cptr())
}
// SetData associates an arbitrary named pointer with the window.
// (https://wiki.libsdl.org/SDL_SetWindowData)
func (window *Window) SetData(name string, userdata unsafe.Pointer) unsafe.Pointer {
return unsafe.Pointer(C.SDL_SetWindowData(window.cptr(), C.CString(name), userdata))
}
// GetData returns the data pointer associated with the window.
// (https://wiki.libsdl.org/SDL_GetWindowData)
func (window *Window) GetData(name string) unsafe.Pointer {
return unsafe.Pointer(C.SDL_GetWindowData(window.cptr(), C.CString(name)))
}
// SetPosition sets the position of the window.
// (https://wiki.libsdl.org/SDL_SetWindowPosition)
func (window *Window) SetPosition(x, y int32) {
C.SDL_SetWindowPosition(window.cptr(), C.int(x), C.int(y))
}
// GetPosition returns the position of the window.
// (https://wiki.libsdl.org/SDL_GetWindowPosition)
func (window *Window) GetPosition() (x, y int32) {
var _x, _y C.int
C.SDL_GetWindowPosition(window.cptr(), &_x, &_y)
return int32(_x), int32(_y)
}
// SetResizable sets the user-resizable state of the window.
// (https://wiki.libsdl.org/SDL_SetWindowResizable)
func (window *Window) SetResizable(resizable bool) {
C.SDL_SetWindowResizable(window.cptr(), C.SDL_bool(Btoi(resizable)))
}
// SetSize sets the size of the window's client area.
// (https://wiki.libsdl.org/SDL_SetWindowSize)
func (window *Window) SetSize(w, h int32) {
C.SDL_SetWindowSize(window.cptr(), C.int(w), C.int(h))
}
// GetSize returns the size of the window's client area.
// (https://wiki.libsdl.org/SDL_GetWindowSize)
func (window *Window) GetSize() (w, h int32) {
var _w, _h C.int
C.SDL_GetWindowSize(window.cptr(), &_w, &_h)
return int32(_w), int32(_h)
}
// SetMinimumSize sets the minimum size of the window's client area.
// (https://wiki.libsdl.org/SDL_SetWindowMinimumSize)
func (window *Window) SetMinimumSize(minW, minH int32) {
C.SDL_SetWindowMinimumSize(window.cptr(), C.int(minW), C.int(minH))
}
// GetMinimumSize returns the minimum size of the window's client area.
// (https://wiki.libsdl.org/SDL_GetWindowMinimumSize)
func (window *Window) GetMinimumSize() (w, h int32) {
var _w, _h C.int
C.SDL_GetWindowMinimumSize(window.cptr(), &_w, &_h)
return int32(_w), int32(_h)
}
// SetMaximumSize sets the maximum size of the window's client area.
// (https://wiki.libsdl.org/SDL_SetWindowMaximumSize)
func (window *Window) SetMaximumSize(maxW, maxH int32) {
C.SDL_SetWindowMaximumSize(window.cptr(), C.int(maxW), C.int(maxH))
}
// GetMaximumSize returns the maximum size of the window's client area.
// (https://wiki.libsdl.org/SDL_GetWindowMaximumSize)
func (window *Window) GetMaximumSize() (w, h int32) {
var _w, _h C.int
C.SDL_GetWindowMaximumSize(window.cptr(), &_w, &_h)
return int32(_w), int32(_h)
}
// SetBordered sets the border state of the window.
// (https://wiki.libsdl.org/SDL_SetWindowBordered)
func (window *Window) SetBordered(bordered bool) {
C.SDL_SetWindowBordered(window.cptr(), C.SDL_bool(Btoi(bordered)))
}
// Show shows the window.
// (https://wiki.libsdl.org/SDL_ShowWindow)
func (window *Window) Show() {
C.SDL_ShowWindow(window.cptr())
}
// Hide hides the window.
// (https://wiki.libsdl.org/SDL_HideWindow)
func (window *Window) Hide() {
C.SDL_HideWindow(window.cptr())
}
// Raise raises the window above other windows and set the input focus.
// (https://wiki.libsdl.org/SDL_RaiseWindow)
func (window *Window) Raise() {
C.SDL_RaiseWindow(window.cptr())
}
// Maximize makes the window as large as possible.
// (https://wiki.libsdl.org/SDL_MaximizeWindow)
func (window *Window) Maximize() {
C.SDL_MaximizeWindow(window.cptr())
}
// Minimize minimizes the window to an iconic representation.
// (https://wiki.libsdl.org/SDL_MinimizeWindow)
func (window *Window) Minimize() {
C.SDL_MinimizeWindow(window.cptr())
}
// Restore restores the size and position of a minimized or maximized window.
// (https://wiki.libsdl.org/SDL_RestoreWindow)
func (window *Window) Restore() {
C.SDL_RestoreWindow(window.cptr())
}
// SetFullscreen sets the window's fullscreen state.
// (https://wiki.libsdl.org/SDL_SetWindowFullscreen)
func (window *Window) SetFullscreen(flags uint32) error {
return errorFromInt(int(
C.SDL_SetWindowFullscreen(window.cptr(), C.Uint32(flags))))
}
// GetSurface returns the SDL surface associated with the window.
// (https://wiki.libsdl.org/SDL_GetWindowSurface)
func (window *Window) GetSurface() (*Surface, error) {
surface := (*Surface)(unsafe.Pointer(C.SDL_GetWindowSurface(window.cptr())))
if surface == nil {
return nil, GetError()
}
return surface, nil
}
// UpdateSurface copies the window surface to the screen.
// (https://wiki.libsdl.org/SDL_UpdateWindowSurface)
func (window *Window) UpdateSurface() error {
return errorFromInt(int(
C.SDL_UpdateWindowSurface(window.cptr())))
}
// UpdateSurfaceRects copies areas of the window surface to the screen.
// (https://wiki.libsdl.org/SDL_UpdateWindowSurfaceRects)
func (window *Window) UpdateSurfaceRects(rects []Rect) error {
return errorFromInt(int(
C.SDL_UpdateWindowSurfaceRects(window.cptr(), rects[0].cptr(), C.int(len(rects)))))
}
// SetGrab sets the window's input grab mode.
// (https://wiki.libsdl.org/SDL_SetWindowGrab)
func (window *Window) SetGrab(grabbed bool) {
C.SDL_SetWindowGrab(window.cptr(), C.SDL_bool((Btoi(grabbed))))
}
// GetGrab returns the window's input grab mode.
// (https://wiki.libsdl.org/SDL_GetWindowGrab)
func (window *Window) GetGrab() bool {
return C.SDL_GetWindowGrab(window.cptr()) != 0
}
// SetBrightness sets the brightness (gamma multiplier) for the display that owns the given window.
// (https://wiki.libsdl.org/SDL_SetWindowBrightness)
func (window *Window) SetBrightness(brightness float32) error {
return errorFromInt(int(
C.SDL_SetWindowBrightness(window.cptr(), C.float(brightness))))
}
// GetBrightness returns the brightness (gamma multiplier) for the display that owns the given window.
// (https://wiki.libsdl.org/SDL_GetWindowBrightness)
func (window *Window) GetBrightness() float32 {
return float32(C.SDL_GetWindowBrightness(window.cptr()))
}
// SetGammaRamp sets the gamma ramp for the display that owns the given window.
// (https://wiki.libsdl.org/SDL_SetWindowGammaRamp)
func (window *Window) SetGammaRamp(red, green, blue *[256]uint16) error {
return errorFromInt(int(
C.SDL_SetWindowGammaRamp(
window.cptr(),
(*C.Uint16)(unsafe.Pointer(red)),
(*C.Uint16)(unsafe.Pointer(green)),
(*C.Uint16)(unsafe.Pointer(blue)))))
}
// GetGammaRamp returns the gamma ramp for the display that owns a given window.
// (https://wiki.libsdl.org/SDL_GetWindowGammaRamp)
func (window *Window) GetGammaRamp() (red, green, blue *[256]uint16, err error) {
code := int(C.SDL_GetWindowGammaRamp(
window.cptr(),
(*C.Uint16)(unsafe.Pointer(red)),
(*C.Uint16)(unsafe.Pointer(green)),
(*C.Uint16)(unsafe.Pointer(blue))))
return red, green, blue, errorFromInt(code)
}
// SetWindowOpacity sets the opacity of the window.
// (https://wiki.libsdl.org/SDL_SetWindowOpacity)
func (window *Window) SetWindowOpacity(opacity float32) error {
return errorFromInt(int(
C.SDL_SetWindowOpacity(window.cptr(), C.float(opacity))))
}
// GetWindowOpacity returns the opacity of the window.
// (https://wiki.libsdl.org/SDL_GetWindowOpacity)
func (window *Window) GetWindowOpacity() (opacity float32, err error) {
return opacity, errorFromInt(int(
C.SDL_GetWindowOpacity(window.cptr(), (*C.float)(unsafe.Pointer(&opacity)))))
}
// ShowSimpleMessageBox displays a simple modal message box.
// (https://wiki.libsdl.org/SDL_ShowSimpleMessageBox)
func ShowSimpleMessageBox(flags uint32, title, message string, window *Window) error {
_title := C.CString(title)
defer C.free(unsafe.Pointer(_title))
_message := C.CString(message)
defer C.free(unsafe.Pointer(_message))
return errorFromInt(int(
C.SDL_ShowSimpleMessageBox(C.Uint32(flags), _title, _message, window.cptr())))
}
// ShowMessageBox creates a modal message box.
// (https://wiki.libsdl.org/SDL_ShowMessageBox)
func ShowMessageBox(data *MessageBoxData) (buttonid int32, err error) {
_title := C.CString(data.Title)
defer C.free(unsafe.Pointer(_title))
_message := C.CString(data.Message)
defer C.free(unsafe.Pointer(_message))
var cbuttons []C.SDL_MessageBoxButtonData
var cbtntexts []*C.char
defer func(texts []*C.char) {
for _, t := range texts {
C.free(unsafe.Pointer(t))
}
}(cbtntexts)
for _, btn := range data.Buttons {
ctext := C.CString(btn.Text)
cbtn := C.SDL_MessageBoxButtonData{
flags: C.Uint32(btn.Flags),
buttonid: C.int(btn.ButtonID),
text: ctext,
}
cbuttons = append(cbuttons, cbtn)
cbtntexts = append(cbtntexts, ctext)
}
var buttonPtr *C.SDL_MessageBoxButtonData
if len(cbuttons) > 0 {
buttonPtr = &cbuttons[0]
}
cdata := C.SDL_MessageBoxData{
flags: C.Uint32(data.Flags),
window: data.Window.cptr(),
title: _title,
message: _message,
numbuttons: C.int(len(data.Buttons)),
buttons: buttonPtr,
colorScheme: data.ColorScheme.cptr(),
}
buttonid = int32(C.ShowMessageBox(cdata))
return buttonid, errorFromInt(int(buttonid))
}
// IsScreenSaverEnabled reports whether the screensaver is currently enabled.
// (https://wiki.libsdl.org/SDL_IsScreenSaverEnabled)
func IsScreenSaverEnabled() bool {
return C.SDL_IsScreenSaverEnabled() != 0
}
// EnableScreenSaver allows the screen to be blanked by a screen saver.
// (https://wiki.libsdl.org/SDL_EnableScreenSaver)
func EnableScreenSaver() {
C.SDL_EnableScreenSaver()
}
// DisableScreenSaver prevents the screen from being blanked by a screen saver.
// (https://wiki.libsdl.org/SDL_DisableScreenSaver)
func DisableScreenSaver() {
C.SDL_DisableScreenSaver()
}
// GLLoadLibrary dynamically loads an OpenGL library.
// (https://wiki.libsdl.org/SDL_GL_LoadLibrary)
func GLLoadLibrary(path string) error {
return errorFromInt(int(
C.SDL_GL_LoadLibrary(C.CString(path))))
}
// GLGetProcAddress returns an OpenGL function by name.
// (https://wiki.libsdl.org/SDL_GL_GetProcAddress)
func GLGetProcAddress(proc string) unsafe.Pointer {
return unsafe.Pointer(C.SDL_GL_GetProcAddress(C.CString(proc)))
}
// GLUnloadLibrary unloads the OpenGL library previously loaded by GLLoadLibrary().
// (https://wiki.libsdl.org/SDL_GL_UnloadLibrary)
func GLUnloadLibrary() {
C.SDL_GL_UnloadLibrary()
}
// GLExtensionSupported reports whether an OpenGL extension is supported for the current context.
// (https://wiki.libsdl.org/SDL_GL_ExtensionSupported)
func GLExtensionSupported(extension string) bool {
return C.SDL_GL_ExtensionSupported(C.CString(extension)) != 0
}
// GLSetAttribute sets an OpenGL window attribute before window creation.
// (https://wiki.libsdl.org/SDL_GL_SetAttribute)
func GLSetAttribute(attr GLattr, value int) error {
return errorFromInt(int(
C.SDL_GL_SetAttribute(attr.c(), C.int(value))))
}
// GLGetAttribute returns the actual value for an attribute from the current context.
// (https://wiki.libsdl.org/SDL_GL_GetAttribute)
func GLGetAttribute(attr GLattr) (int, error) {