Logo OpenGL Logo Ocaml Logo


GLCaml is an Objective Caml interface for OpenGL versions 1.1, 1.2, 1.3, 1.4, 1.5, 2.0 and 2.1, plus extensions, for the Windows, Linux, Solaris and Mac OS-X operating systems on both 32-bit and 64-bit machines.

It consists of three files:, glcaml.mli and glcaml_stub.c, and is intended as a compact drop-in binding rather than a big standalone library. It is licensed under the BSD License.

The bindings are generated using cleaned up header files from the glext project on Sourceforge. GLCaml is a direct, not particularly type-safe binding to OpenGL. It has the following features:


This version of GLCaml has major API changes with respect to the previous versions. The following changes have been made:

  1. Bigarrays are no longer necessary for using OpenGL functions. Standard Ocaml types (ints, floats, bools and strings and corresponding arrays) are now used.
  2. Enumerated constants (glenums) have been replaced by ints. As a result, there are no more GL_ALL_CAPS constants; these have been replaced by gl_no_caps ints
  3. An exception is now always thrown if an OpenGL call is not available. This is because silent fails can leave mutable parameters in an undefined state.

Using GLCaml, SDLCaml and Win

GLCaml can be used in combination with OcamlSDL, the canonical binding for SDL, or Jean-Christophe Filliatre's SDL bindings, or with lablgtk's GTKGlArea. It can even be used with Ocaml's Graphics module using the Win module bindings provided in this package. Optional bindings for SDL are also provided along with the GLCaml package to enable instant usage, if so desired.

The lablgl OpenGL bindings are typesafe, elegant and portable. However, it only covers OpenGL 1.2. In addition, it's statically linked to the OpenGL import library.

Another OpenGL binding for Ocaml is Nickolay Kolchin-Semyonov's camlgl. It extends OpenGL support to version 1.5 and loads all functions dynamically. It is however unmaintained at the moment.

Sean C. Chapel has built GLCaml on OS-X, and reports that it works with OcamlSDL on OS-X. It has to be compiled with -framework SDL in order to get it to work.

GLCaml supports almost all OpenGL ARB and vendor extensions.

The GLCaml package also contains SDLCaml, a compact drop-in binding for LibSDL. SDLCaml can be used as a small, fast replacement for OcamlSDL. It contains the following files

along with comprehensive documentation and a number of SDL tutorials, translated into Ocaml from the Lazy Foo' Productions tutorials. In addition to the SDL bindings, SDLCaml contains the following convenience functions, all written in OCaml:

Janko Metelko has a number of examples using SDLCaml on his blog.

The GLCaml package also contains Win, a small module allowing OpenGL calls to be used from the Ocaml Graphics module. A number of examples using Ocaml Graphics windows for OpenGL rendering have been provided. This has only been tested on Linux, Solaris and Windows. One of the examples ( shows OpenGL shaders working in an Ocaml Graphics window. Win consists of the following files: