OCamlSDL Logo
Get OCamlSDL at SourceForge.net
OCamlSDL
the library
More complete tutorial made by Volker Grabsch
You could find the new tutorial at http://wiki.njh.eu/OCaml_and_SDL
Makefile
OCAMLMAKEFILE = ../OCamlMakefile #where you can find the file OCamlMakefile

SOURCES = foobar.ml
RESULT  = foobar

INCDIRS=+sdl 
LIBS=bigarray sdl 


# Add +lablGL to INCDIRS if you use Sdlgl
# and lablgl to LIBS


TRASH=*~

-include $(OCAMLMAKEFILE) # you could retreive the OCamlMakefile

Code samples

Dummy sample: INITIALIZING SDL
open Sdl;; 

init [`EVERYTHING];; 

quit();;


VIDEO sample: Putting a red pixel
open Sdl;;
open Sdlvideo;; 

init [`VIDEO];; (* only video *) 

(* opening a windows 320x200 16 bpp *)
let (bpp, w, h) = (16, 320, 200);;
let screen = set_video_mode ~w ~h ~bpp [`HWSURFACE];; (* define some colors *)

(* fill screen with white color
   putting a pixel in center of screen *)

fill_rect screen (map_RGB screen white);;
put_pixel screen ~x:160 ~y:100 red;;
flip screen;;                     

quit();;


CDROM sample: Playing the first track
open Sdl;;
open Sdlcdrom;;

init [`CDROM];;

let my_cdrom = cd_open (get_num_drives() -1);;
cd_play_track my_cdrom ((cd_info my_cdrom).tracks.(0));;
cd_close mycdrom;;
quit();;


MIXER sample: Playing a wave
open Sdl;;
open Sdlmixer;;

init[`AUDIO];; (* only AUDIO initialisation *)

open_audio ~freq:44100 ();;
let c = loadWAV "/tmp/foobar.wav";; (* foobar.wav is a simple WAV file*)
play_sound c;;
free_chunk c;;
close_audio();;
quit();;




Screenshots

Yet to come

$Date: 2007/04/24 22:35:58 $