⚠️ Warning: This is a draft ⚠️

This means it might contain formatting issues, incorrect code, conceptual problems, or other severe issues.

If you want to help to improve and eventually enable this page, please fork RosettaGit's repository and open a merge request on GitHub.

{{libheader|glMLite}} {{libheader|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 noise_gl.ml

One can also interpret it with the native code OCaml toplevel: ocamlnat unix.cmxs bigarray.cmxs -I +glMLite GL.cmxs Glut.cmxs noise_gl.ml

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 (Random.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;