(bind-func xtm_load_vgimage
(lambda (path)
(let ((w_ptr:i32* (salloc))
(h_ptr:i32* (salloc))
(c_ptr:i32* (salloc))
(data:i8* (SOIL_load_image path w_ptr h_ptr c_ptr SOIL_LOAD_RGBA))
(w (pref w_ptr 0))
(h (pref h_ptr 0))
(c (pref c_ptr 0))
(row:i8* null)
(img (xtm_create_vgimage w h))
(i 0))
(if (null? data)
(begin (printf "Error: image not loaded\n") null)
;; flip image
(begin
(dotimes (i h)
(set! row (pref-ptr data (* i (* w 4))))
(xtm_set_vgimage_subdata img
row
(* w 4)
0
(- h i 1)
w
1))
img)))))