~ubuntu-branches/ubuntu/hardy/lablgl/hardy

« back to all changes in this revision

Viewing changes to LablGlut/examples/nehe/lesson3.ml

  • Committer: Bazaar Package Importer
  • Author(s): Sven Luther
  • Date: 2004-05-26 09:39:17 UTC
  • Revision ID: james.westby@ubuntu.com-20040526093917-uakgrsrv5keom5kn
Tags: upstream-1.00
ImportĀ upstreamĀ versionĀ 1.00

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
(*
 
2
 * This code was created by Jeff Molofee '99 
 
3
 * If you've found this code useful, please let me know.
 
4
 *
 
5
 * Visit Jeff at http://nehe.gamedev.net/
 
6
 * 
 
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
 
10
 *)
 
11
 
 
12
let init_gl width height =
 
13
    GlDraw.shade_model `smooth;
 
14
    GlClear.color (0.0, 0.0, 0.0);
 
15
    GlClear.depth 1.0;
 
16
    GlClear.clear [`color; `depth];
 
17
    Gl.enable `depth_test;
 
18
    GlFunc.depth_func `lequal;
 
19
    GlMisc.hint `perspective_correction `nicest
 
20
 
 
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);
 
33
  GlDraw.ends ();
 
34
  (* Draw the square *)
 
35
  GlMat.translate3 (3.0, 0.0, 0.0);
 
36
  GlDraw.begins `quads;
 
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);
 
42
  GlDraw.ends ();
 
43
  Glut.swapBuffers ()
 
44
 
 
45
(* Handle window reshape events *)
 
46
let reshape_cb ~w ~h =
 
47
  let 
 
48
    ratio = (float_of_int w) /. (float_of_int h) 
 
49
  in
 
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 ()
 
56
 
 
57
(* Handle keyboard events *)
 
58
let keyboard_cb ~key ~x ~y =
 
59
  match key with
 
60
    | 27 (* ESC *) -> exit 0
 
61
    | _ -> ()
 
62
 
 
63
let main () =
 
64
  let 
 
65
    width = 640 and
 
66
    height = 480
 
67
  in
 
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;
 
75
    init_gl width height;
 
76
    Glut.mainLoop ()
 
77
 
 
78
let _ = main ()