0 
 1 (* main *)
 2 let () =
 3   (* Create the main window *)
 4   let mode, settings =
 5     { SFRenderWindow.width = 800; height = 600; bitsPerPixel = 32 },
 6     { SFRenderWindow.depthBits = 24; stencilBits = 8; antialiasingLevel = 0 }
 7   in
 8   let app = SFRenderWindow.create mode "SFML window" [`resize; `close] settings in
 9 
10   (* Load a sprite to display *)
11   let image = SFImage.createFromFile "cute_image.jpg" in
12   let sprite = SFSprite.create() in
13   SFSprite.setImage sprite image;
14 
15   (* Create a graphical string to display *)
16   let font = SFFont.createFromFile ~charSize:50 "./data/some_font.ttf" in
17   let text = SFString.create() in
18   SFString.setText text "Hello OCaml-SFML";
19   SFString.setFont text font;
20   SFString.setSize text 36.0;
21   SFString.setPosition2 text (20.0, 50.0);
22 
23   (* Load a music to play *)
24   let music = SFMusic.createFromFile "./data/nice_music.ogg" in
25   SFMusic.setVolume music 10.0;
26 
27   (* Play the music *)
28   SFMusic.play music;
29 
30   (* Create a rectangle shape *)
31   let shape =
32     SFShape.createRectangle
33       ~p1:(24.0, 100.0) ~p2:(330.0, 120.0)
34       ~color:(SFColor.RGB(255,0,0))
35       ~outline:1.0
36       ~outlineCol:(SFColor.RGB(0,255,0))
37   in
38 
39   (* Start the game loop *)
40   while SFRenderWindow.isOpened app do
41     (* Process events *)
42     let rec proc_ev() =
43       match SFRenderWindow.getEvent app with
44       | Some SFEvent.Closed
45       | Some SFEvent.KeyPressed (SFKey.Escape,_,_,_) ->
46           (* Close the window: exit *)
47           SFRenderWindow.close app
48 
49       | None -> ()
50       | _ -> proc_ev()
51     in
52     proc_ev();
53 
54     (* Clear the screen *)
55     SFRenderWindow.clear app SFColor.black;
56 
57     (* Draw the sprite *)
58     SFRenderWindow.drawSprite app sprite;
59 
60     (* Draw the string *)
61     SFRenderWindow.drawString app text;
62 
63     (* Draw the rectangle shape *)
64     SFRenderWindow.drawShape app shape;
65 
66     (* Update the window *)
67     SFRenderWindow.display app;
68   done;
69 
70   (* Cleanup resources that need to *)
71   (* (Read the doc to know which needs to) *)
72   SFMusic.destroy music;
73   SFShape.destroy shape;
74   SFRenderWindow.destroy app;
75 ;;
4C