Revisited all examples and updated.
[cl-glfw.git] / examples / triangle.lisp
blob18b09cc902a6c48daf0f9606b939e8aeed8446b5
1 (require '#:asdf)
2 (asdf:oos 'asdf:load-op '#:cl-glfw)
5 (let ((frames 0)
6 t0 t1)
7 (glfw:do-window ("Spinning Triangle" 640 480)
8 ((glfw:enable glfw:+sticky-keys+)
9 (glfw:swap-interval 0)
10 (setf t0 (glfw:get-time)
11 t1 (glfw:get-time)))
13 (when (eql (glfw:get-key glfw:+key-esc+) glfw:+press+)
14 (return-from glfw:do-window))
16 (setf t1 (glfw:get-time))
18 (when (or (> (- t1 t0) 1)
19 (= frames 0))
20 (glfw:set-window-title (format nil "Spinning Triangle (~,1f FPS)" (/ frames (- t1 t0))))
21 (setf frames 0
22 t0 t1))
24 (incf frames)
26 (destructuring-bind (width height) (glfw:get-window-size)
27 (setf height (max height 1))
28 (gl:viewport 0 0 width height)
30 (gl:clear-color 0 0 0 0)
31 (gl:clear gl:+color-buffer-bit+)
33 (gl:matrix-mode gl:+projection+)
34 (gl:load-identity)
35 (glu:perspective 65 (/ width height) 1 100)
36 (gl:matrix-mode gl:+modelview+)
37 (gl:load-identity)
38 (glu:look-at 0 1 0
39 0 20 0
40 0 0 1)
42 (gl:translate-f 0 14 0)
45 (destructuring-bind (x y) (glfw:get-mouse-pos)
46 (declare (ignore y))
47 (gl:rotate-f (+ (* x 0.3)
48 (* t1 100))
49 0 0 1))
51 (gl:with-begin gl:+triangles+
52 (gl:color-3f 1 0 0) (gl:vertex-3f -5 0 -4)
53 (gl:color-3f 0 1 0) (gl:vertex-3f 5 0 -4)
54 (gl:color-3f 0 0 1) (gl:vertex-3f 0 0 6)))))