;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;
;; OpenGL Light Test
;;
;; Circle three light sources around the GL teapot
;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(define *gl* (gl:make-opengl))
(gl:open-opengl *gl* '(200 200 640 480))
(define init
(lambda ()
(gl:clear-color *gl* 0.0 0.0 0.0 0.0)
(gl:shade-model *gl* *gl:smooth*)
(gl:enable *gl* *gl:depth-test*)))
(define init-lights
(lambda ()
(gl:enable *gl* *gl:lighting*)
(gl:enable *gl* *gl:light0*)
(gl:enable *gl* *gl:light1*)
(gl:enable *gl* *gl:light2*)
(gl:light *gl* *gl:light0* *gl:diffuse* (vector 0 0 1 1.0))
(gl:light *gl* *gl:light0* *gl:specular* (vector 0 0 1 1.0))
(gl:light *gl* *gl:light1* *gl:diffuse* (vector 1 0 0 1.0))
(gl:light *gl* *gl:light1* *gl:specular* (vector 1 0 0 1.0))
(gl:light *gl* *gl:light2* *gl:diffuse* (vector 0 1 0 1.0))
(gl:light *gl* *gl:light2* *gl:specular* (vector 0 1 0 1.0))))
(define view
(lambda ()
(gl:viewport *gl* 0 0 640 480)
(gl:matrix-mode *gl* *gl:projection*)
(gl:load-identity *gl*)
(glu:perspective *gl* 40.0 (/ 640 480) 1.0 20.0)
(gl:matrix-mode *gl* *gl:modelview*)
(gl:load-identity *gl*)))
(define draw-light
(lambda (light angle x y z r g b)
(gl:push-matrix *gl*)
(gl:rotate *gl* angle x y z)
(gl:light *gl* light *gl:position* (vector 0.0 0.0 1.5 1.0))
(gl:translate *gl* 0.0 0.0 1.5)
(gl:disable *gl* *gl:lighting*)
(gl:color *gl* r g b)
(glut:wire-cube *gl* 0.1)
(gl:enable *gl* *gl:lighting*)
(gl:pop-matrix *gl*)))
(define draw-scene
(lambda (angle)
(gl:clear *gl* (io:binary-or *gl:depth-buffer-bit* *gl:color-buffer-bit*))
(gl:push-matrix *gl*)
(glu:look-at *gl* 3.0 3.0 3.0 0.0 0.0 0.0 0.0 1.0 0.0)
(draw-light *gl:light0* (+ 45 angle) 1 1 0 0 0 1)
(draw-light *gl:light1* (+ 90 angle) 0 1 1 1 0 0)
(draw-light *gl:light2* angle 1 0 1 0 1 0)
(glut:solid-teapot *gl* 1.0)
;(glut:solid-sphere *gl* 1.0 20 20)
(gl:pop-matrix *gl*)
(gl:flush *gl*)
(callback (+ (now) 2000) 'draw-scene (fmod (+ angle 10) 360))))
(init)
(init-lights)
(view)
(draw-scene 0)