let vertices = [( 1.0, 1.0, 1.0); (-.1.0, -.1.0, 1.0); (-.1.0, 1.0, -.1.0); ( 1.0, -.1.0, -.1.0);] let faces = [[0; 1; 2]; [0; 3; 1]; [0; 2; 3]; [1; 3; 2];] let color = [(1.0, 1.0, 0.0); (0.0, 1.0, 1.0); (1.0, 0.0, 1.0); (0.0, 1.0, 0.0);] let display () = GlClear.clear [`color]; (* типа clear_graph () *) List.iter2 (fun face color -> GlDraw.color color; (* установка цвета рисования *) GlDraw.begins `triangles; List.iter (fun i -> GlDraw.vertex3 (List.nth vertices i)) face; GlDraw.ends (); ) faces color; Gl.flush (); Glut.swapBuffers ();; (* w - 119 a - 97 s - 115 d - 100 q - 113 e - 101 *) let keyboard ~key ~x ~y = match key with | 27 -> exit 0 | 119 -> GlMat.rotate ~angle: 2.0 ~x:1.0 (); display () (* up *) | 115 -> GlMat.rotate ~angle:(-.2.0) ~x:1.0 (); display () (* down *) | 97 -> GlMat.rotate ~angle: 2.0 ~y:1.0 (); display () (* left *) | 100 -> GlMat.rotate ~angle:(-.2.0) ~y:1.0 (); display () (* right *) | 113 -> GlMat.rotate ~angle: 2.0 ~z:1.0 (); display () (* spin left *) | 101 -> GlMat.rotate ~angle:(-.2.0) ~z:1.0 (); display () (* spin right *) | _ -> Printf.printf "Unknown key: %d\n" key;; let main () = ignore(Glut.init Sys.argv); Glut.initDisplayMode ~alpha:true ~depth:true () ; Glut.initWindowSize ~w:500 ~h:500 ; ignore(Glut.createWindow ~title:"Tetrahedron"); GlMat.ortho ~x:(-3.0, 3.0) ~y:(-3.0, 3.0) ~z:(-3.0, 3.0); GlDraw.cull_face `back; Gl.enable `cull_face; GlClear.color (0.5, 0.5, 0.5); (* цвет фона *) Glut.displayFunc ~cb:display; Glut.keyboardFunc ~cb:keyboard; Glut.mainLoop (); ;; main ();;