1 (in-package :lambdamundo
)
6 (gl:enable gl
:+depth-test
+)
7 (gl:depth-func gl
:+less
+)
8 (gl:disable gl
:+cull-face
+)
9 (gl:disable gl
:+lighting
+))
13 ;; drawing --------------------
16 (defparameter *draw-fns
* (make-hash-table :test
'equalp
)
17 "An table of functions called in order to render the scene")
19 (defparameter *draw-array
* (make-array 0 :adjustable t
:fill-pointer
0)
20 "An array that indexes *draw-fns* to establish draw order" )
22 (defun reset-draw-fns ()
23 "Reset all drawing functions."
24 (setf *draw-fns
* (make-hash-table :test
'equalp
))
25 (setf *draw-array
* (make-array 0 :adjustable t
:fill-pointer
0)))
27 (defun extend-draw-array (name priority
)
28 "If the name is in the array, adjust priority, else add it to the array"
29 (assert (not (null (gethash name
*draw-fns
*))) (name) "~S is not a drawable")
32 (position-if #'(lambda (x) (equal (car x
) name
)) *draw-array
*)))
34 (setf (aref *draw-array
* draw-priority-pos
) (cons name priority
))
35 (vector-push-extend (cons name priority
) *draw-array
*))))
37 (defmacro make-draw-function
(name priority
&body forms
)
38 "Macro to wrap a draw function body and add it to the arrays"
40 (setf (gethash ,name
*draw-fns
*)
41 (compile nil
'(lambda () ,@forms
)))
42 (extend-draw-array ,name
,priority
)
43 (sort *draw-array
* #'(lambda (a b
)
44 (< (cdr a
) (cdr b
))))))
46 (defun remove-draw-function (name)
47 (remhash name
*draw-fns
*))
50 (gl:clear
(logior gl
:+color-buffer-bit
+ gl
:+depth-buffer-bit
+))
52 (for entry in-vector
*draw-array
*)
54 (gethash (car entry
) *draw-fns
*)))
55 (when draw-fn
(funcall draw-fn
)))))
79 (gl:with-begin gl
:+quads
+
80 (gl:color-3f
0.0 1.0 0.0)
85 (apply #'gl
:vertex-3f
(nth (1- vertex
) vertices
))))))))
87 ;; (make-draw-function
89 ;; (gl:with-begin gl:+triangles+
90 ;; (gl:color-3f 1.0 0.0 0.0) (gl:vertex-3f 1.0 0.0 -5.0)
91 ;; (gl:color-3f 0.0 1.0 0.0) (gl:vertex-3f -1.0 1.0 -5.0)
92 ;; (gl:color-3f 0.0 0.0 0.0) (gl:vertex-3f -1.0 -1.0 -5.0)))
94 ;; there will be a draw function per class of object