Skip to content

Instantly share code, notes, and snippets.

@wakita
Created October 27, 2012 09:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wakita/3963663 to your computer and use it in GitHub Desktop.
Save wakita/3963663 to your computer and use it in GitHub Desktop.
lablGL のデモ --- 3D グラフィクスが 45 行の OCaml でできました.
let pi = acos (-1.);;
let lighting () =
List.iter (GlLight.light ~num:0)
[ `ambient (0.4, 0.4, 0.4, 1.0); `diffuse (1.0, 1.0, 1.0, 1.0);
`specular (1.0, 1.0, 1.0, 1.0); `position (1.0, 1.0, 1.0, 0.0) ];
GlFunc.depth_func `less;
List.iter Gl.enable [`lighting; `light0; `depth_test];;
let solid_sphere ?(x=0.0) ?(y=0.0) ?(z=0.0) ?(radius=1.0) () =
let open GlMat in
push ();
translate ~x ~y ~z ();
GluQuadric.sphere ~radius ~slices:32 ~stacks:32 ();
pop ();;
let display () =
GlClear.clear [`color; `depth];
for i = 1 to 20 do
let z = float (-i * 5) in
solid_sphere ~x:(5.0) ~z ();
solid_sphere ~x:(-5.0) ~z ();
solid_sphere ~y:(5.0) ~z ();
solid_sphere ~y:(-5.0) ~z ();
done;
Gl.flush ();;
let reshape ~w ~h =
let open GlMat in
GlDraw.viewport ~x:0 ~y:0 ~w ~h;
mode `projection;
load_identity ();
GluMat.perspective ~fovy: 40.0 ~aspect: (float w /. float h) ~z: (0.1, 100.0);
mode `modelview;;
let _ =
let open Glut in
init ~argv:Sys.argv;
initDisplayMode ~alpha:true ~depth:true ();
initWindowSize ~w:500 ~h:500;
createWindow ~title:"Scene";
lighting ();
reshapeFunc ~cb:reshape;
displayFunc ~cb:display;
mainLoop ()
@wakita
Copy link
Author

wakita commented Oct 27, 2012

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment