1
(* $Id: texturesurf.ml,v 1.1 2003/09/25 13:54:10 raffalli Exp $ *)
2
(* Converted to lablglut by Issac Trotts on July 25, 2002 *)
7
[|[|0.0; 0.0; 0.0; 1.0|];
8
[|1.0; 0.0; 1.0; 1.0|]|]
11
[|[|-1.5; -1.5; 4.9; -0.5; -1.5; 2.0; 0.5; -1.5; -1.0; 1.5; -1.5; 2.0|];
12
[|-1.5; -0.5; 1.0; -0.5; -0.5; 3.0; 0.5; -0.5; 0.0; 1.5; -0.5; -1.0|];
13
[|-1.5; 0.5; 4.0; -0.5; 0.5; 0.0; 0.5; 0.5; 3.0; 1.5; 0.5; 4.0|];
14
[|-1.5; 1.5; -2.0; -0.5; 1.5; -2.0; 0.5; 1.5; 0.0; 1.5; 1.5; -1.0|]|]
22
GlClear.clear [`color;`depth];
23
GlDraw.color (1.0,1.0,1.0);
24
GlMap.eval_mesh2 ~mode:`fill ~range1:(0,20) ~range2:(0,20);
30
GlPix.create `ubyte ~height:image_height ~width:image_width ~format:`rgb in
31
let raw = GlPix.to_raw image
32
and pos = GlPix.raw_pos image in
33
for i = 0 to image_width - 1 do
34
let ti = 2.0 *. pi *. float i /. float image_width in
35
for j = 0 to image_height - 1 do
36
let tj = 2.0 *. pi *. float j /. float image_height in
37
Raw.sets raw ~pos:(pos ~x:j ~y:i)
38
(Array.map ~f:(fun x -> truncate (127.0 *. (1.0 +. x)))
39
[|sin ti; cos (2.0 *. ti); cos (ti +. tj)|]);
45
let ctrlpoints = Raw.of_matrix ~kind:`double ctrlpoints
46
and texpts = Raw.of_matrix ~kind:`double texpts in
47
GlMap.map2 ~target:`vertex_3
48
(0.0, 1.0) ~order:4 (0.0, 1.0) ~order:4 ctrlpoints;
49
GlMap.map2 ~target:`texture_coord_2
50
(0.0,1.0) ~order:2 (0.0,1.0) ~order:2 texpts;
51
Gl.enable `map2_texture_coord_2;
52
Gl.enable `map2_vertex_3;
53
GlMap.grid2 ~n1:20 ~range1:(0.0,1.0) ~n2:20 ~range2:(0.0,1.0);
54
let image = make_image () in
55
GlTex.env (`mode `decal);
56
List.iter ~f:(GlTex.parameter ~target:`texture_2d)
60
`min_filter `nearest ];
62
List.iter ~f:Gl.enable [`texture_2d;`depth_test;`normalize];
63
GlDraw.shade_model `flat
65
let my_reshape ~w ~h =
66
GlDraw.viewport ~x:0 ~y:0 ~w ~h;
67
GlMat.mode `projection;
68
GlMat.load_identity ();
69
let r = float h /. float w in
71
GlMat.ortho ~x:(-4.0, 4.0) ~y:(-4.0 *. r, 4.0 *. r) ~z:(-4.0, 4.0)
73
GlMat.ortho ~x:(-4.0 /. r, 4.0 /. r) ~y:(-4.0, 4.0) ~z:(-4.0, 4.0);
74
GlMat.mode `modelview;
75
GlMat.load_identity ();
76
GlMat.rotate ~angle:85. ~x:1. ~y:1. ~z:1. ()
79
ignore(Glut.init Sys.argv);
80
Glut.initDisplayMode ~alpha:true ~depth:true ~double_buffer:true () ;
81
Glut.initWindowSize ~w:300 ~h:300 ;
82
ignore(Glut.createWindow ~title:"Texture Surf");
84
Glut.reshapeFunc ~cb:my_reshape ;
85
Glut.displayFunc ~cb:display ;
86
Glut.specialFunc ~cb:(fun ~key ~x ~y ->
88
| Glut.KEY_UP -> GlMat.rotate ~angle:(-5.) ~z:1.0 (); display ()
89
| Glut.KEY_DOWN -> GlMat.rotate ~angle:(5.) ~z:1.0 (); display ()
90
| Glut.KEY_LEFT -> GlMat.rotate ~angle:(5.) ~x:1.0 (); display ()
91
| Glut.KEY_RIGHT -> GlMat.rotate ~angle:(-5.) ~x:1.0 (); display ()
93
Glut.keyboardFunc ~cb:(fun ~key ~x ~y ->
95
| 27 (*esc*) -> exit 0