View Full Version : Graphics in Ocaml.

November 15th, 2007, 05:46 PM
This code is supposed to draw a triangle with OCaml..but I am having a trouble compiling it..

I think it's not the same as compiling a regular .ml file..
Anyway here is the code

let _ =
ignore( Glut.init Sys.argv );
Glut.initDisplayMode ~double_buffer:true ();
ignore (Glut.createWindow ~title:"OpenGL Demo");
let angle t = 10. *. t *. t in
let render () =
GlClear.clear [ `color ];
GlMat.load_identity ();
GlMat.rotate ~angle: (angle (Sys.time ())) ~z:1. ();
GlDraw.begins `triangles;
List.iter GlDraw.vertex2 [-1., -1.; 0., 1.; 1., -1.];
GlDraw.ends ();
Glut.swapBuffers () in
GlMat.mode `modelview;
Glut.displayFunc ~cb:render;
Glut.idleFunc ~cb:(Some Glut.postRedisplay);
Glut.mainLoop ()

Any help will be appreciated :)

November 15th, 2007, 11:57 PM
sudo aptitude update
sudo aptitude install liblablgl-ocaml-dev ocaml-findlib

ocamfind opt graphics_test.ml -package lablgl.glut -linkpkg -o graphics_test

In this case, I've named the file graphics_test.ml . :)

November 16th, 2007, 03:16 PM
Thanks it worked perfectly :)
I owe you one:p

June 24th, 2012, 10:54 AM
I recognise that code :) and thanks for a way of getting it to compile without "Unbound module Glut" error. It's not exactly intuitive though, is it?

I had installed the liblablgl-ocaml package.. I was expecting it to be somewhere the linker could find it already, without having to install a separate program to help the compilation.

Is there a tutorial for starting OCaml in Ubuntu / Debian? If I stick the obvious words into Google, I get an awfully long list of repositories and not much useful (to me) content.