deps.sh for fetching mupdf deps
[llpp.git] / glutils.ml
blob93da2641c7776ee245a986d04de32aaff9042215
1 external drawstr : int -> int -> int -> string -> float = "ml_draw_string";;
2 external measurestr : int -> string -> float = "ml_measure_string";;
4 let traw = Raw.create_static `float ~len:8;;
5 let vraw = Raw.create_static `float ~len:8;;
7 let filledrect2 x0 y0 x1 y1 x2 y2 x3 y3 =
8 Raw.sets_float vraw ~pos:0 [| x0; y0; x1; y1; x2; y2; x3; y3 |];
9 GlArray.vertex `two vraw;
10 GlArray.draw_arrays `triangle_strip ~first:0 ~count:4;
13 let filledrect1 x0 y0 x1 y1 = filledrect2 x0 y0 x0 y1 x1 y0 x1 y1;;
15 let filledrect x0 y0 x1 y1 =
16 GlArray.disable `texture_coord;
17 filledrect1 x0 y0 x1 y1;
18 GlArray.enable `texture_coord;
21 let linerect x0 y0 x1 y1 =
22 GlArray.disable `texture_coord;
23 Raw.sets_float vraw ~pos:0 [| x0; y0; x0; y1; x1; y1; x1; y0 |];
24 GlArray.vertex `two vraw;
25 GlArray.draw_arrays `line_loop ~first:0 ~count:4;
26 GlArray.enable `texture_coord;
29 let drawstring size x y s =
30 Gl.enable `blend;
31 Gl.enable `texture_2d;
32 GlFunc.blend_func ~src:`src_alpha ~dst:`one_minus_src_alpha;
33 ignore (drawstr size x y s);
34 Gl.disable `blend;
35 Gl.disable `texture_2d;
38 let drawstring1 size x y s =
39 drawstr size x y s;
42 let drawstring2 size x y fmt =
43 Printf.kprintf (drawstring size (x+1) (y+size+1)) fmt
46 let makecheckers () =
47 (* Based on lablGL-1.04/LablGlut/examples/lablGL/checker.ml which had
48 following to say:
49 converted by Issac Trotts. July 25, 2002 *)
50 let image = GlPix.create `ubyte ~format:`luminance ~width:2 ~height:2 in
51 Raw.sets_string (GlPix.to_raw image) ~pos:0 "\255\200\200\255";
52 let id = GlTex.gen_texture () in
53 GlTex.bind_texture ~target:`texture_2d id;
54 GlPix.store (`unpack_alignment 1);
55 GlTex.image2d image;
56 List.iter (GlTex.parameter ~target:`texture_2d)
57 [ `mag_filter `nearest; `min_filter `nearest ];
58 id;