3 (defmacro def-vec-funcs
(&rest names
)
5 ,@(loop for name in names collect
6 (let ((name-v (alexandria:format-symbol
:gui
"~a-V" name
)))
9 (values null
&optional
))
10 (,name
(vec-x vec
) (vec-y vec
) (vec-z vec
))
13 (def-vec-funcs vertex tex-coord translate normal scale
)
17 (ps (make-array (+ n
2) :element-type
'vec
18 :initial-element
(v))))
20 ((simple-array vec
1) ps
))
21 (setf (aref ps
0) (v))
23 (let ((arg (* 2d0 pi i
(/ 1d0 n
))))
24 (declare ((double-float 0d0
6.3d0
) arg
))
25 (setf (aref ps
(1+ i
)) (make-vec (cos arg
) (sin arg
)))))
26 (setf (aref ps
(1+ n
)) (aref ps
1))
29 (declaim (type (simple-array vec
1) circle-points
))
32 "Draw circle with radius 1."
33 (dotimes (i (length circle-points
))
34 (vertex-v (aref circle-points i
)))
37 (defmethod draw ((disk lens
:disk
))
38 (declare (values null
&optional
))
39 (with-slots ((c lens
::center
) (r lens
::radius
)) disk
43 (with-primitive :triangle-fan
46 (defclass texture-luminance-ub8
()
47 ((dimensions :accessor dimensions
:initarg
:dimensions
:initform
'(0 0 0)
49 (object :accessor object
:initarg
:object
:initform
0 :type fixnum
)
50 (target :accessor target
:initarg
:target
51 :initform
:texture-3d
:type fixnum
)))
53 (defmethod initialize-instance :after
((tex texture-luminance-ub8
) &key data
)
54 (let ((rank (etypecase data
55 ((simple-array (unsigned-byte 8) 2) 2)
56 ((simple-array (unsigned-byte 8) 3) 3))))
57 (with-slots (dimensions object target
) tex
58 (setf object
(first (gen-textures 1))
59 dimensions
(array-dimensions data
)
61 (2 :texture-rectangle-nv
)
63 (bind-texture target object
)
64 (tex-parameter target
:texture-min-filter
:linear
)
65 (tex-parameter target
:texture-mag-filter
:linear
)
66 (sb-sys:with-pinned-objects
(data)
67 (let* ((data1 (sb-ext:array-storage-vector data
))
68 (data-sap (sb-sys:vector-sap data1
)))
70 (2 (tex-image-2d target
0 :luminance
71 (array-dimension data
1) ;; x
72 (array-dimension data
0) 0 :luminance
73 :unsigned-byte data-sap
))
74 (3 (tex-image-3d target
0 :luminance
75 (array-dimension data
2) ;; x
76 (array-dimension data
1) ;; y
77 (array-dimension data
0) 0 :luminance
78 :unsigned-byte data-sap
))))))))
80 (defmethod destroy ((tex texture-luminance-ub8
))
81 (delete-textures (list (object tex
))))
83 (defmethod bind-tex ((tex texture-luminance-ub8
))
84 (bind-texture (target tex
) (object tex
)))
86 (defmethod draw-xz ((tex texture-luminance-ub8
) x
+ x- z
+ z-
87 &key
(y 0d0
) (ty 0d0
))
88 "Draw a quad with a texture. If the texture is 3d, an xz-plane at y
89 is selected. The parameter x+, x-, z+, z- and y define vertex
90 positions of the quad. In case of a 3d texture ty choses the y
91 texture coordinate with value from 0 .. 1."
92 (with-slots (target dimensions
) tex
97 (:texture-rectangle-nv
98 (destructuring-bind (yy xx
) dimensions
101 (list (make-vec x y
) (make-vec 0d0 y
)
102 (make-vec 0d0
0d0
) (make-vec x
0d0
)))))
103 (:texture-3d
(list (make-vec 1d0 ty
1d0
) (make-vec 0d0 ty
1d0
)
104 (make-vec 0d0 ty
0d0
) (make-vec 1d0 ty
0d0
)))))
105 (vertexs (list (make-vec x
+ y z-
)
108 (make-vec x
+ y z
+))))
109 (gl:with-primitive
:quads
110 (loop for v in vertexs and c in texcoords do
111 (tex-coord-v c
) (vertex-v v
))))
112 (gl:disable target
)))
118 (gl:with-primitive
:lines
119 (gl:color
1 0 0 1) (gl:vertex
0 0 0) (gl:vertex
1 0 0)
120 (gl:color
0 1 0 1) (gl:vertex
0 0 0) (gl:vertex
0 1 0)
121 (gl:color
0 0 1 1) (gl:vertex
0 0 0) (gl:vertex
0 0 1)))
124 (defun draw-wire-box (start end
)
125 (gl:with-pushed-matrix
127 (scale-v (v- end start
))
128 (gl:translate
.5 .5 .5)