(bind-func load_data
(lambda (tex:Texture* flipped:i32 filename:String*)
;; (println "LOAD:" filename)
;; seems to need to be set
(stbi_set_flip_vertically_on_load flipped)
(let ((width_ptr:i32* (tref-ptr tex 2))
(height_ptr:i32* (tref-ptr tex 3))
(comp_ptr:i32* (salloc))
(data (stbi_load (cstring filename) width_ptr height_ptr comp_ptr 4)))
(cond ((= (pref comp_ptr 0) 4)
(tset! tex 1 GL_RGBA))
((= (pref comp_ptr 0) 3)
(tset! tex 1 GL_RGBA)) ;; rgb should be converted to RGBA
((= (pref comp_ptr 0) 1)
(tset! tex 1 GL_DEPTH_COMPONENT))
(else (println "Unknown componenet depth: " (pref comp_ptr 0)) 1:i32))
(if (null? data)
(begin
(println (stbi_failure_reason)) 1)
(begin
(tset! tex 4 data) 1))
void)))