-
Notifications
You must be signed in to change notification settings - Fork 29
/
tsdl.mli
4020 lines (3150 loc) · 129 KB
/
tsdl.mli
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
(*---------------------------------------------------------------------------
Copyright (c) 2013 The tsdl programmers. All rights reserved.
SPDX-License-Identifier: ISC
---------------------------------------------------------------------------*)
(** SDL thin bindings.
Consult the {{!conventions}binding conventions}, the
{{!Sdl.coverage}binding coverage} and the {{!page-index.quick}
quick start}.
Given the thinness of the binding most functions are documented by
linking directly to SDL's own documentation.
Open the module to use it, this defines only the module [Sdl] in
your scope.
{b Note.} The module initialization code calls
{{:http://wiki.libsdl.org/SDL2/SDL_SetMainReady}SDL_SetMainReady}.
{b References}
{ul
{- {{:http://wiki.libsdl.org/SDL2/APIByCategory}SDL API}}} *)
(** {1:sdl SDL} *)
(** SDL bindings. *)
module Sdl : sig
(** {1:types Integer types, bigarrays and results} *)
type uint8 = int
(** The type for unsigned 8-bit integers. *)
type int16 = int
(** The type for signed 16-bit integers. *)
type uint16 = int
(** The type for unsigned 16-bit integers. *)
type uint32 = int32
(** The type for unsigned 32-bit integers. *)
type uint64 = int64
(** The type for unsigned 64-bit integers. *)
type ('a, 'b) bigarray = ('a, 'b, Bigarray.c_layout) Bigarray.Array1.t
(** The type for bigarrays.*)
type nonrec 'a result = ('a, [ `Msg of string ]) result
(** The type for function results. In the error case,
the string is what {!Sdl.get_error} returned. *)
(** {1:basics Basics} *)
(** {2:init {{:http://wiki.libsdl.org/SDL2/CategoryInit}
Initialization and shutdown}} *)
module Init : sig
type t
val ( + ) : t -> t -> t
(** [f + f'] combines flags [f] and [f']. *)
val ( - ) : t -> t -> t
(** [f - f'] removes flag [f'] from [f]. *)
val test : t -> t -> bool
(** [test flags mask] is [true] if any of the flags in [mask] is
set in [flags]. *)
val eq : t -> t -> bool
(** [eq f f'] is [true] if the flags are equal. *)
val nothing : t
val timer : t
val audio : t
val video : t
val joystick : t
val haptic : t
val gamecontroller : t
val events : t
val everything : t
val noparachute : t
end
(** Subsystem flags. *)
val init : Init.t -> unit result
(** {{:http://wiki.libsdl.org/SDL2/SDL_Init}SDL_Init} *)
val init_sub_system : Init.t -> unit result
(** {{:http://wiki.libsdl.org/SDL2/SDL_InitSubSystem}SDL_InitSubSystem} *)
val quit : unit -> unit
(** {{:http://wiki.libsdl.org/SDL2/SDL_Quit}SDL_Quit} *)
val quit_sub_system : Init.t -> unit
(** {{:http://wiki.libsdl.org/SDL2/SDL_QuitSubSystem}SDL_QuitSubSystem} *)
val was_init : Init.t option -> Init.t
(** {{:http://wiki.libsdl.org/SDL2/SDL_WasInit}SDL_WasInit} *)
(** {2:hints {{:http://wiki.libsdl.org/SDL2/CategoryHints}Hints}} *)
module Hint : sig
(** {1:hint Hints} *)
type t = string
val audio_resampling_mode : t
(** {{:http://wiki.libsdl.org/SDL2/SDL_HINT_AUDIO_RESAMPLING_MODE}
SDL_HINT_AUDIO_RESAMPLING_MODE} *)
val framebuffer_acceleration : t
(** {{:http://wiki.libsdl.org/SDL2/SDL_HINT_FRAMEBUFFER_ACCELERATION}
SDL_HINT_FRAMEBUFFER_ACCELERATION} *)
val idle_timer_disabled : t
(** {{:http://wiki.libsdl.org/SDL2/SDL_HINT_IDLE_TIMER_DISABLED}
SDL_HINT_IDLE_TIMER_DISABLED} *)
val mouse_focus_clickthrough : t
(** {{:http://wiki.libsdl.org/SDL2/SDL_HINT_MOUSE_FOCUS_CLICKTHROUGH}
SDL_HINT_MOUSE_FOCUS_CLICKTHROUGH} *)
val mouse_normal_speed_scale : t
(** {{:http://wiki.libsdl.org/SDL2/SDL_MOUSE_NORMAL_SPEED_SCALE}
SDL_MOUSE_NORMAL_SPEED_SCALE} *)
val mouse_relative_speed_scale : t
(** {{:http://wiki.libsdl.org/SDL2/SDL_MOUSE_RELATIVE_SPEED_SCALE}
SDL_MOUSE_RELATIVE_SPEED_SCALE} *)
val orientations : t
(** {{:http://wiki.libsdl.org/SDL2/SDL_HINT_ORIENTATIONS}
SDL_HINT_ORIENTATIONS} *)
val render_driver : t
(** {{:http://wiki.libsdl.org/SDL2/SDL_HINT_RENDER_DRIVER}
SDL_HINT_RENDER_DRIVER} *)
val render_logical_size_mode : t
(** {{:http://wiki.libsdl.org/SDL2/SDL_HINT_RENDER_LOGICAL_SIZE_MODE}
SDL_HINT_RENDER_LOGICAL_SIZE_MODE} *)
val render_opengl_shaders : t
(** {{:http://wiki.libsdl.org/SDL2/SDL_HINT_RENDER_OPENGL_SHADERS}
SDL_HINT_RENDER_OPENGL_SHADERS} *)
val render_scale_quality : t
(** {{:http://wiki.libsdl.org/SDL2/SDL_HINT_RENDER_SCALE_QUALITY}
SDL_HINT_RENDER_SCALE_QUALITY} *)
val render_vsync : t
(** {{:http://wiki.libsdl.org/SDL2/SDL_HINT_RENDER_VSYNC}
SDL_HINT_RENDER_VSYNC} *)
val no_signal_handlers : t
(** {{:http://wiki.libsdl.org/SDL2/SDL_HINT_NO_SIGNAL_HANDLERS}
SDL_HINT_NO_SIGNAL_HANDLERS} *)
val thread_stack_size : t
(** {{:http://wiki.libsdl.org/SDL2/SDL_HINT_THREAD_STACK_SIZE}
SDL_HINT_THREAD_STACK_SIZE} *)
val touch_mouse_events : t
(** {{:http://wiki.libsdl.org/SDL2/SDL_HINT_TOUCH_MOUSE_EVENTS}
SDL_HINT_TOUCH_MOUSE_EVENTS} *)
val mouse_touch_events : t
(** {{:http://wiki.libsdl.org/SDL2/SDL_HINT_MOUSE_TOUCH_EVENTS}
SDL_HINT_MOUSE_TOUCH_EVENTS} *)
val window_frame_usable_while_cursor_hidden: t
(** {{:http://wiki.libsdl.org/SDL2/SDL_HINT_WINDOW_FRAME_USABLE_WHILE_CURSOR_HIDDEN}
SDL_HINT_WINDOW_FRAME_USABLE_WHILE_CURSOR_HIDDEN} *)
(** {1:priority Priority} *)
type priority
(** {{:http://wiki.libsdl.org/SDL2/SDL_HintPriority}SDL_HintPriority} *)
val default : priority
val normal : priority
val override : priority
end
val clear_hints : unit -> unit
(** {{:http://wiki.libsdl.org/SDL2/SDL_ClearHints}SDL_ClearHints} *)
val get_hint : Hint.t -> string option
(** {{:http://wiki.libsdl.org/SDL2/SDL_GetHint}SDL_GetHint} *)
val get_hint_boolean : Hint.t -> bool -> bool
(** {{:http://wiki.libsdl.org/SDL2/SDL_GetHintBoolean}SDL_GetHintBoolean} *)
val set_hint : Hint.t -> string -> bool
(** {{:http://wiki.libsdl.org/SDL2/SDL_SetHint}SDL_SetHint} *)
val set_hint_with_priority : Hint.t -> string -> Hint.priority -> bool
(** {{:http://wiki.libsdl.org/SDL2/SDL_SetHintWithPriority}
SDL_SetHintWithPriority} *)
(** {2:errors {{:http://wiki.libsdl.org/SDL2/CategoryError}Errors}} *)
val clear_error : unit -> unit
(** {{:http://wiki.libsdl.org/SDL2/SDL_ClearError}SDL_ClearError} *)
val get_error : unit -> string
(** {{:http://wiki.libsdl.org/SDL2/SDL_GetError}SDL_GetError} *)
val set_error : ('b, Format.formatter, unit) format -> 'b
(** {{:http://wiki.libsdl.org/SDL2/SDL_SetError}SDL_SetError} *)
(** {2:log {{:http://wiki.libsdl.org/SDL2/CategoryLog}Log}} *)
module Log : sig
(** {1:category Category} *)
type category = int
(** {{:http://wiki.libsdl.org/SDL2/SDL_LOG_CATEGORY}SDL_LOG_CATEGORY} *)
val category_application : category
val category_error : category
val category_system : category
val category_audio : category
val category_video : category
val category_render : category
val category_input : category
(** {1:priority Priority} *)
type priority
(** {{:http://wiki.libsdl.org/SDL2/SDL_LogPriority}SDL_LogPriority} *)
val priority_compare : priority -> priority -> int
val priority_verbose : priority
val priority_debug : priority
val priority_info : priority
val priority_warn : priority
val priority_error : priority
val priority_critical : priority
end
val log : ('b, Format.formatter, unit) format -> 'b
(** {{:http://wiki.libsdl.org/SDL2/SDL_Log}SDL_Log} *)
val log_critical : Log.category -> ('b, Format.formatter, unit) format -> 'b
(** {{:http://wiki.libsdl.org/SDL2/SDL_LogCritical}SDL_LogCritical} *)
val log_debug : Log.category -> ('b, Format.formatter, unit) format -> 'b
(** {{:http://wiki.libsdl.org/SDL2/SDL_LogDebug}SDL_LogDebug} *)
val log_error : Log.category -> ('b, Format.formatter, unit) format -> 'b
(** {{:http://wiki.libsdl.org/SDL2/SDL_LogError}SDL_LogError} *)
val log_get_priority : Log.category -> Log.priority
(** {{:http://wiki.libsdl.org/SDL2/SDL_LogGetPriority}SDL_LogGetPriority} *)
val log_info : Log.category -> ('b, Format.formatter, unit) format -> 'b
(** {{:http://wiki.libsdl.org/SDL2/SDL_LogInfo}SDL_LogInfo} *)
val log_message : Log.category -> Log.priority ->
('b, Format.formatter, unit) format -> 'b
(** {{:http://wiki.libsdl.org/SDL2/SDL_LogMessage}SDL_LogMessage} *)
val log_reset_priorities : unit -> unit
(** {{:http://wiki.libsdl.org/SDL2/SDL_LogResetPriorities}
SDL_LogResetPriorities} *)
val log_set_all_priority : Log.priority -> unit
(** {{:http://wiki.libsdl.org/SDL2/SDL_LogSetAllPriority}
SDL_LogSetAllPriority} *)
val log_set_priority : Log.category -> Log.priority -> unit
(** {{:http://wiki.libsdl.org/SDL2/SDL_LogSetPriority}SDL_LogSetPriority} *)
val log_verbose : Log.category -> ('b, Format.formatter, unit) format -> 'b
(** {{:http://wiki.libsdl.org/SDL2/SDL_LogVerbose}SDL_LogVerbose} *)
val log_warn : Log.category -> ('b, Format.formatter, unit) format -> 'b
(** {{:http://wiki.libsdl.org/SDL2/SDL_LogWarn}SDL_LogWarn} *)
(** {2:version {{:http://wiki.libsdl.org/SDL2/CategoryVersion}Version}} *)
val get_version : unit -> (int * int * int)
(** {{:http://wiki.libsdl.org/SDL2/SDL_GetVersion}SDL_GetVersion} *)
val get_revision : unit -> string
(** {{:http://wiki.libsdl.org/SDL2/SDL_GetRevision}SDL_GetRevision} *)
val get_revision_number : unit -> int
(** {{:http://wiki.libsdl.org/SDL2/SDL_GetRevisionNumber}
SDL_GetRevisionNumber} *)
(** {1:fileabstraction Files and IO abstraction} *)
(** {2:io {{:https://wiki.libsdl.org/SDL2/CategoryIO}IO abstraction}} *)
type rw_ops
(** {{:https://wiki.libsdl.org/SDL2/SDL_RWops}SDL_RWops} *)
val load_file : string -> string result
(** {{:https://wiki.libsdl.org/SDL2/SDL_LoadFile}SDL_LoadFile} *)
val load_file_rw : rw_ops -> bool -> string result
(** {{:https://wiki.libsdl.org/SDL2/SDL_LoadFile_RW}SDL_LoadFile_RW} *)
val rw_from_file : string -> string -> rw_ops result
(** {{:https://wiki.libsdl.org/SDL2/SDL_RWFromFile}SDL_RWFromFile} *)
val rw_from_const_mem : string -> rw_ops result
(** {{:https://wiki.libsdl.org/SDL2/SDL_RWFromConstMem}SDL_RWFromConstMem} *)
val rw_from_mem : bytes -> rw_ops result
(** {{:https://wiki.libsdl.org/SDL2/SDL_RWFromConstMem}SDL_RWFromMem} *)
val rw_close : rw_ops -> unit result
(** {{:https://wiki.libsdl.org/SDL2/SDL_RWclose}SDL_RWclose} *)
(**/**)
val unsafe_rw_ops_of_ptr : nativeint -> rw_ops
val unsafe_ptr_of_rw_ops : rw_ops -> nativeint
(**/**)
(** {1:fspaths {{:https://wiki.libsdl.org/SDL2/CategoryFilesystem}Filesystem
Paths}} *)
val get_base_path : unit -> string result
(** {{:https://wiki.libsdl.org/SDL2/SDL_GetBasePath}SDL_GetBasePath} *)
val get_pref_path : org:string -> app:string -> string result
(** {{:https://wiki.libsdl.org/SDL2/SDL_GetPrefPath}SDL_GetPrefPath} *)
(** {1:video Video} *)
type window
(** {{:https://wiki.libsdl.org/SDL2/SDL_Window}SDL_Window} *)
(**/**)
val unsafe_window_of_ptr : nativeint -> window
val unsafe_ptr_of_window : window -> nativeint
(**/**)
(** {2:colors Colors} *)
type color
(** {{:http://wiki.libsdl.org/SDL2/SDL_Color}SDL_Color} *)
module Color : sig
val create : r:uint8 -> g:uint8 -> b:uint8 -> a:uint8 -> color
val r : color -> uint8
val g : color -> uint8
val b : color -> uint8
val a : color -> uint8
val set_r : color -> uint8 -> unit
val set_g : color -> uint8 -> unit
val set_b : color -> uint8 -> unit
val set_a : color -> uint8 -> unit
end
(** {2:points Points and vertices} *)
type point
(** {{:http://wiki.libsdl.org/SDL2/SDL_Point}SDL_Point} *)
module Point : sig
val create : x:int -> y:int -> point
val x : point -> int
val y : point -> int
val set_x : point -> int -> unit
val set_y : point -> int -> unit
end
type fpoint
(** structure SDL_FPoint *)(* from <SDL2/SDL_rect.h> *)
module Fpoint : sig
val create : x:float -> y:float -> fpoint
val x : fpoint -> float
val y : fpoint -> float
val set_x : fpoint -> float -> unit
val set_y : fpoint -> float -> unit
end
type vertex
(** {{:https://wiki.libsdl.org/SDL2/SDL_Vertex}SDL_Vertex} *)
module Vertex : sig
val create : position:fpoint -> color:color -> tex_coord:fpoint -> vertex
val position : vertex -> fpoint
val color : vertex -> color
val tex_coord : vertex -> fpoint
val set_position : vertex -> fpoint -> unit
val set_color : vertex -> color -> unit
val set_tex_coord : vertex -> fpoint -> unit
end
(** {2:rectangles
{{:http://wiki.libsdl.org/SDL2/CategoryRect}Rectangles}} *)
type rect
(** {{:http://wiki.libsdl.org/SDL2/SDL_Rect}SDL_Rect} *)
module Rect : sig
val create : x:int -> y:int -> w:int -> h:int -> rect
val x : rect -> int
val y : rect -> int
val w : rect -> int
val h : rect -> int
val set_x : rect -> int -> unit
val set_y : rect -> int -> unit
val set_w : rect -> int -> unit
val set_h : rect -> int -> unit
end
type frect
(** structure SDL_FRect *)(* from <SDL2/SDL_rect.h> *)
module Frect : sig
val create : x:float -> y:float -> w:float -> h:float -> frect
val x : frect -> float
val y : frect -> float
val w : frect -> float
val h : frect -> float
val set_x : frect -> float -> unit
val set_y : frect -> float -> unit
val set_w : frect -> float -> unit
val set_h : frect -> float -> unit
end
val enclose_points : ?clip:rect -> point list -> rect option
(** {{:http://wiki.libsdl.org/SDL2/SDL_EnclosePoints}SDL_EnclosePoints}.
Returns [None] if all the points were outside
the clipping rectangle (if provided). *)
val enclose_points_ba : ?clip:rect -> (int32, Bigarray.int32_elt) bigarray ->
rect option
(** See {!enclose_points}. Each consecutive pair in the array defines a
point.
@raise Invalid_argument if the length of the array is not
a multiple of 2. *)
val has_intersection : rect -> rect -> bool
(** {{:http://wiki.libsdl.org/SDL2/SDL_HasIntersection}SDL_HasIntersection} *)
val intersect_rect : rect -> rect -> rect option
(** {{:http://wiki.libsdl.org/SDL2/SDL_IntersectRect}SDL_IntersectRect} *)
val intersect_rect_and_line : rect -> int -> int -> int -> int ->
((int * int) * (int * int)) option
(** {{:http://wiki.libsdl.org/SDL2/SDL_IntersectRectAndLine}
SDL_IntersectRectAndLine}. Returns the clipped segment if it
intersects. *)
val point_in_rect: point -> rect -> bool
(** {{:http://wiki.libsdl.org/SDL2/SDL_PointInRect}SDL_PointInRect} *)
val rect_empty : rect -> bool
(** {{:http://wiki.libsdl.org/SDL2/SDL_RectEmpty}SDL_RectEmpty} *)
val rect_equals : rect -> rect -> bool
(** {{:http://wiki.libsdl.org/SDL2/SDL_RectEquals}SDL_RectEquals} *)
val union_rect : rect -> rect -> rect
(** {{:http://wiki.libsdl.org/SDL2/SDL_UnionRect}SDL_UnionRect} *)
(** {2:palettes {{:http://wiki.libsdl.org/SDL2/CategoryPixels}Palettes}} *)
type palette
(** {{:https://wiki.libsdl.org/SDL2/SDL_Palette}SDL_Palette} *)
val alloc_palette : int -> palette result
(** {{:http://wiki.libsdl.org/SDL2/SDL_AllocPalette}SDL_AllocPalette} *)
val free_palette : palette -> unit
(** {{:http://wiki.libsdl.org/SDL2/SDL_FreePalette}SDL_FreePalette} *)
val get_palette_ncolors : palette -> int
(** [get_palette_ncolors p] is the field [ncolors] of [p]. *)
val get_palette_colors : palette -> color list
(** [get_palette_colors p] is a copy of the contents of the field [colors]
of [s]. *)
val get_palette_colors_ba : palette ->
(int, Bigarray.int8_unsigned_elt) bigarray
(** [get_palette_colors_ba p] is a copy of the contents of the field [colors]
of [p]. *)
val set_palette_colors : palette -> color list -> fst:int ->
unit result
(** {{:http://wiki.libsdl.org/SDL2/SDL_SetPaletteColors}SDL_SetPaletteColors} *)
val set_palette_colors_ba : palette ->
(int, Bigarray.int8_unsigned_elt) bigarray -> fst:int -> unit result
(** See {!set_palette_colors}. Each consecutive quadruplet defines a
color. The data is copied.
@raise Invalid_argument if the length of the array is not
a multiple of 4. *)
(**/**)
val unsafe_palette_of_ptr : nativeint -> palette
val unsafe_ptr_of_palette : palette -> nativeint
(**/**)
(** {2:pixel_formats {{:http://wiki.libsdl.org/SDL2/CategoryPixels}Pixels
formats}} *)
type gamma_ramp = (int, Bigarray.int16_unsigned_elt) bigarray
(** The type for gamma ramps, 256 [uint16] values. *)
val calculate_gamma_ramp : float -> gamma_ramp
(** {{:http://wiki.libsdl.org/SDL2/SDL_CalculateGammaRamp}
SDL_CalculateGammaRamp} *)
module Blend : sig
type mode
(** {{:https://wiki.libsdl.org/SDL2/SDL_BlendMode}SDL_BlendMode} *)
val mode_none : mode
val mode_blend : mode
val mode_add : mode
val mode_mod : mode
type operation
(** {{:https://wiki.libsdl.org/SDL2/SDL_BlendOperation}SDL_BlendOperation} *)
val add : operation
val subtract : operation
val rev_subtract : operation
val minimum : operation
val maximum : operation
type factor
(** {{:https://wiki.libsdl.org/SDL2/SDL_BlendFactor}SDL_BlendFactor} *)
val zero : factor
val one : factor
val src_color : factor
val one_minus_src_color : factor
val src_alpha : factor
val one_minus_src_alpha : factor
val dst_color : factor
val one_minus_dst_color : factor
val dst_alpha : factor
val one_minus_dst_alpha : factor
end
val compose_custom_blend_mode :
Blend.factor -> Blend.factor -> Blend.operation -> Blend.factor ->
Blend.factor -> Blend.operation -> Blend.mode
(** {{:https://wiki.libsdl.org/SDL2/SDL_ComposeCustomBlendMode}
SDL_ComposeCustomBlendMode} *)
module Pixel : sig
type format_enum
(** {{:https://wiki.libsdl.org/SDL2/SDL_PixelFormatEnum}
SDL_PixelFormatEnum} *)
val eq : format_enum -> format_enum -> bool
val to_uint32 : format_enum -> uint32
val format_unknown : format_enum
val format_index1lsb : format_enum
val format_index1msb : format_enum
val format_index4lsb : format_enum
val format_index4msb : format_enum
val format_index8 : format_enum
val format_rgb332 : format_enum
val format_rgb444 : format_enum
val format_rgb555 : format_enum
val format_bgr555 : format_enum
val format_argb4444 : format_enum
val format_rgba4444 : format_enum
val format_abgr4444 : format_enum
val format_bgra4444 : format_enum
val format_argb1555 : format_enum
val format_rgba5551 : format_enum
val format_abgr1555 : format_enum
val format_bgra5551 : format_enum
val format_rgb565 : format_enum
val format_bgr565 : format_enum
val format_rgb24 : format_enum
val format_bgr24 : format_enum
val format_rgb888 : format_enum
val format_rgbx8888 : format_enum
val format_bgr888 : format_enum
val format_bgrx8888 : format_enum
val format_argb8888 : format_enum
val format_rgba8888 : format_enum
val format_abgr8888 : format_enum
val format_bgra8888 : format_enum
val format_argb2101010 : format_enum
val format_yv12 : format_enum
val format_iyuv : format_enum
val format_yuy2 : format_enum
val format_uyvy : format_enum
val format_yvyu : format_enum
end
type pixel_format
(** {{:https://wiki.libsdl.org/SDL2/SDL_PixelFormat}SDL_PixelFormat} *)
val alloc_format : Pixel.format_enum -> pixel_format result
(** {{:http://wiki.libsdl.org/SDL2/SDL_AllocFormat}SDL_AllocFormat} *)
val free_format : pixel_format -> unit
(** {{:http://wiki.libsdl.org/SDL2/SDL_FreeFormat}SDL_FreeFormat} *)
val get_pixel_format_name : Pixel.format_enum -> string
(** {{:http://wiki.libsdl.org/SDL2/SDL_GetPixelFormatName}
SDL_GetPixelFormatName} *)
val get_pixel_format_format : pixel_format -> Pixel.format_enum
(** [get_pixel_format_format pf] is the field [format] of [pf]. *)
val get_pixel_format_bits_pp : pixel_format -> int
(** [get_pixel_format_bits_pp pf] is the field [BitsPerPixel] of [pf]. *)
val get_pixel_format_bytes_pp : pixel_format -> int
(** [get_pixel_format_bytes_pp pf] is the field [BytesPerPixel] of [pf]. *)
val get_rgb : pixel_format -> uint32 -> (uint8 * uint8 * uint8)
(** {{:http://wiki.libsdl.org/SDL2/SDL_GetRGB}SDL_GetRGB} *)
val get_rgba : pixel_format -> uint32 -> (uint8 * uint8 * uint8 * uint8)
(** {{:http://wiki.libsdl.org/SDL2/SDL_GetRGBA}SDL_GetRGBA} *)
val map_rgb : pixel_format -> uint8 -> uint8 -> uint8 -> uint32
(** {{:http://wiki.libsdl.org/SDL2/SDL_MapRGB}SDL_MapRGB} *)
val map_rgba : pixel_format -> uint8 -> uint8 -> uint8 -> uint8 -> uint32
(** {{:http://wiki.libsdl.org/SDL2/SDL_MapRGBA}SDL_MapRGBA} *)
val masks_to_pixel_format_enum :
int -> uint32 -> uint32 -> uint32 -> uint32 -> Pixel.format_enum
(** {{:http://wiki.libsdl.org/SDL2/SDL_MasksToPixelFormatEnum}
SDL_MasksToPixelFormatEnum} *)
val pixel_format_enum_to_masks :
Pixel.format_enum -> (int * uint32 * uint32 * uint32 * uint32) result
(** {{:http://wiki.libsdl.org/SDL2/SDL_PixelFormatEnumToMasks}
SDL_PixelFormatEnumToMasks} *)
val set_pixel_format_palette : pixel_format -> palette -> unit result
(** {{:http://wiki.libsdl.org/SDL2/SDL_SetPixelFormatPalette}
SDL_SetPixelFormatPalette}.
{b Note} If you allocated the palette with {!alloc_palette} you
can {!free_palette} after. *)
(**/**)
val unsafe_pixel_format_of_ptr : nativeint -> pixel_format
val unsafe_ptr_of_pixel_format : pixel_format -> nativeint
(**/**)
(** {2:surfaces
{{:http://wiki.libsdl.org/SDL2/CategorySurface}Surface}} *)
type surface
(** {{:https://wiki.libsdl.org/SDL2/SDL_Surface}SDL_Surface} *)
val blit_scaled :
src:surface -> rect option -> dst:surface -> rect option -> unit result
(** {{:http://wiki.libsdl.org/SDL2/SDL_BlitScaled}SDL_BlitScaled} *)
val blit_surface :
src:surface -> rect option -> dst:surface -> rect option -> unit result
(** {{:http://wiki.libsdl.org/SDL2/SDL_BlitSurface}SDL_BlitSurface} *)
val convert_pixels :
w:int -> h:int -> src:Pixel.format_enum ->
('a, 'b) bigarray -> int -> dst:Pixel.format_enum ->
('c, 'd) bigarray -> int -> unit result
(** {{:http://wiki.libsdl.org/SDL2/SDL_ConvertPixels}SDL_ConvertPixels}
{b Note} Pitches are given in bigarray elements {b not} in bytes.
{b Warning.} Unsafe, make sure your parameters don't result
in invalid access to memory. *)
val convert_surface : surface -> pixel_format -> surface result
(** {{:http://wiki.libsdl.org/SDL2/SDL_ConvertSurface}SDL_ConvertSurface} *)
val convert_surface_format : surface -> Pixel.format_enum -> surface result
(** {{:http://wiki.libsdl.org/SDL2/SDL_ConvertSurfaceFormat}
SDL_ConvertSurfaceFormat} *)
val create_rgb_surface :
w:int -> h:int -> depth:int -> uint32 -> uint32 -> uint32 -> uint32 ->
surface result
(** {{:http://wiki.libsdl.org/SDL2/SDL_CreateRGBSurface}SDL_CreateRGBSurface} *)
val create_rgb_surface_from :
('a, 'b) bigarray -> w:int -> h:int -> depth:int -> pitch:int -> uint32 ->
uint32 -> uint32 -> uint32 -> surface result
(** {{:http://wiki.libsdl.org/SDL2/SDL_CreateRGBSurfaceFrom}
SDL_CreateRGBSurfaceFrom}
{b Note} The pitch is given in bigarray elements {b not} in
bytes.
{b Warning} Unsafe, make sure your parameters don't result
in invalid access to memory. The bigarray data is not copied,
it must remain valid until {!free_surface} is called on the
surface. *)
val create_rgb_surface_with_format :
w:int -> h:int -> depth:int -> Pixel.format_enum -> surface result
(** {{:http://wiki.libsdl.org/SDL2/SDL_CreateRGBSurfaceWithFormat}
SDL_CreateRGBSurfaceWithFormat} *)
val create_rgb_surface_with_format_from :
('a, 'b) bigarray -> w:int -> h:int -> depth:int -> pitch:int ->
Pixel.format_enum -> surface result
(** {{:http://wiki.libsdl.org/SDL2/SDL_CreateRGBSurfaceWithFormatFrom}
SDL_CreateRGBSurfaceWithFormatFrom} *)
val duplicate_surface : surface -> surface
(** {{:http://wiki.libsdl.org/SDL2/SDL_DuplicateSurface}SDL_DuplicateSurface} *)
val fill_rect : surface -> rect option -> uint32 -> unit result
(** {{:http://wiki.libsdl.org/SDL2/SDL_FillRect}SDL_FillRect} *)
val fill_rects : surface -> rect list -> uint32 -> unit result
(** {{:http://wiki.libsdl.org/SDL2/SDL_FillRects}SDL_FillRects} *)
val fill_rects_ba :
surface -> (int32, Bigarray.int32_elt) bigarray -> uint32 -> unit result
(** See {!fill_rects}. Each consecutive quadruplet defines a
rectangle.
@raise Invalid_argument if the length of the array is not
a multiple of 4. *)
val free_surface : surface -> unit
(** {{:http://wiki.libsdl.org/SDL2/SDL_FreeSurface}SDL_FreeSurface} *)
val get_clip_rect : surface -> rect
(** {{:http://wiki.libsdl.org/SDL2/SDL_GetClipRect}SDL_GetClipRect} *)
val get_color_key : surface -> uint32 result
(** {{:http://wiki.libsdl.org/SDL2/SDL_GetColorKey}SDL_GetColorKey} *)
val get_surface_alpha_mod : surface -> uint8 result
(** {{:http://wiki.libsdl.org/SDL2/SDL_GetSurfaceAlphaMod}
SDL_GetSurfaceAlphaMod} *)
val get_surface_blend_mode : surface -> Blend.mode result
(** {{:http://wiki.libsdl.org/SDL2/SDL_GetSurfaceBlendMode}
SDL_GetSurfaceBlendMode} *)
val get_surface_color_mod : surface -> (int * int * int) result
(** {{:http://wiki.libsdl.org/SDL2/SDL_GetSurfaceColorMod}
SDL_GetSurfaceColorMod} *)
val get_surface_format_enum : surface -> Pixel.format_enum
(** [get_surface_format_neum s] is the pixel format enum of the
field [format] of [s]. *)
val get_surface_pitch : surface -> int
(** [get_surface_pitch s] is the field [pitch] of [s]. *)
val get_surface_pixels : surface -> ('a, 'b) Bigarray.kind -> ('a, 'b) bigarray
(** [get_surface_pixels s kind] is the field [pixels] of [s] viewed as
a [kind] bigarray. Note that you must lock the surface before
accessing this.
{b Warning.} The bigarray memory becomes invalid
once the surface is unlocked or freed.
@raise Invalid_argument If [kind] can't align with the surface pitch. *)
val get_surface_size : surface -> int * int
(** [get_surface_size s] is the fields [w] and [h] of [s]. *)
val load_bmp : string -> surface result
(** {{:http://wiki.libsdl.org/SDL2/SDL_LoadBMP}SDL_LoadBMP} *)
val load_bmp_rw : rw_ops -> close:bool -> surface result
(** {{:http://wiki.libsdl.org/SDL2/SDL_LoadBMP_RW}SDL_LoadBMP_RW} *)
val lock_surface : surface -> unit result
(** {{:http://wiki.libsdl.org/SDL2/SDL_LockSurface}SDL_LockSurface} *)
val lower_blit :
src:surface -> rect -> dst:surface -> rect -> unit result
(** {{:http://wiki.libsdl.org/SDL2/SDL_LowerBlit}SDL_LowerBlit} *)
val lower_blit_scaled :
src:surface -> rect -> dst:surface -> rect -> unit result
(** {{:http://wiki.libsdl.org/SDL2/SDL_LowerBlitScaled}SDL_LowerBlitScaled} *)
val save_bmp : surface -> string -> unit result
(** {{:http://wiki.libsdl.org/SDL2/SDL_SaveBMP}SDL_SaveBMP} *)
val save_bmp_rw : surface -> rw_ops -> close:bool -> unit result
(** {{:http://wiki.libsdl.org/SDL2/SDL_SaveBMP_RW}SDL_SaveBMP_RW} *)
val set_clip_rect : surface -> rect -> bool
(** {{:http://wiki.libsdl.org/SDL2/SDL_SetClipRect}SDL_SetClipRect} *)
val set_color_key : surface -> bool -> uint32 -> unit result
(** {{:http://wiki.libsdl.org/SDL2/SDL_SetColorKey}SDL_SetColorKey} *)
val set_surface_alpha_mod : surface -> uint8 -> unit result
(** {{:http://wiki.libsdl.org/SDL2/SDL_SetSurfaceAlphaMod}
SDL_SetSurfaceAlphaMod} *)
val set_surface_blend_mode : surface -> Blend.mode -> unit result
(** {{:http://wiki.libsdl.org/SDL2/SDL_SetSurfaceBlendMode}
SDL_SetSurfaceBlendMode} *)
val set_surface_color_mod : surface -> uint8 -> uint8 -> uint8 -> unit result
(** {{:http://wiki.libsdl.org/SDL2/SDL_SetSurfaceColorMod}
SDL_SetSurfaceColorMod} *)
val set_surface_palette : surface -> palette -> unit result
(** {{:http://wiki.libsdl.org/SDL2/SDL_SetSurfacePalette}SDL_SetSurfacePalette}
{b Note} If you allocated the palette with {!alloc_palette} you
can {!free_palette} after. *)
val set_surface_rle : surface -> bool -> unit result
(** {{:http://wiki.libsdl.org/SDL2/SDL_SetSurfaceRLE}SDL_SetSurfaceRLE} *)
val unlock_surface : surface -> unit
(** {{:http://wiki.libsdl.org/SDL2/SDL_UnlockSurface}SDL_UnlockSurface} *)
(**/**)
val unsafe_surface_of_ptr : nativeint -> surface
val unsafe_ptr_of_surface : surface -> nativeint
(**/**)
(** {2:renderers {{:http://wiki.libsdl.org/SDL2/CategoryRender}Renderers}} *)
type flip
(** {{:https://wiki.libsdl.org/SDL2/SDL_RendererFlip}SDL_RendererFlip} *)
module Flip : sig
val ( + ) : flip -> flip -> flip
(** [f + f'] combines flips [f] and [f']. *)
val none : flip
val horizontal : flip
val vertical : flip
end
type texture
(** {{:https://wiki.libsdl.org/SDL2/SDL_Texture}SDL_Texture} *)
(**/**)
val unsafe_texture_of_ptr : nativeint -> texture
val unsafe_ptr_of_texture : texture -> nativeint
(**/**)
type renderer
(** {{:https://wiki.libsdl.org/SDL2/SDL_Renderer}SDL_Renderer} *)
(**/**)
val unsafe_renderer_of_ptr : nativeint -> renderer
val unsafe_ptr_of_renderer : renderer -> nativeint
(**/**)
module Renderer : sig
type flags
(** {{:https://wiki.libsdl.org/SDL2/SDL_RendererFlags}SDL_RendererFlags} *)
val ( + ) : flags -> flags -> flags
(** [f + f'] combines flags [f] and [f']. *)
val ( - ) : flags -> flags -> flags
(** [f - f'] removes flag [f'] from [f]. *)
val test : flags -> flags -> bool
(** [test flags mask] is [true] if any of the flags in [mask] is
set in [flags]. *)
val eq : flags -> flags -> bool
(** [eq f f'] is [true] if the flags are equal. *)
val software : flags
val accelerated : flags
val presentvsync : flags
val targettexture : flags
end
type renderer_info =
{ ri_name : string;
ri_flags : Renderer.flags;
ri_texture_formats : Pixel.format_enum list;
ri_max_texture_width : int;
ri_max_texture_height : int; }
(** {{:https://wiki.libsdl.org/SDL2/SDL_RendererInfo}SDL_RendererInfo} *)
val create_renderer :
?index:int -> ?flags:Renderer.flags-> window -> renderer result
(** {{:http://wiki.libsdl.org/SDL2/SDL_CreateRenderer}SDL_CreateRenderer} *)
val create_software_renderer : surface -> renderer result
(** {{:http://wiki.libsdl.org/SDL2/SDL_CreateSoftwareRenderer}
SDL_CreateSoftwareRenderer} *)
val destroy_renderer : renderer -> unit
(** {{:http://wiki.libsdl.org/SDL2/SDL_DestroyRenderer}SDL_DestroyRenderer} *)
val get_num_render_drivers : unit -> int result
(** {{:http://wiki.libsdl.org/SDL2/SDL_GetNumRenderDrivers}
SDL_GetNumRenderDrivers} *)
val get_render_draw_blend_mode : renderer -> Blend.mode result
(** {{:http://wiki.libsdl.org/SDL2/SDL_GetRenderDrawBlendMode}
SDL_GetRenderDrawBlendMode} *)
val get_render_draw_color : renderer -> (uint8 * uint8 * uint8 * uint8) result
(** {{:http://wiki.libsdl.org/SDL2/SDL_GetRenderDrawColor}
SDL_GetRenderDrawColor} *)
val get_render_driver_info : int -> renderer_info result
(** {{:http://wiki.libsdl.org/SDL2/SDL_GetRenderDriverInfo}
SDL_GetRenderDriverInfo} *)
val get_render_target : renderer -> texture option
(** {{:http://wiki.libsdl.org/SDL2/SDL_GetRenderTarget}SDL_GetRenderTarget} *)
val get_renderer : window -> renderer result
(** {{:http://wiki.libsdl.org/SDL2/SDL_GetRenderer}SDL_GetRenderer} *)
val get_renderer_info : renderer -> renderer_info result
(** {{:http://wiki.libsdl.org/SDL2/SDL_GetRendererInfo}SDL_GetRendererInfo} *)
val get_renderer_output_size : renderer -> (int * int) result
(** {{:http://wiki.libsdl.org/SDL2/SDL_GetRendererOutputSize}
SDL_GetRendererOutputSize} *)
val render_clear : renderer -> unit result
(** {{:http://wiki.libsdl.org/SDL2/SDL_RenderClear}SDL_RenderClear} *)
val render_copy :
?src:rect -> ?dst:rect -> renderer -> texture -> unit result
(** {{:http://wiki.libsdl.org/SDL2/SDL_RenderCopy}SDL_RenderCopy} *)
val render_copy_ex :
?src:rect -> ?dst:rect ->renderer -> texture -> float -> point option ->
flip -> unit result
(** {{:http://wiki.libsdl.org/SDL2/SDL_RenderCopyEx}SDL_RenderCopyEx} *)
val render_draw_line :
renderer -> int -> int -> int -> int -> unit result
(** {{:http://wiki.libsdl.org/SDL2/SDL_RenderDrawLine}SDL_RenderDrawLine} *)
val render_draw_line_f :
renderer -> float -> float -> float -> float -> unit result
(** {{:http://wiki.libsdl.org/SDL2/SDL_RenderDrawLineF}SDL_RenderDrawLineF} *)
val render_draw_lines : renderer -> point list -> unit result
(** {{:http://wiki.libsdl.org/SDL2/SDL_RenderDrawLines}SDL_RenderDrawLines} *)
val render_draw_lines_ba :
renderer -> (int32, Bigarray.int32_elt) bigarray -> unit result
(** See {!render_draw_lines}. Each consecutive pair in the array
defines a point.
@raise Invalid_argument if the length of the array is not a
multiple of 2. *)
val render_draw_point : renderer -> int -> int -> unit result
(** {{:http://wiki.libsdl.org/SDL2/SDL_RenderDrawPoint}SDL_RenderDrawPoint} *)
val render_draw_points : renderer -> point list -> unit result
(** {{:http://wiki.libsdl.org/SDL2/SDL_RenderDrawPoints}SDL_RenderDrawPoints} *)
val render_draw_points_ba :
renderer -> (int32, Bigarray.int32_elt) bigarray -> unit result
(** See {!render_draw_points}. Each consecutive pair in the array
defines a point.
@raise Invalid_argument if the length of the array is not a
multiple of 2. *)
val render_draw_point_f : renderer -> float -> float -> unit result
(** SDL_RenderDrawPointF *)
val render_draw_points_f : renderer -> fpoint list -> unit result
(** {{:http://wiki.libsdl.org/SDL2/SDL_RenderDrawPointsF}
SDL_RenderDrawPointsF} *)
val render_draw_points_f_ba :
renderer -> (float, Bigarray.float32_elt) bigarray -> unit result
(** See {!render_draw_points}. Each consecutive pair in the array
defines a point.
@raise Invalid_argument if the length of the array is not a
multiple of 2. *)
val render_draw_rect : renderer -> rect option -> unit result
(** {{:http://wiki.libsdl.org/SDL2/SDL_RenderDrawRect}SDL_RenderDrawRect} *)
val render_draw_rects : renderer -> rect list -> unit result