summaryrefslogtreecommitdiff
path: root/doc/api.texi
blob: 84c2600487c04a3443eeb9b498627082fd1e3026 (plain)
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
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
@menu
* Basics::                      Initialization and other basic things.
* Window Management::           Working with the window system.
* Input::                       Keyboard, mouse, joystick input.
* Events::                      Asynchronous event handling.
* Surfaces::                    Software rendering.
* Rendering::                   Hardware accelerated rendering.
* Images::                      Loading and saving images.
* Sound::                       Sound effects and music.
* Fonts::                       Truetype and bitmap font rendering.
@end menu

@node Basics
@section Basics

@example
(use-modules (sdl2))
@end example

@deffn {Scheme Procedure} sdl-init [@var{subsystems}]
Initialize the SDL library.  This must be called before using any
other SDL procedure.

@var{subsystems} is an optional list of symbols that specifies the
subsystems to initialize.  All subsystems are initialized by default.
The possible flags are @code{timer}, @code{audio}, @code{video},
@code{haptic}, @code{game-controller}, and @code{events}.
@end deffn

@deffn {Scheme Procedure} sdl-quit
Quit all activated SDL subsystems.  This procedure should be called
upon all exit conditions.
@end deffn

@deffn {Scheme Procedure} sdl-version
Return a three element list containing the major, minor, and patch
version of the linked SDL library.
@end deffn

@deffn {Scheme Procedure} sdl-ticks
Return the number of milliseconds since the SDL library was
initialized.
@end deffn

@node Window Management
@section Window Management

@menu
* Windows::                     Window manipulation.
* OpenGL::                      OpenGL contexts.
@end menu

@example
(use-modules (sdl2 video))
@end example

@node Windows
@subsection Windows

@deffn {Scheme Procedure} make-window [#:title "Guile SDL2 Window"] @
                          [#:position (#f #f)] @
                          [#:size (640 480)] @
                          [#:maximize? #f] @
                          [#:minimize? #f] @
                          [#:opengl? #f] @
                          [#:border? #t] @
                          [#:fullscreen? #f] @
                          [#:fullscreen-desktop? #f] @
                          [#:grab-input? #f] @
                          [#:high-dpi? #f]
Create a new window named @var{title} with dimensions @var{size} located
at @var{position} on the display.  @var{position} and @var{size} are
two-element lists in the form @code{(x y)}, where each coordinate is
measured in pixels.  In the case of @var{position}, a coordinate may use
the special symbol @var{center} to indicate that the window should be
centered on that axis, or @code{#f} to indicate that it does not matter
where the window is located on that axis.
@end deffn

@deffn {Scheme Procedure} close-window! window
Close @var{window}.
@end deffn

@deffn {Scheme Procedure} call-with-window window proc
Call @var{proc} with @var{window}, an SDL window object, and close it
when @var{proc} returns or otherwise exits.
@end deffn

@deffn {Scheme Procedure} window-title window
Return the title for @var{window}.
@end deffn

@deffn {Scheme Procedure} window-size window
Return the dimensions of @var{window}.
@end deffn

@deffn {Scheme Procedure} window-position window
Return the position of @var{window} on the display.
@end deffn

@deffn {Scheme Procedure} window-id window
Return the numeric ID of @var{window}.
@end deffn

@deffn {Scheme Procedure} id->window id
Return the window corresponding to @var{ID}, a positive integer, or
@code{#f} if there is no such window.
@end deffn

@deffn {Scheme Procedure} hide-window! window
Hide @var{window}.
@end deffn

@deffn {Scheme Procedure} show-window! window
Show @var{window} and focus on it.
@end deffn

@deffn {Scheme Procedure} maximize-window! window
Make @var{window} as large as possible.
@end deffn

@deffn {Scheme Procedure} minimize-window! window
Shrink @var{window} to an iconic representation.
@end deffn

@deffn {Scheme Procedure} raise-window! window
Raise @var{window} above all other windows and set input focus.
@end deffn

@deffn {Scheme Procedure} restore-window! window
Restore the size and position of a minimized or maximized @var{window}.
@end deffn

@deffn {Scheme Procedure} set-window-border! window border?
When @var{border?}, draw the usual border around @var{window}, otherwise
remove the border.
@end deffn

@deffn {Scheme Procedure} set-window-title! window title
Set the title of @var{window} to the string @var{title}.
@end deffn

@deffn {Scheme Procedure} set-window-position! window position
Set the position of @var{window} to @var{position}, a two-element list
of (x,y) coordinates measured in pixels.
@end deffn

@deffn {Scheme Procedure} set-window-size! window size
Set the dimensions of @var{window} to @var{size}, a two-element list of
(width,height) coordinates measured in pixels.
@end deffn

@deffn {Scheme Procedure} set-window-fullscreen! window fullscreen? [#:desktop?]
Toggle fullscreen mode on/off for @var{window}.  If @var{fullscreen?},
fullscreen mode is activated, otherwise it is deactivated.  If
@var{fullscreen?} and @var{desktop?}, a special "fake" fullscreen mode
is used that takes the size of the desktop.
@end deffn

@node OpenGL
@subsection OpenGL

@deffn {Scheme Procedure} make-gl-context window
Create an OpenGL context for @var{window}.
@end deffn

@deffn {Scheme Procedure} delete-gl-context! context
Delete @var{context}, an OpenGL context object.
@end deffn

@deffn {Scheme Procedure} call-with-gl-context window proc
Call @var{proc} with a new OpenGL context created for @var{window}, and
close the context when @var{proc} returns or otherwise exits.
@end deffn

@deffn {Scheme Procedure} swap-gl-window window
Update @var{window} with OpenGL rendering.
@end deffn

@deffn {Scheme Procedure} set-gl-attribute! attr value
Set the OpenGL attribute represented by the symbol @var{attr} to
@var{value}.  Possible values for @var{attr} are:

@itemize
@item @code{red-size}
@item @code{green-size}
@item @code{blue-size}
@item @code{alpha-size}
@item @code{buffer-size}
@item @code{double-buffer}
@item @code{depth-size}
@item @code{stencil-size}
@item @code{accum-red-size}
@item @code{accum-green-size}
@item @code{accum-blue-size}
@item @code{stereo}
@item @code{multisample-buffers}
@item @code{multisample-samples}
@item @code{retained-backing}
@item @code{context-major-version}
@item @code{context-minor-version}
@item @code{context-egl}
@item @code{context-flags}
@item @code{context-profile-mask}
@item @code{share-with-current-context}
@item @code{framebuffer-srgb-capable}
@end itemize

@end deffn

@deffn {Scheme Procedure} set-gl-swap-interval! interval
Set the framebuffer swap interval for the current OpenGL context to the
type indicated by the symbol @var{interval}.  Possible values of
@var{interval} are:

@itemize
@item @code{immediate}, for immediate updates
@item @code{vsync}, for updates synchronized with the screen's vertical retrace
@item @code{late-swap-tear}, for late swap tearing
@end itemize

Late swap tearing works the same as vsync, but if the vertical retrace
has been missed for a given frame, buffers are swapped immediately,
which might be less jarring for the user during occasional framerate
drops.
@end deffn

@node Input
@section Input

@menu
* Keyboard::                    Keyboard input.
* Mouse::                       Mouse input.
* Joysticks::                   Joystick input.
* Game Controllers::            Game controller input.
@end menu

@node Keyboard
@subsection Keyboard

@example
(use-modules (sdl2 input keyboard))
@end example

@deffn {Scheme Procedure} key-pressed? key
Return @code{#t} if @var{key} is currently being pressed.
@end deffn

@deffn {Scheme Procedure} key-released? key
Return @code{#t} is @var{key} is not currently being pressed.
@end deffn

@node Mouse
@subsection Mouse

@example
(use-modules (sdl2 input mouse))
@end example

@deffn {Scheme Procedure} mouse-x
Return the x coordinate of the mouse cursor.
@end deffn

@deffn {Scheme Procedure} mouse-y
Return the y coordinate of the mouse cursor.
@end deffn

@deffn {Scheme Procedure} mouse-button-pressed? button
Return @code{#t} if @var{button} is currently being pressed.
@end deffn

@deffn {Scheme Procedure} mouse-button-released? button
Return @code{#t} if @var{button} is not currently being pressed.
@end deffn

@node Joysticks
@subsection Joysticks

@example
(use-modules (sdl2 input joystick))
@end example

@deffn {Scheme Procedure} num-joysticks
Return the current number of connected joystick devices.
@end deffn

@deffn {Scheme Procedure} open-joystick device-index
Return a joystick object for the physical joystick device associated
with @var{device-index}.
@end deffn

@deffn {Scheme Procedure} close-joystick joystick
Close @var{joystick}.
@end deffn

@deffn {Scheme Procedure} joystick-instance-id joystick
Return the instance id of @var{joystick}.
@end deffn

@deffn {Scheme Procedure} joystick-power-level joystick
Return the symbolic battery power level for @var{joystick}, either
@code{unknown}, @code{empty}, @code{low}, @code{medium}, @code{full},
or @code{wired}.
@end deffn

@deffn {Scheme Procedure} joystick-num-axes joystick
Return the number of axes for @var{joystick}.
@end deffn

@deffn {Scheme Procedure} joystick-num-balls joystick
Return the number of balls for @var{joystick}.
@end deffn

@deffn {Scheme Procedure} joystick-num-buttons joystick
Return the number of buttons for @var{joystick}.
@end deffn

@deffn {Scheme Procedure} joystick-num-hats joystick
Return the number of hats for @var{joystick}.
@end deffn

@node Game Controllers
@subsection Game Controllers

@example
(use-modules (sdl2 input game-controller))
@end example

@deffn {Scheme Procedure} load-game-controller-mappings! file
Load game controller mapping from @var{file} and return the number of
mappings added this way.

See @url{https://raw.github.com/gabomdq/SDL_GameControllerDB/master/gamecontrollerdb.txt}
for a community maintained controller mapping file.
@end deffn

@deffn {Scheme Procedure} open-game-controller joystick-index
Return a game controller object for the physical joystick device associated
with the @var{joystick-index}.
@end deffn

@deffn {Scheme Procedure} close-game-controller controller
Close @var{controller}.
@end deffn

@deffn {Scheme Procedure} game-controller? controller
Close @var{controller}.
@end deffn

@deffn {Scheme Procedure} game-controller-attached? controller
Return @code{#t} if @var{controller} is currently in use.
@end deffn

@deffn {Scheme Procedure} game-controller-joystick controller
Return the underlying joystick object associated with @var{controller}.
@end deffn

@deffn {Scheme Procedure} game-controller-name controller
Return the human readable name for @var{controller}.
@end deffn

@deffn {Scheme Procedure} game-controller-axis controller axis
Return a number in the range [-32768, 32767] representing the
current state of @var{axis} on @var{controller}.

@var{axis} may be one of the following symbols:
@itemize
@item @code{left-x}
@item @code{left-y}
@item @code{right-x}
@item @code{right-y}
@item @code{trigger-left}
@item @code{trigger-right}
@end itemize
@end deffn

@deffn {Scheme Procedure} game-controller-button-pressed? controller button
Return @code{#t} if @var{button} is pressed on @var{controller}.

@var{button} may be one of the following symbols:
@itemize
@item @code{a}
@item @code{b}
@item @code{x}
@item @code{y}
@item @code{back}
@item @code{guide}
@item @code{start}
@item @code{left-stick}
@item @code{right-stick}
@item @code{left-shoulder}
@item @code{right-shoulder}
@item @code{dpad-up}
@item @code{dpad-down}
@item @code{dpad-left}
@item @code{dpad-right}
@end itemize
@end deffn

@deffn {Scheme Procedure} game-controller-index? joystick-index
Return @code{#t} if @var{joystick-index} is a valid game controller index.
@end deffn

@node Events
@section Events

@example
(use-modules (sdl2 events))
@end example

@deffn {Scheme Procedure} make-quit-event timestamp
@end deffn

@deffn {Scheme Procedure} quit-event? e
Return @code{#t} if @var{e} is a quit event.
@end deffn

@deffn {Scheme Procedure} quit-event-timestamp e
@end deffn

@deffn {Scheme Procedure} make-window-event timestamp window-id type vector
@end deffn

@deffn {Scheme Procedure} window-event? e
Return @code{#t} if @var{e} is a window event.
@end deffn

@deffn {Scheme Procedure} window-shown-event? e
Return @code{#t} if @var{e} is a window shown event.
@end deffn

@deffn {Scheme Procedure} window-hidden-event? e
Return @code{#t} if @var{e} is a window hidden event.
@end deffn

@deffn {Scheme Procedure} window-exposed-event? e
Return @code{#t} if @var{e} is a window exposed event.
@end deffn

@deffn {Scheme Procedure} window-moved-event? e
Return @code{#t} if @var{e} is a window moved event.
@end deffn

@deffn {Scheme Procedure} window-resized-event? e
Return @code{#t} if @var{e} is a window resized event.
@end deffn

@deffn {Scheme Procedure} window-size-changed-event? e
Return @code{#t} if @var{e} is a window size changed event.
@end deffn

@deffn {Scheme Procedure} window-minimized-event? e
Return @code{#t} if @var{e} is a window minimized event.
@end deffn

@deffn {Scheme Procedure} window-maximized-event? e
Return @code{#t} if @var{e} is a window maximized event.
@end deffn

@deffn {Scheme Procedure} window-restored-event? e
Return @code{#t} if @var{e} is a window restored event.
@end deffn

@deffn {Scheme Procedure} window-enter-event? e
Return @code{#t} if @var{e} is a window enter event.
@end deffn

@deffn {Scheme Procedure} window-leave-event? e
Return @code{#t} if @var{e} is a window leave event.
@end deffn

@deffn {Scheme Procedure} window-focus-gained-event? e
Return @code{#t} if @var{e} is a window focus gained event.
@end deffn

@deffn {Scheme Procedure} window-focus-lost-event? e
Return @code{#t} if @var{e} is a window focus lost event.
@end deffn

@deffn {Scheme Procedure} window-closed-event? e
Return @code{#t} if @var{e} is a window closed event.
@end deffn

@deffn {Scheme Procedure} window-event-timestamp e
@end deffn

@deffn {Scheme Procedure} window-event-window-id e
@end deffn

@deffn {Scheme Procedure} window-event-type e
@end deffn

@deffn {Scheme Procedure} window-event-vector e
@end deffn

@deffn {Scheme Procedure} make-keyboard-event timestamp @
                                              window-id @
                                              pressed? @
                                              repeat? @
                                              key @
                                              scancode @
                                              modifiers
@end deffn

@deffn {Scheme Procedure} keyboard-event? e
Return @code{#t} if @var{e} is a keyboard event.
@end deffn

@deffn {Scheme Procedure} keyboard-down-event? e
Return @code{#t} if @var{e} is a key press event.
@end deffn

@deffn {Scheme Procedure} keyboard-up-event? e
Return @code{#t} if @var{e} is a key release event.
@end deffn

@deffn {Scheme Procedure} keyboard-event-timestamp e
@end deffn

@deffn {Scheme Procedure} keyboard-event-window-id e
@end deffn

@deffn {Scheme Procedure} keyboard-event-pressed? e
@end deffn

@deffn {Scheme Procedure} keyboard-event-repeat? e
@end deffn

@deffn {Scheme Procedure} keyboard-event-key e
@end deffn

@deffn {Scheme Procedure} keyboard-event-scancode e
@end deffn

@deffn {Scheme Procedure} keyboard-event-modifiers e
@end deffn

@deffn {Scheme Procedure} make-text-input-event timestamp window-id text
@end deffn

@deffn {Scheme Procedure} text-input-event? e
Return @code{#t} if @var{e} is a text input event.
@end deffn

@deffn {Scheme Procedure} text-input-event-timestamp e
@end deffn

@deffn {Scheme Procedure} text-input-event-window-id e
@end deffn

@deffn {Scheme Procedure} text-input-event-text e
@end deffn

@deffn {Scheme Procedure} make-mouse-button-event timestamp @
                                                  window-id @
                                                  which @
                                                  button @
                                                  pressed? @
                                                  clicks @
                                                  x @
                                                  y
@end deffn

@deffn {Scheme Procedure} mouse-button-event? e
Return @code{#t} if @var{e} is a mouse button event.
@end deffn

@deffn {Scheme Procedure} mouse-button-down-event? e
Return @code{#t} if @var{e} is a mouse button down event.
@end deffn

@deffn {Scheme Procedure} mouse-button-up-event? e
Return @code{#t} if @var{e} is a mouse button up event.
@end deffn

@deffn {Scheme Procedure} mouse-button-event-timestamp e
@end deffn

@deffn {Scheme Procedure} mouse-button-event-window-id e
@end deffn

@deffn {Scheme Procedure} mouse-button-event-which e
@end deffn

@deffn {Scheme Procedure} mouse-button-event-button e
@end deffn

@deffn {Scheme Procedure} mouse-button-event-pressed? e
@end deffn

@deffn {Scheme Procedure} mouse-button-event-clicks e
@end deffn

@deffn {Scheme Procedure} mouse-button-event-x e
@end deffn

@deffn {Scheme Procedure} mouse-button-event-y e
@end deffn

@deffn {Scheme Procedure} make-mouse-motion-event timestamp @
                                                  window-id @
                                                  which @
                                                  buttons @
                                                  x @
                                                  y @
                                                  x-rel @
                                                  y-rel
@end deffn

@deffn {Scheme Procedure} mouse-motion-event? e
Return @code{#t} if @var{e} is a mouse motion event.
@end deffn

@deffn {Scheme Procedure} mouse-motion-event-timestamp e
@end deffn

@deffn {Scheme Procedure} mouse-motion-event-window-id e
@end deffn

@deffn {Scheme Procedure} mouse-motion-event-which e
@end deffn

@deffn {Scheme Procedure} mouse-motion-event-buttons e
@end deffn

@deffn {Scheme Procedure} mouse-motion-event-x e
@end deffn

@deffn {Scheme Procedure} mouse-motion-event-y e
@end deffn

@deffn {Scheme Procedure} mouse-motion-event-x-rel e
@end deffn

@deffn {Scheme Procedure} mouse-motion-event-y-rel e
@end deffn

@deffn {Scheme Procedure} make-joystick-axis-event timestamp which axis value
@end deffn

@deffn {Scheme Procedure} joystick-axis-event? e
Return @code{#t} if @var{e} is a joystick axis event.
@end deffn

@deffn {Scheme Procedure} joystick-axis-event-timestamp e
@end deffn

@deffn {Scheme Procedure} joystick-axis-event-which e
@end deffn

@deffn {Scheme Procedure} joystick-axis-event-button e
@end deffn

@deffn {Scheme Procedure} joystick-axis-event-pressed? e
@end deffn

@deffn {Scheme Procedure} make-joystick-ball-event timestamp @
                                                   which @
                                                   ball @
                                                   x-rel @
                                                   y-rel
@end deffn

@deffn {Scheme Procedure} joystick-ball-event? e
Return @code{#t} if @var{e} is a joystick ball event.
@end deffn

@deffn {Scheme Procedure} joystick-ball-event-timestamp e
@end deffn

@deffn {Scheme Procedure} joystick-ball-event-which e
@end deffn

@deffn {Scheme Procedure} joystick-ball-event-ball e
@end deffn

@deffn {Scheme Procedure} joystick-ball-event-x-rel e
@end deffn

@deffn {Scheme Procedure} joystick-ball-event-y-rel e
@end deffn

@deffn {Scheme Procedure} make-joystick-hat-event timestamp which hat value
@end deffn

@deffn {Scheme Procedure} joystick-hat-event? e
Return @code{#t} if @var{e} is a joystick hat event.
@end deffn

@deffn {Scheme Procedure} joystick-hat-event-timestamp e
@end deffn

@deffn {Scheme Procedure} joystick-hat-event-which e
@end deffn

@deffn {Scheme Procedure} joystick-hat-event-hat e
@end deffn

@deffn {Scheme Procedure} joystick-hat-event-value e
@end deffn

@deffn {Scheme Procedure} make-joystick-device-event timestamp which action
@end deffn

@deffn {Scheme Procedure} joystick-device-event? e
Return @code{#t} if @var{e} is a joystick device event.
@end deffn

@deffn {Scheme Procedure} joystick-device-event-timestamp e
@end deffn

@deffn {Scheme Procedure} joystick-device-event-which e
@end deffn

@deffn {Scheme Procedure} joystick-device-event-action e
@end deffn

@deffn {Scheme Procedure} make-controller-axis-event timestamp which axis value
@end deffn

@deffn {Scheme Procedure} controller-axis-event? e
Return @code{#t} if @var{e} is a game controller axis event.
@end deffn

@deffn {Scheme Procedure} controller-axis-event-timestamp e
@end deffn

@deffn {Scheme Procedure} controller-axis-event-which e
@end deffn

@deffn {Scheme Procedure} controller-axis-event-axis e
@end deffn

@deffn {Scheme Procedure} controller-axis-event-value e
@end deffn

@deffn {Scheme Procedure} make-controller-button-event timestamp @
                                                       which @
                                                       button @
                                                       pressed?
@end deffn

@deffn {Scheme Procedure} controller-button-event? e
Return @code{#t} if @var{event} is a game controller button event.
@end deffn

@deffn {Scheme Procedure} controller-button-down-event? e
@end deffn

@deffn {Scheme Procedure} controller-button-up-event? e
@end deffn

@deffn {Scheme Procedure} controller-button-event-timestamp e
@end deffn

@deffn {Scheme Procedure} controller-button-event-which e
@end deffn

@deffn {Scheme Procedure} controller-button-event-button e
@end deffn

@deffn {Scheme Procedure} controller-button-event-pressed? e
@end deffn

@deffn {Scheme Procedure} make-controller-device-event timestamp which action
@end deffn

@deffn {Scheme Procedure} controller-device-event? e
Return @code{#t} if @var{event} is a game controller device event.
@end deffn

@deffn {Scheme Procedure} controller-added-event? e
Return @code{#t} if @var{event} is a game controller device event with the
'added' action.
@end deffn

@deffn {Scheme Procedure} controller-removed-event? e
Return @code{#t} if @var{event} is a game controller device event with the
'removed' action.
@end deffn

@deffn {Scheme Procedure} controller-remapped-event? e
Return @code{#t} if @var{event} is a game controller device event with the
'remapped' action.
@end deffn

@deffn {Scheme Procedure} controller-device-event-timestamp e
@end deffn

@deffn {Scheme Procedure} controller-device-event-which e
@end deffn

@deffn {Scheme Procedure} controller-device-event-action e
@end deffn

@deffn {Scheme Procedure} poll-event
@end deffn

@node Surfaces
@section Surfaces

@example
(use-modules (sdl2 surface))
@end example

@deffn {Scheme Procedure} color? c
Return @code{#t} if @var{c} is a color.
@end deffn

@deffn {Scheme Procedure} color-r c
@end deffn

@deffn {Scheme Procedure} color-g c
@end deffn

@deffn {Scheme Procedure} color-b c
@end deffn

@deffn {Scheme Procedure} color-a c
@end deffn

@deffn {Scheme Procedure} palette? p
Return @code{#t} if @var{p} is a palette.
@end deffn

@deffn {Scheme Procedure} palette-length palette
Return the number of colors in @var{palette}.
@end deffn

@deffn {Scheme Procedure} palette-colors palette
Return the colors in @var{palette}.
@end deffn

@deffn {Scheme Procedure} pixel-format? pf
Return @code{#t} if @var{pf} is a pixel format.
@end deffn

@deffn {Scheme Procedure} pixel-format-name pf
Return the symbolic name of the pixel format @var{pf}.
@end deffn

@deffn {Scheme Procedure} pixel-format-palette pf
Return the palette for the pixel format @var{pf}.
@end deffn

@deffn {Scheme Procedure} pixel-format-bits-per-pixel pf
Return the number of bits per pixel for the pixel format @var{pf}.
@end deffn

@deffn {Scheme Procedure} pixel-format-bytes-per-pixel pf
Return the number of bytes per pixel for the pixel format @var{pf}.
@end deffn

@deffn {Scheme Procedure} pixel-format-red-mask pf
Return the bitmask for the red component of a pixel in the pixel format
@var{pf}.
@end deffn

@deffn {Scheme Procedure} pixel-format-green-mask pf
Return the bitmask for the green component of a pixel in the pixel format
@var{pf}.
@end deffn

@deffn {Scheme Procedure} pixel-format-blue-mask pf
Return the bitmask for the blue component of a pixel in the pixel format
@var{pf}.
@end deffn

@deffn {Scheme Procedure} pixel-format-alpha-mask pf
Return the bitmask for the alpha component of a pixel in the pixel format
@var{pf}.
@end deffn

@deffn {Scheme Procedure} make-rgb-surface width height depth
Create a new SDL surface with the dimensions @var{width} and @var{height} and
@var{depth} bits per pixel.
@end deffn

@deffn {Scheme Procedure} bytevector->surface bv width height depth pitch
Convert @var{bv}, a bytevector of pixel data with dimensions
@var{width}x@var{height}, to an SDL surface.  Each pixel is @var{depth} bits in
size, and each row of pixels is @var{pitch} bytes in size.
@end deffn

@deffn {Scheme Procedure} delete-surface! surface
Free the memory used by @var{surface}.
@end deffn

@deffn {Scheme Procedure} call-with-surface surface proc
Call @var{proc}, passing it @var{surface} and deleting @var{surface} upon exit
of @var{proc}.
@end deffn

@deffn {Scheme Procedure} load-bmp file
Create a new surface from the bitmap data in @var{file}.
@end deffn

@deffn {Scheme Procedure} surface-width surface
Return the width of @var{surface} in pixels.
@end deffn

@deffn {Scheme Procedure} surface-height surface
Return the height of @var{surface} in pixels.
@end deffn

@deffn {Scheme Procedure} surface-pitch surface
Return the length of a row of pixels in @var{surface} in bytes.
@end deffn

@deffn {Scheme Procedure} surface-pixels surface
Return a bytevector containing the raw pixel data in @var{surface}.
@end deffn

@deffn {Scheme Procedure} surface-pixel-format surface
Return the pixel format for @var{surface}.
@end deffn

@deffn {Scheme Procedure} convert-surface-format surface format
Convert the pixels in @var{surface} to @var{format}, a symbol representing a
specific pixel format, and return a new surface object.

Valid format types are:

@itemize
@item @code{index1lsb}
@item @code{index1msb}
@item @code{index4lsb}
@item @code{index4msb}
@item @code{index8}
@item @code{rgb332}
@item @code{rgb444}
@item @code{rgb555}
@item @code{bgr555}
@item @code{argb4444}
@item @code{rgba4444}
@item @code{abgr4444}
@item @code{bgra4444}
@item @code{argb1555}
@item @code{rgba5551}
@item @code{abgr1555}
@item @code{bgra5551}
@item @code{rgb565}
@item @code{bgr565}
@item @code{rgb24}
@item @code{bgr24}
@item @code{rgb888}
@item @code{rgbx8888}
@item @code{bgr888}
@item @code{bgrx8888}
@item @code{argb8888}
@item @code{rgba8888}
@item @code{abgr8888}
@item @code{bgra8888}
@item @code{argb2101010}
@item @code{yv12}
@item @code{iyuv}
@item @code{yuy2}
@item @code{uyvy}
@item @code{yvyu}
@end itemize
@end deffn

@deffn {Procedure} blit-surface @var{src} @var{src-rect} @var{dst} @var{dst-rect}
Blit the rectangle @var{src-rect} from the surface @var{src} to
@var{dst-rect} of the surface @var{dst}.
@end deffn

@node Rendering
@section Rendering

@example
(use-modules (sdl2 render))
@end example

@deffn {Scheme Procedure} make-renderer window @
                                        [#:optional flags='(accelerated vsync)]
Return a new renderer for @var{window} created with the options specified
in @var{flags}, a list of symbols.  The valid symbols that may appear in
@var{flags} are:

@itemize
@item software, to use a software renderer fallback
@item accelerated, to use hardware acceleration
@item vsync, to synchronize rendering with the monitor's refresh rate
@item texture, for render to texture support
@end itemize
@end deffn

@deffn {Scheme Procedure} renderer? r
Return @code{#t} if @var{r} is a renderer.
@end deffn

@deffn {Scheme Procedure} delete-renderer! renderer
Delete the rendering context @var{renderer}.
@end deffn

@deffn {Scheme Procedure} call-with-renderer renderer proc
Call @var{proc}, passing it @var{renderer} and closing @var{renderer} upon exit
of @var{proc}.
@end deffn

@deffn {Scheme Procedure} clear-renderer renderer
Clear the rendering target @var{renderer} with the current drawing color.
@end deffn

@deffn {Scheme Procedure} present-renderer renderer
Display @var{renderer}.
@end deffn

@deffn {Scheme Procedure} render-copy renderer @
                                      texture @
                                      [#:srcrect]
                                      [#:dstrect]
Copy @var{texture} to the rendering target of @var{renderer}.
@end deffn

@deffn {Scheme Procedure} surface->texture renderer surface
Convert @var{surface} to a texture suitable for @var{renderer}.
@end deffn

@node Images
@section Images

@example
(use-modules (sdl2 image))
@end example

@deffn {Scheme Procedure} image-init
Initialize dynamically loaded image libraries.
@end deffn

@deffn {Scheme Procedure} image-quit
Clean up dynamically loaded image libraries.
@end deffn

@deffn {Scheme Procedure} load-image file
Load the image in @var{file} and return an SDL surface.
@end deffn

@deffn {Scheme Procedure} save-png surface file
Save @var{surface} to @var{file} as a PNG formatted image.
@end deffn

@node Sound
@section Sound

@example
(use-modules (sdl2 mixer))
@end example

@defvr {Scheme Variable} %default-frequency
@end defvr

@defvr {Scheme Variable} %default-format
@end defvr

@defvr {Scheme Variable} %default-chunk-size
@end defvr

@deffn {Scheme Procedure} mixer-init [#:optional formats='(flac mod modplug mp3 ogg fluidsynth)]
Initialize mixer library with support for @var{formats}, a list of
symbols representing audio file formats.  Possible formats are:

@itemize
@item flac
@item mod
@item modplug
@item mp3
@item ogg
@item fluidsynth
@end itemize
@end deffn

@deffn {Scheme Procedure} mixer-quit
Shutdown mixer library.
@end deffn

@deffn {Scheme Procedure} open-audio [#:frequency=%default-frequency] @
                                     [#:format=%default-format] @
                                     [#:stereo?=#t] @
                                     [#:chunk-size=%default-chunk-size]
Initialize the mixer API.  @var{frequency} specificies the sample rate in
hertz.  When @var{stereo?} is @code{#t}, two output channels are used, otherwise
mono output is used instead.  @var{chunk-size} specifies the number of bytes
used per output sample.  @var{format} is a symbol that specifies the output
sample format.  Possible values are:

@itemize
@item u8
@item s8
@item u16lsb
@item s16lsb
@item u16msb
@item s16msb
@item u16
@item s16
@item s32lsb
@item s32msb
@item s32
@item f32lsb
@item f32msb
@item f32
@end itemize
@end deffn

@deffn {Scheme Procedure} close-audio
Shut down the mixer API.
@end deffn

@deffn {Scheme Procedure} chunk? c
Return @code{#t} if @var{c} is a chunk.
@end deffn

@deffn {Scheme Procedure} load-chunk file
Load the audio data in @var{file} and return an audio chunk.
@end deffn

@deffn {Scheme Procedure} delete-chunk! chunk
Free the memory used for @var{chunk}.
@end deffn

@deffn {Scheme Procedure} set-chunk-volume! chunk volume
Set the loudness of @var{chunk} to @var{volume}, an integer in the range
[0,128].  Return the previous chunk volume setting.
@end deffn

@deffn {Scheme Procedure} play-chunk! chunk @
                                      [#:loops=0] @
                                      [#:channel]
Play @var{chunk} on @var{channel}, an integer channel identifier or @code{#f}
to use the first unreserved audio channel.  @var{chunk} will play @var{loops} +
1 times.  Return the channel identifier that @var{chunk} is played on.
@end deffn

@deffn {Scheme Procedure} set-channel-volume! channel volume
Set the loudness of @var{channel}, an integer channel identifier or @code{#f}
for all channels, to @var{volume}, an integer in the range [0,128].  Return
the previous volume of @var{channel}, or the average of all channels if
@var{channel} is @code{#f}.
@end deffn

@deffn {Scheme Procedure} pause-channel! channel
Pause playback on @var{channel}, an integer channel identifier, or @code{#f} to
pause all channels.
@end deffn

@deffn {Scheme Procedure} resume-channel! channel
Resume playback on @var{channel}, an integer channel identifier, or @code{#f} to
resume all channels.
@end deffn

@deffn {Scheme Procedure} stop-channel! channel
Halt playback on @var{channel}, an integer channel identifier, or @code{#f} to
halt all channels.
@end deffn

@deffn {Scheme Procedure} channel-playing? channel
Return @code{#t} if @var{channel} is playing.
@end deffn

@deffn {Scheme Procedure} playing-channels-count
Return the number of channels currently playing.
@end deffn

@deffn {Scheme Procedure} channel-paused? channel
Return @code{#t} if @var{channel} is paused.
@end deffn

@deffn {Scheme Procedure} paused-channels-count
Return the number of channels that are paused.
@end deffn

@deffn {Scheme Procedure} music? m
Return @code{#t} if @var{m} is music.
@end deffn

@deffn {Scheme Procedure} load-music file
Load music from @var{file}.
@end deffn

@deffn {Scheme Procedure} delete-music! music
Delete the memory used for @var{music}.
@end deffn

@deffn {Scheme Procedure} play-music! music [#:optional loops=1]
Play @var{music}, repeated @var{loops} times.  @var{loops} may be @code{#f}, in
which case the music loops indefinitely.
@end deffn

@deffn {Scheme Procedure} set-music-volume! volume
Set music loudness to @var{volume}, an integer in the range [0,128].  Return the
previous volume.
@end deffn

@deffn {Scheme Procedure} music-volume
Return the music volume.
@end deffn

@deffn {Scheme Procedure} pause-music!
Puase the music.
@end deffn

@deffn {Scheme Procedure} resume-music!
Resume music playback.
@end deffn

@deffn {Scheme Procedure} rewind-music!
Start music playback from the beginning.  Rewinding is only supported for MOD,
OGG, MP3, and native MIDI music.
@end deffn

@deffn {Scheme Procedure} stop-music!
Halt music playback.
@end deffn

@deffn {Scheme Procedure} music-playing?
Return @code{#t} if music is currently playing.
@end deffn

@deffn {Scheme Procedure} music-paused?
Return @code{#t} if music is currently paused.
@end deffn

@node Fonts
@section Fonts

@example
(use-modules (sdl2 ttf))
@end example

@deffn {Scheme Procedure} ttf-init
Initialize the TTF system.
@end deffn

@deffn {Scheme Procedure} ttf-quit
Shut down and clean up the TTF system.
@end deffn

@deffn {Scheme Procedure} load-font file point-size
Load TTF font from @var{file} and return a new font object whose glyph size is
@var{point-size}.
@end deffn

@deffn {Scheme Procedure} delete-font! font
Delete the memory allocated for @var{font}.
@end deffn

@deffn {Scheme Procedure} font-height font
Return the maximum height of @var{font}.
@end deffn

@deffn {Scheme Procedure} render-font-solid font text color
Render @var{text}, a UTF-8 encoded string, using @var{font} and @var{color}, the
foreground color, and return a surface containing the results.
@end deffn

@deffn {Scheme Procedure} render-font-blended font text color
Render @var{text}, a UTF-8 encoded string, using @var{font} and @var{color}, the
foreground color, and return a high-quality alpha-blended surface containing the
results.
@end deffn