2
* This code was created by Jeff Molofee '99
3
* If you've found this code useful, please let me know.
5
* Visit Jeff at http://nehe.gamedev.net/
7
* Ported to O'Caml/lablglut by Jeffrey Palmer 8/02
8
* For port-specific issues, comments, etc., please
9
* contact jeffrey.palmer@acm.org
12
let init_gl width height =
13
GlDraw.shade_model `smooth;
14
GlClear.color (0.0, 0.0, 0.0);
16
GlClear.clear [`color; `depth];
17
Gl.enable `depth_test;
18
GlFunc.depth_func `lequal;
19
GlMisc.hint `perspective_correction `nicest
21
let draw_gl_scene () =
22
GlClear.clear [`color; `depth];
23
GlMat.load_identity ();
24
(* Draw the triangle *)
25
GlMat.translate3 (-1.5, 0.0, -6.0);
26
GlDraw.begins `triangles;
27
GlDraw.color ( 1.0, 0.0, 0.0);
28
GlDraw.vertex3 ( 0.0, 1.0, 0.0);
29
GlDraw.color ( 0.0, 1.0, 0.0);
30
GlDraw.vertex3 (-1.0, -1.0, 0.0);
31
GlDraw.color ( 0.0, 0.0, 1.0);
32
GlDraw.vertex3 ( 1.0, -1.0, 0.0);
35
GlMat.translate3 (3.0, 0.0, 0.0);
37
GlDraw.color ( 0.5, 0.5, 1.0);
38
GlDraw.vertex3 (-1.0, 1.0, 0.0);
39
GlDraw.vertex3 ( 1.0, 1.0, 0.0);
40
GlDraw.vertex3 ( 1.0, -1.0, 0.0);
41
GlDraw.vertex3 (-1.0, -1.0, 0.0);
45
(* Handle window reshape events *)
46
let reshape_cb ~w ~h =
48
ratio = (float_of_int w) /. (float_of_int h)
50
GlDraw.viewport 0 0 w h;
51
GlMat.mode `projection;
52
GlMat.load_identity ();
53
GluMat.perspective 45.0 ratio (0.1, 100.0);
54
GlMat.mode `modelview;
55
GlMat.load_identity ()
57
(* Handle keyboard events *)
58
let keyboard_cb ~key ~x ~y =
60
| 27 (* ESC *) -> exit 0
68
ignore (Glut.init Sys.argv);
69
Glut.initDisplayMode ~alpha:true ~depth:true ~double_buffer:true ();
70
Glut.initWindowSize width height;
71
ignore (Glut.createWindow "O'Caml OpenGL Lesson 3");
72
Glut.displayFunc draw_gl_scene;
73
Glut.keyboardFunc keyboard_cb;
74
Glut.reshapeFunc reshape_cb;