;; a trivial opengl draw loop
(bind-func gl_render
(let ((fbo:E_fbo* null)
(size 0.01)
(lights:i32 3)
(i:i32 0)
(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))
(_angle:float* (alloc 10))
(_power:float* (alloc 10))
(_spotpos:float* (alloc (* lights 4)))
(spotpos:float* null)
(_spottgt:float* (alloc (* lights 4)))
(spottgt:float* null)
(_light_view_matrix:float* (alloc (* lights 16)))
(light_view_matrix:float* null)
(_diffuse_light:float* (alloc (* lights 4)))
(_specular_light:float* (alloc (* lights 4)))
(_ambient_light:float* (alloc (* lights 4))))
;; warm for light 1!
(pfill! (pref-ptr _ambient_light 0) 1.0 0.8 0.5 1.0)
(pfill! (pref-ptr _specular_light 0) 1.0 1.0 1.0 1.0)
(pfill! (pref-ptr _diffuse_light 0) 1.0 0.8 0.5 1.0)
;; red for light 2!
(pfill! (pref-ptr _ambient_light 4) 0.0 0.0 0.0 1.0)
(pfill! (pref-ptr _specular_light 4) 1.0 0.0 0.0 1.0)
(pfill! (pref-ptr _diffuse_light 4) 1.0 0.1 0.0 1.0)
;; green for light 3!
(pfill! (pref-ptr _ambient_light 8) 0.0 0.0 0.0 1.0)
(pfill! (pref-ptr _specular_light 8) 0.0 1.0 0.0 1.0)
(pfill! (pref-ptr _diffuse_light 8) 0.1 1.0 0.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)
;; setup rotating spot light
(pfill! (pref-ptr _spottgt 0)
(dtof (* 5.0 (cos (* degree .05))))
-1.7
(+ 11.0 (dtof (* 5.0 (sin (* degree .05)))))
1.0)
(pfill! (pref-ptr _spotpos 0) 0.0 -2.8 11.0 1.0)
;; (pfill! (pref-ptr _spotpos 0) (+ .5 (dtof (* 8.0 (cos (* degree 0.05))))) 1.0 20.0 1.0)
;; setup second light as fixed
;; (pfill! (pref-ptr _spottgt 4) (+ .5 (dtof (* 10.0 (cos (* degree 0.05))))) 0.0 -1.0 1.0)
;; (pfill! (pref-ptr _spotpos 4) (+ .5 (dtof (* 10.0 (cos (* degree 0.05))))) 2.0 20.0 1.0)
(pfill! (pref-ptr _spottgt 4) -3.0 0.0 0.0 1.0)
(pfill! (pref-ptr _spotpos 4) 8.0 4.0 -2.0 1.0)
(pfill! (pref-ptr _spottgt 8) -1.0 0.0 -1.0 1.0)
(pfill! (pref-ptr _spotpos 8) -15.0 4.0 7.0 1.0)
;; (pfill! (pref-ptr _spottgt 8) 2.0 0.0 -5.0 1.0)
;; (pfill! (pref-ptr _spotpos 8) -3.0 1.0 10.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)
(set! lights (i64toi32 3))
;; make sure a few opengl settings are enabled
(glShadeModel GL_SMOOTH)
(glEnable GL_DEPTH_TEST)
(glEnable GL_TEXTURE_2D)
;;
;; Now we render the Scene into An FBO
;; this first pass is from the lights
;; perspective (i.e. Light provides ViewMatrix)
;; We really only care about the depth buffer here
;;
(set! fbo (get-fbo))
;; bind framebuffer to write depth info into
(glBindFramebuffer GL_FRAMEBUFFER (tref fbo 0))
(glUseProgram simpleshader)
;; clear fbo
(glClearColor 0.0 0.0 0.0 1.0)
(glClear (+ GL_COLOR_BUFFER_BIT GL_DEPTH_BUFFER_BIT))