;; where type is GL_UNSIGNED_BYTE GL_FLOAT GL_SHORT etc..
;; if texid is zero then assign a new tex id otherwise use the texid provided
(bind-func gl_load_tex_rect
(lambda (width height channels type data texid)
(let* ((tex:i32* (salloc)))
(pset! tex 0 texid)
;(printf "load image: size: w:%d h:%d: channels:%d\n" width height channels)
(if (< texid 1) (glGenTextures 1 tex))
;(printf "tex: %d\n" (pref tex 0))
(glBindTexture GL_TEXTURE_RECTANGLE_ARB (pref tex 0))
;;(glPixelStorei GL_UNPACK_ALIGNMENT 1) ;; this causes problems!!!
(glTexParameteri GL_TEXTURE_RECTANGLE_ARB GL_TEXTURE_WRAP_S GL_CLAMP_TO_EDGE)
(glTexParameteri GL_TEXTURE_RECTANGLE_ARB GL_TEXTURE_WRAP_T GL_CLAMP_TO_EDGE)
(glTexParameteri GL_TEXTURE_RECTANGLE_ARB GL_TEXTURE_MAG_FILTER GL_NEAREST)
(glTexParameteri GL_TEXTURE_RECTANGLE_ARB GL_TEXTURE_MIN_FILTER GL_NEAREST)
(glTexImage2D GL_TEXTURE_RECTANGLE_ARB 0 channels ;GL_RGBA
width height
0
(cond ((= channels 1) GL_RED)
((= channels 3) GL_RGB)
((= channels 4) GL_RGBA) ;GL_RGBA)
(else GL_RGBA))
type
; GL_FLOAT; GL_UNSIGNED_BYTE
data)
(pref tex 0))))