package tsdl
Module Tsdl.SdlSource
SDL bindings.
Integer types, bigarrays and results
The type for unsigned 8-bit integers.
The type for signed 16-bit integers.
The type for unsigned 16-bit integers.
The type for unsigned 32-bit integers.
The type for unsigned 64-bit integers.
The type for bigarrays.
The type for function results. In the error case, the string is what Sdl.get_error returned.
Basics
Initialization and shutdown
Hints
Errors
Log
Version
Files and IO abstraction
IO abstraction
Filesystem Paths
Video
Colors
Points and vertices
structure SDL_FPoint
Rectangles
structure SDL_FRect
SDL_EnclosePoints. Returns None if all the points were outside the clipping rectangle (if provided).
See enclose_points. Each consecutive pair in the array defines a point.
val intersect_rect_and_line :
rect ->
int ->
int ->
int ->
int ->
((int * int) * (int * int)) optionSDL_IntersectRectAndLine. Returns the clipped segment if it intersects.
Palettes
get_palette_colors p is a copy of the contents of the field colors of s.
get_palette_colors_ba p is a copy of the contents of the field colors of p.
val set_palette_colors_ba :
palette ->
(int, Bigarray.int8_unsigned_elt) bigarray ->
fst:int ->
unit resultSee set_palette_colors. Each consecutive quadruplet defines a color. The data is copied.
Pixels formats
The type for gamma ramps, 256 uint16 values.
val compose_custom_blend_mode :
Blend.factor ->
Blend.factor ->
Blend.operation ->
Blend.factor ->
Blend.factor ->
Blend.operation ->
Blend.modeget_pixel_format_format pf is the field format of pf.
get_pixel_format_bits_pp pf is the field BitsPerPixel of pf.
get_pixel_format_bytes_pp pf is the field BytesPerPixel of pf.
Note If you allocated the palette with alloc_palette you can free_palette after.
Surface
val convert_pixels :
w:int ->
h:int ->
src:Pixel.format_enum ->
('a, 'b) bigarray ->
int ->
dst:Pixel.format_enum ->
('c, 'd) bigarray ->
int ->
unit resultNote Pitches are given in bigarray elements not in bytes.
Warning. Unsafe, make sure your parameters don't result in invalid access to memory.
val create_rgb_surface_from :
('a, 'b) bigarray ->
w:int ->
h:int ->
depth:int ->
pitch:int ->
uint32 ->
uint32 ->
uint32 ->
uint32 ->
surface resultNote The pitch is given in bigarray elements not in bytes.
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 resultval create_rgb_surface_with_format_from :
('a, 'b) bigarray ->
w:int ->
h:int ->
depth:int ->
pitch:int ->
Pixel.format_enum ->
surface resultSee fill_rects. Each consecutive quadruplet defines a rectangle.
get_surface_format_neum s is the pixel format enum of the field format of s.
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.
Warning. The bigarray memory becomes invalid once the surface is unlocked or freed.
Note If you allocated the palette with alloc_palette you can free_palette after.
Renderers
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;
}See render_draw_lines. Each consecutive pair in the array defines a point.
See render_draw_points. Each consecutive pair in the array defines a point.
val render_draw_points_f_ba :
renderer ->
(float, Bigarray.float32_elt) bigarray ->
unit resultSee render_draw_points. Each consecutive pair in the array defines a point.
See render_draw_rects. Each consecutive quadruple in the array defines a rectangle.
See render_draw_rects. Each consecutive quadruple in the array defines a rectangle.
val render_geometry_raw :
?indices:(int32, Bigarray.int32_elt) bigarray ->
?texture:texture ->
renderer ->
xy:(float, Bigarray.float32_elt) bigarray ->
?xy_stride:int ->
color:(int, Bigarray.int8_unsigned_elt) bigarray ->
?color_stride:int ->
uv:(float, Bigarray.float32_elt) bigarray ->
?uv_stride:int ->
num_vertices:int ->
unit ->
unit resultNote. The stride arguments are in bytes, like in the C call. The defaults assume packed arrays.
Textures
val create_texture :
renderer ->
Pixel.format_enum ->
Texture.access ->
w:int ->
h:int ->
texture resultval lock_texture :
texture ->
rect option ->
('a, 'b) Bigarray.kind ->
(('a, 'b) bigarray * int) resultNote. The returned pitch is in bigarray element, not in bytes.
Note The pitch is given in bigarray elements not in bytes.
val update_yuv_texture :
texture ->
rect option ->
y:(int, Bigarray.int8_unsigned_elt) bigarray ->
int ->
u:(int, Bigarray.int8_unsigned_elt) bigarray ->
int ->
v:(int, Bigarray.int8_unsigned_elt) bigarray ->
int ->
unit resultVideo drivers
Displays
Note. Nothing can be done with that.
type display_mode = {dm_format : Pixel.format_enum;dm_w : int;dm_h : int;dm_refresh_rate : int option;dm_driverdata : driverdata option;
}Windows
val create_window :
string ->
?x:int ->
?y:int ->
w:int ->
h:int ->
Window.flags ->
window resultx and y default to Window.pos_undefined.
Note. According to SDL's documentation the surface is freed when the window is destroyed.
val update_window_surface_rects_ba :
window ->
(int32, Bigarray.int32_elt) bigarray ->
unit resultSee update_window_surface_rects. Each consecutive quadruplet defines a rectangle.
OpenGL contexts
SDL_GLContext
SDL_GL_UnbindTexture Warning Segfaults on SDL 2.0.1 see this report.
Vulkan
Screen saver
Message boxes
val show_simple_message_box :
Message_box.flags ->
title:string ->
string ->
window option ->
unit resultClipboard
Input
Keyboard
Mouse
val create_cursor :
(int, Bigarray.int8_unsigned_elt) bigarray ->
(int, Bigarray.int8_unsigned_elt) bigarray ->
w:int ->
h:int ->
hot_x:int ->
hot_y:int ->
cursor resultSDL_ShowCursor with SDL_QUERY.
SDL_ShowCursor. See also get_cursor_shown.
Touch and gestures
Joystick
SDL_JoystickEventState with SDL_QUERY.
SDL_JoystickEventState. See also joystick_get_event_state.
Game controller
SDL_GameControllerAddMappingsFromFile (SDL 2.0.2).
SDL_GameControllerEventState with SDL_QUERY
val game_controller_get_bind_for_axis :
game_controller ->
Controller.axis ->
Controller.button_bindval game_controller_get_bind_for_button :
game_controller ->
Controller.button ->
Controller.button_bindEvents
SDL_EventType. See Event for constants.
event accessors and event_type constants and enumeration.
SDL_EventState with SDL_QUERY.
SDL_EventState. See also get_event_state.
SDL_RegisterEvents called with 1.
Force Feedback
Audio
Audio drivers
Audio devices
The type for audio callbacks.
audio_callback k f is an audio callback. A reference needs to be kept on the callback value until it is no longer needed.
type audio_spec = {as_freq : int;as_format : Audio.format;as_channels : uint8;as_silence : uint8;as_samples : uint8;as_size : uint32;as_callback : audio_callback option;
}val load_wav_rw :
rw_ops ->
audio_spec ->
('a, 'b) Bigarray.kind ->
(audio_spec * ('a, 'b) bigarray) resultval open_audio_device :
string option ->
bool ->
audio_spec ->
Audio.allow ->
(audio_device_id * audio_spec) resultTimer
Platform and CPU information
SDL_HasAVX (SDL 2.0.2)
SDL_HasAVX2 (SDL 2.0.4)
( 2.06.0 )
Power
Locale
The type for SDL_Locale.
Binding Coverage
Everything except the following functions/categories are available.
Unbound categories
- Assertions (cpp based).
- Platform-specific Window Management (not useful at the moment)
- Thread Management (better use another OCaml API)
- Thread Synchronization Primitives (better use another OCaml API)
- Atomic Operations (mostly cpp based)
- File I/O Abstraction (only the minimum was covered for other parts of the API that needs it, better use another OCaml API)
- Shared Object Loading and Function Lookup (use ocaml-ctypes)
- Byte Order and Byte Swapping (cpp based)
- Bit Manipulation (cpp based)
Unbound functions
- SDL_AddHintCallback (avoid callbacks from C to OCaml)
- SDL_DelHintCallback (avoid callbacks from C to OCaml)
- SDL_LogGetOutputFunction (avoid callbacks from C to OCaml)
- SDL_LogSetOutputFunction (avoid callbacks from C to OCaml)
- SDL_CreateWindowFrom (avoid
void *type in the interface) - SDL_GetWindowData (avoid storing OCaml values in C)
- SDL_SetWindowData (avoid storing OCaml values in C)
- SDL_GetWindowWMInfo (avoid
void *type in the interface) - SDL_GL_GetProcAddress (use another OCaml API)
- SDL_GL_LoadLibrary (use another OCaml API)
- SDL_GL_UnloadLibrary (use another OCaml API)
- SDL_AddEventWatch (avoid callbacks from C to OCaml)
- SDL_DelEventWatch (avoid callbacks from C to OCaml)
- SDL_FilterEvents (avoid callbacks from C to OCaml)
- SDL_GetEventFilter (avoid callbacks from C to OCaml)
- SDL_SetEventFilter (avoid callbacks from C to OCaml)
- SDL_PeepEvents (Should certainly be split into more than one fun, functionality also available through other bound functions.)
- SDL_QuitRequested (cpp based)
- SDL_AddTimer (avoid callbacks from C to OCaml, besides callbacks are run on another thread, thus runtime lock support in ocaml-ctypes is needed. Probably better to use another OCaml API anyway)
- SDL_RemoveTimer (avoid callbacks from C to OCaml)
- SDL_SetWindowHitTest (avoid callbacks from C to OCaml)
- SDL_GetAudioStatus (SDL legacy function)
- SDL_OpenAudio (SDL legacy function)
- SDL_CloseAudio (SDL legacy function)
- SDL_LockAudio (SDL legacy function)
- SDL_MixAudio (SDL legacy function)
- SDL_MixAudioFormat (limited functionality, do your own mixing).
- SDL_PauseAudio (SDL legacy function)
- SDL_UnlockAudio (SDL legacy function)