Open the module to use it, this defines only the module
Note. The module initialization code calls SDL_SetMainReady.
Release v0.9.3 — SDL 2.0.5 —
C names are transformed as follows. The
SDL_ is mapped to the
Tsdl.Sdl, for the rest add an underscore between each
minuscule and majuscule and lower case the result
SDL_GetError maps to
Tsdl.Sdl.get_error). Part of the name
may also be wrapped by a module, (e.g. SDL_INIT_VIDEO becomes
Tsdl.Sdl.Init.video). If you open
Tsdl, your code will look
mostly like SDL code but in accordance with OCaml's programming
conventions. Exceptions to the naming convention do occur for
All functions that return an
Tsdl.Sdl.result have the string
Sdl.get_error () in the
Error (`Msg _) case.
Most bit fields and enumerants are not mapped to variants, they
are represented by OCaml values of a given abstract type in a
specific module with a composition operator to combine them and a
testing operator to test them. The flags for initializing SDL in the
Tsdl.Sdl.Init is an example of that:
Using variants in that case is inconvenient for the binding function and of limited use since most of the time bit fields are given to setup state and, as such, are less likley to be used for pattern matching.
match Sdl.init Sdl.Init.(video + timer + audio) with | Error _ -> ... | Ok () -> ...
Tsdl in the toplevel with
findlib just issue:
> #use "topfind";; > #require "tsdl.top";;
This automatically loads the library and opens the
The following is the minimum you need to get a working OpenGL window with SDL.
open Tsdl open Result let main () = match Sdl.init Sdl.Init.video with | Error (`Msg e) -> Sdl.log "Init error: %s" e; exit 1 | Ok () -> match Sdl.create_window ~w:640 ~h:480 "SDL OpenGL" Sdl.Window.opengl with | Error (`Msg e) -> Sdl.log "Create window error: %s" e; exit 1 | Ok w -> Sdl.delay 3000l; Sdl.destroy_window w; Sdl.quit (); exit 0 let () = main ()
This can be compiled to byte and native code with:
> ocamlfind ocamlc -package tsdl -linkpkg -o min.byte min.ml > ocamlfind ocamlopt -package tsdl -linkpkg -o min.native min.ml