Loading animated 3D data/OCaml: Difference between revisions

m
style improvements
(added ocaml)
 
m (style improvements)
 
(5 intermediate revisions by 4 users not shown)
Line 1:
{{libheader|glMLite}}
 
{{libheader|xml-light}}
 
{{libheader|GLUT}}
 
<lang ocaml>(* loading the libraries *)
 
Line 137 ⟶ 143:
 
let parse_shape_contents c =
let geom = parse_geom(List.hd(List.filterfind filter_geom c))
and appearance = List.fold_left appearance_fold [] c in
let shape = (geom, appearance) in
Line 257 ⟶ 263:
let display scene = function () ->
glClear [GL_COLOR_BUFFER_BIT; GL_DEPTH_BUFFER_BIT];
glLoadIdentity ();
 
List.iter (function
Line 290 ⟶ 296:
glColor3v (get_val3 !t color)
) appearance;
glPushMatrix ();
glScalev (get_val3 !t size);
glutSolidCube ~size:1.0;
glPopMatrix ();
 
| _ -> () (* TODO other primitives *)
Line 302 ⟶ 308:
) scene;
 
glFlush ();
glutSwapBuffers ();
;;
 
Line 309 ⟶ 315:
let reshape ~width ~height =
glMatrixMode GL_PROJECTION;
glLoadIdentity ();
gluPerspective 30. (float width /. float height) 2. 30.;
glViewport 0 0 width height;
glMatrixMode GL_MODELVIEW;
glutPostRedisplay ();
;;
 
Line 325 ⟶ 331:
let () =
ignore(glutInit Sys.argv);
glutInitDisplayMode [GLUT_RGBA; GLUT_DOUBLE; GLUT_DEPTH];
glutInitWindowPosition ~x:200 ~y:200;
glutInitWindowSize ~width:400 ~height:300;
Line 344 ⟶ 350:
glutReshapeFunc ~reshape;
glutKeyboardFunc ~keyboard;
glutMainLoop ();
;;</lang>