Skip to content

Instantly share code, notes, and snippets.

@dbuenzli
Last active August 29, 2015 13:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dbuenzli/9050445 to your computer and use it in GitHub Desktop.
Save dbuenzli/9050445 to your computer and use it in GitHub Desktop.
Test case for spinning process with ctypes
(* Spinning with 4.01.0
Compile with:
ocamlfind ocamlc -package tsdl -linkpkg -o spin.byte spin.ml
ocamlfind ocamlopt -package tsdl -linkpkg -o spin.native spin.ml
*)
open Tsdl
let test () =
match Sdl.create_window "Test" ~w:640 ~h:480 Sdl.Window.resizable with
| `Error msg -> Sdl.log "%s" msg
| `Ok w ->
Printf.printf "Pump...\n%!";
Sdl.pump_events ();
Printf.printf "Pumped !\n%!";
let e = Sdl.Event.create () in
let s = Sdl.get_event_state Sdl.Event.window_event in
Printf.printf "Event state: %s" begin match s with
| s when s = Sdl.disable -> "disable"
| s when s = Sdl.enable -> "enable"
| _ -> assert false
end;
Printf.printf "Exit in 1ms!%!";
ignore (Sdl.wait_event_timeout (Some e) 1);
Sdl.destroy_window w;
()
let main () = match Sdl.init Sdl.Init.(video + video + events) with
| `Error msg -> Sdl.log "%s" msg; exit 1
| `Ok () -> test (); exit 0
let () = main ()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment