summaryrefslogtreecommitdiff
path: root/main.ml
blob: dbbc3f7eb524dbc3f94ada5060b2bfc14cffcc1d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65


(* window dimensions, as float because it's mostly needed as such
 * (float <-> int conversions are expensive and annoying to type) *)
let width = 960.0 and height = 540.0
let starttime = Unix.gettimeofday ()



let drawFrame () =
  let t = (Unix.gettimeofday ()) -. starttime in
  GlClear.clear [`color; `depth];
  GlMat.load_identity ();
  (*Metaballs.draw t;*)
  (*Archzoom.draw t;*)
  Cube.draw t;
  Util.drawInfo height width t;
  Glut.swapBuffers ()



let _ =
  (* init glut *)
  ignore (Glut.init Sys.argv);
  Glut.initDisplayMode ~alpha:true ~depth:true ~double_buffer:true ();
  Glut.initWindowSize (truncate width) (truncate height);
  ignore (Glut.createWindow "De Neuspeuteraars!");
  Glut.idleFunc (Some drawFrame);
  Glut.keyboardFunc (fun ~key ~x ~y ->
    Printf.printf "Exited after %.3fs\n" ((Unix.gettimeofday ())-.starttime);
    flush stdout;
    exit 0
  );
  (* init gl *)
  GlClear.color (0.0, 0.0, 0.0);
  GlClear.depth 1.0;
  Gl.enable `blend;
  GlFunc.blend_func `src_alpha `one_minus_src_alpha;

  (* Some nice articles about lighting:
   * http://www.sjbaker.org/steve/omniv/opengl_lighting.html
   * http://www.spacesimulator.net/tut5_vectors_and_lighting.html *)
  GlDraw.shade_model `smooth;
  Gl.enable `light0;
  GlLight.light 0 (`position (1.0, 1.0, 0.0, 1.0));
  GlLight.light 0 (`ambient  (0.0, 0.0, 0.0, 1.0));
  GlLight.light 0 (`diffuse  (0.8, 0.8, 0.8, 1.0));
  GlLight.light 0 (`specular (1.0, 1.0, 1.0, 1.0));
  GlLight.light_model (`ambient (0.2, 0.2, 0.2, 1.0));
  Gl.enable `color_material;
  (* This doesn't seem to do what I want...
  GlLight.color_material ~face:`both `ambient_and_diffuse;
  GlLight.material ~face:`both (`specular (1.0, 1.0, 1.0, 0.3));
  GlLight.material ~face:`both (`emission (0.0, 0.0, 0.0, 0.3));*)

  Gl.enable `depth_test;
  Gl.enable `cull_face;
  GlMat.mode `projection;
  GlMat.load_identity ();
  GluMat.perspective ~fovy:60.0 ~aspect:(width /. height) ~z:(0.1,100.0);
  GlDraw.viewport 0 0 (truncate width) (truncate height);
  GlMat.mode `modelview;
  (* run *)
  Glut.mainLoop ()