Cut-out empty enum groups earlier (results in reordering of exports) and...
[cl-glfw/jecs.git] / examples / triangle.lisp
blob490d52abf455f5345ec78178ed4d5d0ab3817943
1 (require '#:asdf)
2 (asdf:oos 'asdf:load-op '#:cl-glfw)
3 (asdf:oos 'asdf:load-op '#:cl-glfw-opengl)
4 (asdf:oos 'asdf:load-op '#:cl-glfw-glu)
6 (let ((frames 0)
7 t0 t1)
8 (glfw:do-window ("Spinning Triangle" 640 480)
9 ((glfw:enable glfw:+sticky-keys+)
10 (glfw:swap-interval 0)
11 (setf t0 (glfw:get-time)
12 t1 (glfw:get-time)))
14 (when (eql (glfw:get-key glfw:+key-esc+) glfw:+press+)
15 (return-from glfw:do-window))
17 (setf t1 (glfw:get-time))
19 (when (or (> (- t1 t0) 1)
20 (= frames 0))
21 (glfw:set-window-title (format nil "Spinning Triangle (~,1f FPS)" (/ frames (- t1 t0))))
22 (setf frames 0
23 t0 t1))
25 (incf frames)
27 (destructuring-bind (width height) (glfw:get-window-size)
28 (setf height (max height 1))
29 (gl:viewport 0 0 width height)
31 (gl:clear-color 0 0 0 0)
32 (gl:clear gl:+color-buffer-bit+)
34 (gl:matrix-mode gl:+projection+)
35 (gl:load-identity)
36 (glu:perspective 65 (/ width height) 1 100)
37 (gl:matrix-mode gl:+modelview+)
38 (gl:load-identity)
39 (glu:look-at 0 1 0
40 0 20 0
41 0 0 1)
43 (gl:translate-f 0 14 0)
46 (destructuring-bind (x y) (glfw:get-mouse-pos)
47 (declare (ignore y))
48 (gl:rotate-f (+ (* x 0.3)
49 (* t1 100))
50 0 0 1))
52 (gl:with-begin gl:+triangles+
53 (gl:color-3f 1 0 0) (gl:vertex-3f -5 0 -4)
54 (gl:color-3f 0 1 0) (gl:vertex-3f 5 0 -4)
55 (gl:color-3f 0 0 1) (gl:vertex-3f 0 0 6)))))