When glfw is not compiled as a framework, load the dynlib
[cl-glfw.git] / examples / triangle.lisp
blob23e2efcc6a761dc43102c897bc06f0b7d50fd053
1 (require '#:asdf)
2 (asdf:oos 'asdf:load-op '#:cl-glfw)
3 (asdf:oos 'asdf:load-op '#:cl-glfw-opengl-version_1_0)
4 (asdf:oos 'asdf:load-op '#:cl-glfw-glu)
6 (let ((frames 0)
7 t0 t1)
8 (glfw:do-window (:title "Spinning Triangle")
9 ((glfw:enable glfw:+sticky-keys+)
10 (glfw:swap-interval 0)
11 (setf t0 (glfw:get-time)
12 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)))))