;;
;; near = 0.1
;; far = 100.0
;; angle = 35.0
;;
(bind-func xtm_render
(let ((i:i32 0)
(frame:i64 0)
(lights:xtm_lights* (xtm_get_lights))
(camera:xtm_camera* (xtm_get_camera))
(activelights:i32 0)
(framebufsize:float* (alloc 2))
(sh1:ShaderProgram* null)
(sh2:ShaderProgram* null)
(model:float* (alloc 16))
(view:float* (alloc 16))
(projection:float* (alloc 16))
(shadow_fbo:FBO* null)
(render_fbo:FBO* null))
(lambda (pre:XTMRENDERCB opaque:XTMRENDERCB transparent:XTMRENDERCB post:XTMRENDERCB data:i8*)
(set! shadow_fbo (xtm_shadow_fbo))
(set! render_fbo (xtm_render_fbo))
;; (glShadeModel GL_SMOOTH)
(glEnable GL_DEPTH_TEST)
;; (glEnable GL_TEXTURE_2D)
;; seutp projection matrix
(fill_projection_matrix projection xtm_render_angle
(/ (i32tof xtm_render_w) (i32tof xtm_render_h))
xtm_render_near xtm_render_far)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; pre - move lights cameras etc..
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(if (not (null? pre))
(begin
;; each cycle set lights back to 0
(tset! (xtm_get_lights) 9 0)
(xtm_camera_view view) ;; set view
(fill_identity_matrix model) ;; set model
(pre frame null model view projection data)))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; calc shadow for each light into shadow_fbo
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(gl_print_error "prerender gl error")
;; (set! sh1 xtm_render_simple_bone_shader)
(set! sh1 xtm_render_simple_shader)
(start sh1) ;; start program
(bind shadow_fbo) ;; bind fbo
;; clear shadow fbo
(glClearColor 0.0 0.25 0.25 1.0)
(glClear (+ GL_COLOR_BUFFER_BIT GL_DEPTH_BUFFER_BIT))
;; this all for shadows?
(if (not (null? opaque))
(dotimes (i (tref lights 9))
;; 4 x 4 shadow texture texture
(glViewport (* (% i 4) 1024) (* (ftoi32 (/ (i32tof i) 4.0)) 1024) 1024 1024)
(glEnable GL_CULL_FACE) ;; face culling ON for shadowmapping
(glCullFace GL_FRONT)
(fill_identity_matrix model) ;; set model matrix
(xtm_light_view (+ i 1) view) ;; set view matrix
(xtm_update_matrices sh1 model view projection)
(opaque frame sh1 model view projection data)
(gl_print_error)
void))
;; turn off shadow FBO
(unbind shadow_fbo)
(stop sh1)