package tsdl

  1. Overview
  2. Docs
Thin bindings to SDL for OCaml

Install

Dune Dependency

Authors

Maintainers

Sources

tsdl-1.1.0.tbz
sha512=f6d429ac5f7d1ea2411fb65f08e454fc5f515879c92e9031afb978dd0c8865739931a83a277fc3bf556e743a710ec8b530717f9e30e353660e1f0219c8293413

doc/index.html

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.