9 let view = { w
= -1; h
= -1; tw
= 0.0; th
= 0.0; };;
12 GlDraw.viewport
0 0 view.w
view.h
;
13 GlMat.mode `projection
;
14 GlMat.load_identity
();
15 GlMat.mode `modelview
;
16 GlMat.load_identity
();
17 GluMat.ortho2d ~x
:(0.0, view.tw
) ~y
:(0.0, view.th
);
26 let keyboard ~key ~x ~y
=
27 begin match Char.chr key
with
28 | '
\027'
| 'q'
-> exit
0
32 Glut.postRedisplay
();
42 GlClear.clear
[`color
];
44 draw `quads
(fun () ->
45 GlTex.coord2
(0.0, 0.0);
46 GlDraw.vertex2
(0.0, view.th
);
48 GlTex.coord2
(1.0, 0.0);
49 GlDraw.vertex2
(view.tw
, view.th
);
51 GlTex.coord2
(1.0, 1.0);
52 GlDraw.vertex2
(view.tw
, 0.0);
54 GlTex.coord2
(0.0, 1.0);
55 GlDraw.vertex2
(0.0, 0.0);
62 let nto_name = ref None
in
63 let swap = ref false in
64 let setsome r s
= r
:= Some s
in
66 ["-index", Arg.Set_string
Xff.index_path
, " <path> to index"
67 ;"-base", Arg.String
(setsome Xff.base_path
), " <directory> base"
68 ;"-level", Arg.Set_int
level, " <level> mipmap level"
69 ;"-swap", Arg.Set
swap, " swap width and height"
72 Arg.parse
(Arg.align
spec) (setsome nto_name) "Usage: imgv image.nto";
75 | None
-> failwith
"NTO name not specified"
76 | Some s
-> Filename.basename s
78 let xff, sbuf
= Xff.test2
nto_name in
79 let nto = Nto.r
xff sbuf
() in
80 let image2d level (w
, h
, data
) =
81 let w, h
= if !swap then (h
, w) else (w, h
) in
82 let id = GlTex.gen_texture
() in
83 Gl.enable `texture_2d
;
84 GlTex.bind_texture `texture_2d
id;
85 GlTex.env
(`mode `replace
);
86 GlTex.parameter `texture_2d
(`mag_filter `linear
);
87 GlTex.parameter `texture_2d
(`min_filter `linear
);
88 GlTex.parameter `texture_2d
(`wrap_s `repeat
);
89 GlTex.parameter `texture_2d
(`wrap_t `repeat
);
90 let raw = Raw.of_string data `ubyte
in
91 let pix = GlPix.of_raw
raw `rgba
w h
in
92 GlTex.image2d ~
level pix
95 if !level < 0 || !level >= Array.length
nto
98 Printf.sprintf
"invalid mipmap level %d, must be in [0..%d]"
100 (pred
(Array.length
nto))
106 let (w, h
, img
) as nto = nto.(level) in
107 let w, h
= if !swap then (h
, w) else (w, h
) in
112 let _ = Glut.init
Sys.argv
in
113 let () = Glut.initDisplayMode ~depth
:true ~double_buffer
:true () in
114 let () = Glut.initWindowSize
w h
in
115 let title = Printf.sprintf
"%s (%dx%d)" nto_name w h
in
116 let _ = Glut.createWindow
title in
117 let () = Glut.displayFunc
display in
118 let () = Glut.reshapeFunc
reshape in
119 let () = Glut.keyboardFunc
keyboard in
121 let () = Glut.mainLoop
() in