;; a trivial opengl draw loop
(bind-func gl_render
(let ((size 0.01)
(eye:float* (alloc 4))
(target:float* (alloc 4))
(up:float* (alloc 4))
(model_matrix:float* (alloc 16))
(view_matrix:float* (alloc 16))
(projection_matrix:float* (alloc 16))
(spotpos:float* (alloc 4))
(spottgt:float* (alloc 4))
(d:float* (alloc 4))
(s:float* (alloc 4))
(a:float* (alloc 4)))
(lambda (degree:double)
;; setup stuff for render
(glViewport 0 0 (ftoi32 (* 1.0 width)) (ftoi32 (* 1.0 height)))
(glEnable GL_DEPTH_TEST)
(glUseProgram lightshader) ;; turn shader on
;; light is on a slow dolly back and forth
(pfill! spottgt (+ .5 (dtof (* 3.0 (cos (* degree .05))))) 1.0 0.0 1.0)
(pfill! spotpos (+ .5 (dtof (* 3.0 (cos (* degree .05))))) 1.0 10.0 1.0)
;; setup lights colour
(pfill! a 1.0 1.0 1.0 1.0)
(pfill! s 1.0 1.0 1.0 1.0)
(pfill! d 1.0 1.0 1.0 1.0)
;; camera 'eye' moves all around
;; but always looks to 'target' centre
;; camera 'eye' moves all around
;; but always looks to 'target' centre
(pfill! eye
(dtof (* 10.0 (cos (* .01 degree))))
(dtof (+ 5.0 (* 5.0 (cos (* .005 degree)))))
8.0
1.0) ;; position
(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
;; setup projection view and model matrices
(fill_projection_matrix projection_matrix 35.0 (/ width height) 0.1 10.0)
(fill_view_matrix view_matrix eye target up)
(fill_identity_matrix model_matrix)
(shader_update_light lightshader spotpos spottgt 45.0 30.0 a d s)
(shader_update_camera lightshader eye target)
;; draw scene
(shader_update_matrices lightshader model_matrix view_matrix projection_matrix)
(glClearColor 0.0 0.0 0.0 1.0)
(glClear (+ GL_COLOR_BUFFER_BIT GL_DEPTH_BUFFER_BIT))
(draw_scene degree lightshader model_matrix view_matrix projection_matrix)
(glUseProgram 0) ;; turn shader off
void)))