diff options
author | Yorhel <git@yorhel.nl> | 2010-05-31 18:10:30 +0200 |
---|---|---|
committer | Yorhel <git@yorhel.nl> | 2010-05-31 18:10:30 +0200 |
commit | 5284436d4c5e612e5e66eebf358ced305ad8f5e4 (patch) | |
tree | 8c4b5b196458c9b78685d00c3a79ce013c186eda | |
parent | 963bcfe08d6fbc51e236a9b8dd5be506fe17cdb2 (diff) |
Use ortho for the metaballs and changed them to the alpha channel
This was how I originally intended the metaballs to be used. This looks
like a great way to perform transitions between effects.
-rw-r--r-- | main.ml | 3 | ||||
-rw-r--r-- | metaballs.ml | 29 | ||||
-rw-r--r-- | util.ml | 33 |
3 files changed, 36 insertions, 29 deletions
@@ -11,9 +11,9 @@ let drawFrame () = let t = (Unix.gettimeofday ()) -. starttime in GlClear.clear [`color; `depth]; GlMat.load_identity (); - (*Metaballs.draw t;*) (*Archzoom.draw t;*) Cube.draw t; + Metaballs.draw t; Util.drawInfo height width t; Glut.swapBuffers () @@ -54,6 +54,7 @@ let _ = GlLight.material ~face:`both (`shininess 50.0); GlLight.material ~face:`both (`emission (0.0, 0.0, 0.0, 1.0)); + GlTex.env (`mode `modulate); Gl.enable `depth_test; Gl.enable `cull_face; GlMat.mode `projection; diff --git a/metaballs.ml b/metaballs.ml index f90d6fd..85ca08f 100644 --- a/metaballs.ml +++ b/metaballs.ml @@ -3,7 +3,7 @@ (* texture on which we're drawing the metaballs *) -let tex = GlPix.create `float ~format:`luminance ~width:128 ~height:128 +let tex = GlPix.create `float ~format:`alpha ~width:128 ~height:128 (* OpenGL texture ID *) let tex_id = ref None @@ -35,14 +35,16 @@ let calc t = for y = 0 to h-1 do for x = 0 to w-1 do let px = ((float x)/.(float w)) and py = ((float y)/.(float h)) in - let c = (ball px py 0.003 0.5 0.5) +. + let c = 1.3 -. ( + (ball px py 0.003 0.5 0.5) +. (ball px py 0.004 b1x b1y) +. (ball px py 0.007 b2x b2y) +. - (ball px py 0.002 b3x b3y) in - Raw.set_float raw ~pos:(pos ~x:x ~y:y) (c-.0.1); + (ball px py 0.002 b3x b3y)) in + Raw.set_float raw ~pos:(pos ~x:x ~y:y) c; done; done; - GlTex.image2d tex + (* GL_ALPHA8 = 32828; GL_ALPHA16 = 32830 *) + GlTex.image2d ~internal:32828 tex @@ -50,19 +52,16 @@ let calc t = let draw t = settex (); calc t; - Gl.disable `cull_face; Gl.disable `lighting; - GlMat.push (); Gl.enable `texture_2d; - GlMat.translate ~z:(-2.0) (); + Util.setOrtho 1.0 1.0; + GlDraw.color ~alpha:1.0 (0.0, 0.0, 0.0); GlDraw.begins `quads; - GlTex.coord2( 0.0, 1.0); GlDraw.vertex3 (-1.0, 1.0, 0.0); - GlTex.coord2( 1.0, 1.0); GlDraw.vertex3 ( 1.0, 1.0, 0.0); - GlTex.coord2( 1.0, 0.0); GlDraw.vertex3 ( 1.0, -1.0, 0.0); - GlTex.coord2( 0.0, 0.0); GlDraw.vertex3 (-1.0, -1.0, 0.0); + GlTex.coord2 (0.0, 0.0); GlDraw.vertex3 (0.0, 0.0, 0.0); + GlTex.coord2 (1.0, 0.0); GlDraw.vertex3 (1.0, 0.0, 0.0); + GlTex.coord2 (1.0, 1.0); GlDraw.vertex3 (1.0, 1.0, 0.0); + GlTex.coord2 (0.0, 1.0); GlDraw.vertex3 (0.0, 1.0, 0.0); GlDraw.ends (); + Util.setProjection (); Gl.disable `texture_2d; - GlMat.pop (); - Gl.enable `cull_face - @@ -64,7 +64,6 @@ let setTexture pic = GlTex.parameter ~target:`texture_2d (`wrap_t `clamp); GlTex.parameter ~target:`texture_2d (`mag_filter `linear); GlTex.parameter ~target:`texture_2d (`min_filter `linear); - GlTex.env (`mode `modulate); GlTex.image2d pic; tid @@ -137,6 +136,24 @@ let loadObj fn = ) lines +let setOrtho height width = + Gl.disable `depth_test; + GlMat.mode `projection; + GlMat.push (); + GlMat.load_identity (); + GluMat.ortho2d (0.0, width) (0.0, height); + GlMat.mode `modelview; + GlMat.push (); + GlMat.load_identity () + + +let setProjection () = + Gl.enable `depth_test; + GlMat.mode `projection; + GlMat.pop (); + GlMat.mode `modelview; + GlMat.pop () + let fps_frames = ref 0 and fps_last = ref 0.0 and fps_cur = ref 0 @@ -152,14 +169,7 @@ let drawInfo height width t = fps_last := t; fps_frames := 0; ); - (* set ortho *) - GlMat.mode `projection; - GlMat.push (); - GlMat.load_identity (); - GluMat.ortho2d (0.0, width) (0.0, height); - GlMat.mode `modelview; - GlMat.push (); - GlMat.load_identity (); + setOrtho height width; (* draw character *) GlDraw.color (1.0, 1.0, 1.0); (* FPS *) @@ -173,8 +183,5 @@ let drawInfo height width t = (fun c -> Glut.bitmapCharacter Glut.BITMAP_8_BY_13 (Char.code c)) (Printf.sprintf "%6.2f" t); (* reset ortho *) - GlMat.mode `projection; - GlMat.pop (); - GlMat.mode `modelview; - GlMat.pop () + setProjection () |