Image Noise/OCaml/OpenGL

From Rosetta Code
Library: glMLite
Library: GLUT

Compile this program to native-code with the following command:

ocamlopt -o noise_gl.opt bigarray.cmxa unix.cmxa -I +glMLite GL.cmxa Glut.cmxa

One can also interpret it with the native code OCaml toplevel:

ocamlnat unix.cmxs bigarray.cmxs -I +glMLite GL.cmxs Glut.cmxs
open Glut
open GL
let width = 320
let height = 240
let len = width * height
let buff = Bigarray.Array1.create Bigarray.char Bigarray.c_layout len
let t_last = ref (Unix.gettimeofday())
let frames = ref 0
let render () =
for i = 0 to pred len do
buff.{i} <- char_of_int ( 256)
glBitmap width height 0.0 0.0 0.0 0.0 buff;
incr frames;
if !frames = 600 then begin
let t = Unix.gettimeofday() in
Printf.printf "- fps: %f\n%!" ((float !frames) /. (t -. !t_last));
t_last := t;
frames := 0;
let () =
ignore (glutInit Sys.argv);
glutInitDisplayMode [GLUT_RGB; GLUT_DOUBLE];
glutInitWindowSize width height;
ignore (glutCreateWindow "noise");
glutDisplayFunc render;
glutIdleFunc render;