(bind-func FBO_create_with_textures
(lambda (width height depth_p:i1)
(let ((fbo (FBO_create))
(color_tex (Texture_create))
(depth_tex -1))
(glBindTexture GL_TEXTURE_2D color_tex)
(glTexImage2D GL_TEXTURE_2D 0 GL_RGBA width height 0 GL_RGBA GL_UNSIGNED_BYTE null)
(glTexParameteri GL_TEXTURE_2D GL_TEXTURE_WRAP_S GL_REPEAT)
(glTexParameteri GL_TEXTURE_2D GL_TEXTURE_WRAP_T GL_REPEAT)
(glTexParameteri GL_TEXTURE_2D GL_TEXTURE_MIN_FILTER GL_NEAREST)
(glTexParameteri GL_TEXTURE_2D GL_TEXTURE_MAG_FILTER GL_NEAREST)
(glBindFramebuffer GL_FRAMEBUFFER (FBO_id fbo))
(glFramebufferTexture2D GL_FRAMEBUFFER GL_COLOR_ATTACHMENT0 GL_TEXTURE_2D color_tex 0)
(if depth_p
(set! depth_tex (Texture_create_FBO_depth_texture width height)))
(if (<> (glCheckFramebufferStatus GL_FRAMEBUFFER) GL_FRAMEBUFFER_COMPLETE)
(begin
(println "Error creating framebuffer")
(gl_print_error "Error creating FBO & backing textures")
;; return null pointer for fbo
null)
;; fill the FBO tuple with metadata
(begin
(tfill! fbo
(FBO_id fbo)
color_tex
depth_tex
width
height)
;; unbind the frame buffer
(glBindFramebuffer GL_FRAMEBUFFER 0)
fbo)))))