views:

333

answers:

2

I am trying to get started with some basic Ocaml programming. To start I wanted to get the OpenGL example from wikipedia running. http://en.wikipedia.org/wiki/Ocaml

    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 ()

The given compiler directive

ocamlc -I +lablGL lablglut.cma lablgl.cma simple.ml -o simple

Just causes and error on line 2, saying that Glut.init is unbound.

I am running this on cygwin, which could be the source of the problem. But does anybody know how to fix it?

+2  A: 

You need to install the LablGL bindings first, as indicated on the Wikipedia page. I don't know what is the best way to do this on Cygwin.

P.S. OpenGL programming is hardly "basic Ocaml programming"

newacct
It looks as though you also need to be using the MSVC version of Ocaml, though I could have just been doing everything wrong.
AlexH
A: 

This is actually kind of a pain to get working on cygwin + windows. The reason you're getting errors is most likely library issues. It might be as simple as copying the opengl dlls into the directory of your executable (try that first). But mostly likely it's a linking problem. Your best bet is to either compile with msvc (kind of painful) or with mingw. mingw works much better (FOR OPENGL) than getting the whole toolchain working in cygwin. But otherwise I prefer cygwin.

--Nico