Image Noise/OCaml/OpenGL: Difference between revisions
< Image Noise | OCaml
Content added Content deleted
(with ocamlnat) |
imported>Katsumi No edit summary |
||
(One intermediate revision by one other user not shown) | |||
Line 1: | Line 1: | ||
{{libheader|glMLite}} |
{{libheader|glMLite}} |
||
{{libheader|GLUT}} |
|||
Compile this program to native-code with the following command: |
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 |
ocamlopt -o noise_gl.opt bigarray.cmxa unix.cmxa -I +glMLite GL.cmxa Glut.cmxa noise_gl.ml |
||
Line 7: | Line 7: | ||
ocamlnat unix.cmxs bigarray.cmxs -I +glMLite GL.cmxs Glut.cmxs noise_gl.ml |
ocamlnat unix.cmxs bigarray.cmxs -I +glMLite GL.cmxs Glut.cmxs noise_gl.ml |
||
<lang |
<syntaxhighlight lang="ocaml"> |
||
open Glut |
|||
open GL |
open GL |
||
Line 41: | Line 42: | ||
glutDisplayFunc render; |
glutDisplayFunc render; |
||
glutIdleFunc render; |
glutIdleFunc render; |
||
glutMainLoop() |
glutMainLoop() |
||
</syntaxhighlight> |
Latest revision as of 12:09, 20 August 2023
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 () =
glClear [GL_COLOR_BUFFER_BIT];
for i = 0 to pred len do
buff.{i} <- char_of_int (Random.int 256)
done;
glBitmap width height 0.0 0.0 0.0 0.0 buff;
glFlush();
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;
end;
glutSwapBuffers()
let () =
ignore (glutInit Sys.argv);
glutInitDisplayMode [GLUT_RGB; GLUT_DOUBLE];
glutInitWindowSize width height;
ignore (glutCreateWindow "noise");
glutDisplayFunc render;
glutIdleFunc render;
glutMainLoop()