Keytest example.
[cl-glfw.git] / examples / mipmaps.lisp
blob1d5f3722a9f35e9f69577292b96638d12b828234
1 (require '#:asdf)
2 (asdf:oos 'asdf:load-op '#:cl-glfw)
5 (defun main ()
6 (unless (eql gl:+true+ (glfw:open-window 640 480 0 0 0 0 0 0 glfw:+window+))
7 (return-from main))
9 (glfw:enable glfw:+sticky-keys+)
10 (glfw:swap-interval 0)
12 (unless (eql gl:+true+
13 (glfw:load-texture-2d (namestring (merge-pathnames "mipmaps.tga" (or *load-pathname* #P"examples/")))
14 glfw:+build-mipmaps-bit+))
15 (return-from main))
17 (gl:tex-parameter-i gl:+texture-2d+ gl:+texture-min-filter+ gl:+linear-mipmap-linear+)
18 (gl:tex-parameter-i gl:+texture-2d+ gl:+texture-mag-filter+ gl:+linear+)
20 (gl:enable gl:+texture-2d+)
22 (do ((running t (and (zerop (glfw:get-key glfw:+key-esc+))
23 (not (zerop (glfw:get-window-param glfw:+opened+)))))
24 (frames 0)
25 (t0 (glfw:get-time))
26 (t1 (glfw:get-time) (glfw:get-time)))
27 ((not running))
29 (when (or (> (- t1 t0) 1.0)
30 (= frames 0))
31 (glfw:set-window-title (format nil "Spinning Triangle (~,1f FPS)" (/ frames (- t1 t0))))
32 (setf frames 0)
33 (setf t0 t1))
35 (incf frames)
37 (gl:clear-color 0.0 0.0 0.0 0.0)
38 (gl:clear gl:+color-buffer-bit+)
40 (destructuring-bind (width height) (glfw:get-window-size)
41 (setf height (max height 1))
42 (gl:viewport 0 0 width height)
44 (gl:matrix-mode gl:+projection+)
45 (gl:load-identity)
46 (glu:perspective 65.0d0 (coerce (/ width height) 'double-float) 1.0d0 50.0d0)
47 (gl:matrix-mode gl:+modelview+)
48 (gl:load-identity)
49 (glu:look-at 0.0d0 3.0d0 -20.0d0
50 0.0d0 -4.0d0 -11.0d0
51 0.0d0 1.0d0 0.0d0))
53 (destructuring-bind (x y) (glfw:get-mouse-pos)
54 (declare (ignore y))
55 (gl:rotate-f (coerce (+ (* x 0.05)
56 (* t1 5.0))
57 'single-float)
58 0.0 1.0 0.0))
60 (gl:begin gl:+quads+)
61 (gl:tex-coord-2f -20.0 20.0) (gl:vertex-3f -50.0 0.0 -50.0)
62 (gl:tex-coord-2f 20.0 20.0) (gl:vertex-3f 50.0 0.0 -50.0)
63 (gl:tex-coord-2f 20.0 -20.0) (gl:vertex-3f 50.0 0.0 50.0)
64 (gl:tex-coord-2f -20.0 -20.0) (gl:vertex-3f -50.0 0.0 50.0)
65 (gl:end)
66 (glfw:swap-buffers)))
68 (glfw:init)
69 (main)
70 (glfw:terminate)