1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
|
(in-package #:l-system-examples)
(deflsys f (n)
(let* ((r0 0.5235988)
(n0 (* 1.01 n)))
`((f ,(* 1.11 n0))
([)
(+ ,r0)
(f ,(* 0.89 n0))
(])
([)
(- ,r0)
(f ,(* 0.89 n0))
(])
([)
(/ ,r0)
(f ,(* 0.89 n0))
(])
([)
(q ,r0)
(f ,(* 0.89 n0))
(])
(f ,(* 1.11 n0))
([)
(+ ,r0)
(f ,(* 0.89 n0))
(])
([)
(- ,r0)
(f ,(* 0.89 n0))
(])
([)
(/ ,r0)
(f ,(* 0.89 n0))
(])
([)
(q ,r0)
(f ,(* 0.89 n0))
(])
(f ,(* 1.11 n0)))))
(deflsys + (n)
`((+ ,(+ 0.1 n))))
(deflsys - (n)
`((- ,(+ 0.1 n))))
;; Rest
(defclass test-window (gl-window)
((start-time :initform (get-internal-real-time))
(frames :initform 0)
(dt :initform 0)
(rotate :initform 0.0)
(view-matrix :initform (kit.glm:perspective-matrix 50.0 1.1 1.0 800.0))
(vao :initform nil)
(programs :initform nil)))
(defmethod initialize-instance :after ((w test-window)
&key shaders &allow-other-keys)
(setf (idle-render w) t)
(gl:viewport 0 0 800 600)
(with-slots (vao programs) w
(let* ((data
;;convert list of vecs to array
(list-of-vectors->list
;;make list of vecs
(turtle-system
;;Specific geometry for symbol f
#'(lambda (o n list)
(cube o n))
;;make structure of turtle commands
(l-system '((f 1.0)) 3))))
(length (length data))
(array (make-array length
:element-type 'single-float
:initial-contents data)))
(setf programs (compile-shader-dictionary shaders))
(setf vao
(make-instance 'vao
:type 'vertex-3d
:primitive :triangles
:vertex-count (/ length 3)))
(vao-buffer-vector vao 0 (* 4 length) array)
(vao-buffer-vector vao 1 (* 4 length) array))))
;;; Rest
(defmethod render ((window test-window))
(with-slots (view-matrix vao programs rotate) window
(gl:clear-color 0.0 0.0 1.0 1.0)
(gl:clear :color-buffer)
(use-program programs :vertex-color)
(uniform-matrix programs :view-m 4 (vector
(sb-cga:matrix*
view-matrix
(kit.glm:look-at
(sb-cga:vec 0.0 0.0 200.0)
(sb-cga:vec 0.0 10.0 0.0)
(sb-cga:vec 0.0 -1.0 0.0))
(sb-cga:rotate* 0.0
(incf rotate 0.00625)
0.0))))
(vao-draw vao)))
(defmethod render :after ((window test-window))
(with-slots (start-time frames rotate) window
(incf frames)
(let* ((current-time (get-internal-real-time))
(seconds (/ (- current-time start-time) internal-time-units-per-second)))
(when (> seconds 5)
(format t "FPS: ~A~%" (float (/ frames seconds)))
(setf frames 0)
(setf start-time (get-internal-real-time))))))
(defun start-example ()
(kit.sdl2:start)
(sdl2:in-main-thread ()
(sdl2:gl-set-attr :context-major-version 3)
(sdl2:gl-set-attr :context-minor-version 3))
(make-instance 'test-window :shaders 'vao-color.programs.330))
(defvao vertex-3d ()
(:separate ()
(vertex :float 3)
(color :float 3)))
(defdict vao-color.programs.330 ()
(program :vertex-color (:view-m)
(:vertex-shader "
#version 330
uniform mat4 view_m;
layout (location = 0) in vec3 vertex;
layout (location = 1) in vec3 color;
smooth out vec3 f_color;
void main() {
gl_Position = view_m * vec4(vertex, 1.0);
f_color = color;
}
")
(:fragment-shader "
#version 330
smooth in vec3 f_color;
out vec4 f_out;
void main() {
f_out = vec4(f_color,
1.0);
}
")))
|