Created
October 27, 2012 09:03
-
-
Save wakita/3963663 to your computer and use it in GitHub Desktop.
lablGL のデモ --- 3D グラフィクスが 45 行の OCaml でできました.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 () |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
出力結果はこちら
http://gyazo.com/7214667bcf5c02a345f6630519f6588f