(bind-func ai_load_ogl_texture_from_buffer
(lambda (buffer buflen tex_id:i32)
;; if tex_id is 0, generate a new texture
(if (= tex_id 0)
(let ((texid_ptr:i32* (salloc)))
(glGenTextures 1 texid_ptr)
(set! tex_id (pref texid_ptr 0))))
;; (stbi_set_flip_vertically_on_load 1)
(let ((width_ptr:i32* (salloc))
(height_ptr:i32* (salloc))
(comp_ptr:i32* (salloc))
(data (stbi_load_from_memory buffer buflen width_ptr height_ptr comp_ptr 4)))
(if (null? data)
(begin (println (stbi_failure_reason))
0)
(begin
(glActiveTexture GL_TEXTURE0)
(glBindTexture GL_TEXTURE_2D tex_id)
(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 "error in ai_load_ogl_texture")
tex_id)))))