;; a trivial opengl draw loop
(bind-func gl_render
(let ((fbo:E_fbo* null)
(size 0.01)
(eye:float* (alloc 4))
(target:float* (alloc 4))
(up:float* (alloc 4))
(tmp_matrix:float* (alloc 16))
(model_matrix:float* (alloc 16))
(view_matrix:float* (alloc 16))
(projection_matrix:float* (alloc 16))
(mata:float* (alloc 4))
(matd:float* (alloc 4))
(mats:float* (alloc 4))
(spotpos:float* (alloc 4))
(spottgt:float* (alloc 4))
(spotdir:float* (alloc 4))
(light_view_matrix:float* (alloc 16))
(d1:float* (alloc 4))
(s1:float* (alloc 4))
(a1:float* (alloc 4)))
;; white light!
(pfill! a1 1.0 1.0 1.0 1.0)
(pfill! s1 1.0 1.0 1.0 1.0)
(pfill! d1 1.0 1.0 1.0 1.0)
;; camera always up and pointing to centre
(pfill! target 0.0 0.0 0.0 1.0) ;; position vector gets w==1.0
(pfill! up 0.0 1.0 0.0 0.0) ;; direction vector gets w==0.0
(lambda (model1:xtm_node* model2:xtm_node* model3:xtm_node* degree:double)
;; first grab the fbo
(set! fbo (get-fbo))
;; setup light on a slow dolly back and forth
(pfill! spottgt (+ .5 (dtof (* 5.0 (cos (* degree .05))))) 0.0 -1.0 1.0)
(pfill! spotpos (+ .5 (dtof (* 5.0 (cos (* degree .05))))) 2.0 20.0 1.0)
;; set eye position (looking at target)
(pfill! eye
(dtof (* 5.0 (cos (* .01 degree))))
(dtof (+ 5.0 (* 5.0 (cos (* .005 degree)))))
(dtof (+ 15.0 (* 10.0 (cos (* .025 degree)))))
1.0) ;; position
;; setup projection matrix
(fill_projection_matrix projection_matrix 35.0 (/ width height) 0.1 100.0)