-
Notifications
You must be signed in to change notification settings - Fork 0
/
gl_utils.ml
58 lines (45 loc) · 1.42 KB
/
gl_utils.ml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
open Tgl4
let ( let* ) x f = match x with Ok v -> f v | Error _ as e -> e
let bigarray_of k a = Bigarray.(Array1.of_array k c_layout a)
let bigarray_create k len = Bigarray.(Array1.create k c_layout len)
let set_int =
let a = bigarray_create Bigarray.int32 1 in
fun f i ->
a.{0} <- Int32.of_int i ;
f a
let get_int =
let a = bigarray_create Bigarray.int32 1 in
fun f ->
f a ;
Int32.to_int a.{0}
let create_buffer b =
let id = get_int (Gl.gen_buffers 1) in
let bytes = Gl.bigarray_byte_size b in
Gl.bind_buffer Gl.array_buffer id ;
Gl.buffer_data Gl.array_buffer bytes (Some b) Gl.static_draw ;
id
let delete_buffer bid = set_int (Gl.delete_buffers 1) bid
let get_string len f =
let a = bigarray_create Bigarray.char len in
f a ; Gl.string_of_bigarray a
let get_string_with_length len f =
let a = bigarray_create Bigarray.char len in
let i = bigarray_create Bigarray.int32 1 in
f (Some i) a ;
let _ret_len = Int32.to_int i.{0} in
Gl.string_of_bigarray a
let str = Printf.sprintf
let text_rectangle x y w h =
( Gl.triangles
, [|x; y; 0.; x +. w; y; 0.; x +. w; y +. h; 0.; x; y +. h; 0.|]
, [|0.; 1.; 1.; 1.; 1.; 0.; 0.; 0.|]
, [|0; 1; 3; 2; 1; 3|] )
let color_to_floats (r, g, b) =
(float r /. 255., float g /. 255., float b /. 255.)
let flatten_result_list l =
List.fold_right
(fun g acc ->
let* l = acc in
let* geom = g in
Ok (geom :: l) )
l (Ok [])