(bind-func Texture_bind_image
(lambda (tex:Texture filename)
;; seems to need to be set
(stbi_set_flip_vertically_on_load 1)
(let ((width_ptr:i32* (salloc))
(height_ptr:i32* (salloc))
(comp_ptr:i32* (salloc))
(data (stbi_load filename width_ptr height_ptr comp_ptr 4)))
(if (null? data)
(begin (println (stbi_failure_reason))
-1)
(begin
(glActiveTexture GL_TEXTURE0)
(glBindTexture GL_TEXTURE_2D tex)
(glTexImage2D GL_TEXTURE_2D 0
GL_RGBA
(pref width_ptr 0)
(pref height_ptr 0)
0
GL_RGBA
GL_UNSIGNED_BYTE
data)
;; set some parameters
(glTexParameteri GL_TEXTURE_2D GL_TEXTURE_WRAP_S GL_CLAMP_TO_EDGE)
(glTexParameteri GL_TEXTURE_2D GL_TEXTURE_WRAP_T GL_CLAMP_TO_EDGE)
(glTexParameteri GL_TEXTURE_2D GL_TEXTURE_MIN_FILTER GL_LINEAR)
(glTexParameteri GL_TEXTURE_2D GL_TEXTURE_MAG_FILTER GL_LINEAR)
(gl_print_error "couldn't Texture_bind_image")
tex)))))