package tsdl

  1. Overview
  2. Docs

Tsdl v1.1.0

Tsdl is an OCaml library providing thin bindings to the cross-platform SDL library.

See the quick start.

Library tsdl

  • Tsdl SDL thin bindings.

Quick start

Toplevel

To use Tsdl in the toplevel with just issue:

ocaml
# #use "topfind";;
# #thread;; (* Only needed if you are using ocaml and < 5.0.0 *)
# #require "tsdl.top";;

This automatically loads the library and opens the Tsdl module.

OpenGL window

The following is the minimum you need to get a working OpenGL window with SDL.

open Tsdl

let main () = match Sdl.init Sdl.Init.(video + events) with
| Error (`Msg e) -> Sdl.log "Init error: %s" e; 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.pump_events ();
        Sdl.delay 3000l;
        Sdl.destroy_window w;
        Sdl.quit ();
        0

let () = if !Sys.interactive then () else exit (main ())

This can be compiled to byte and native code with:

ocamlfind ocamlc -package tsdl -thread -linkpkg -o min.byte min.ml
ocamlfind ocamlopt -package tsdl -thread -linkpkg -o min.native min.ml
OCaml

Innovation. Community. Security.