When glfw is not compiled as a framework, load the dynlib
[cl-glfw.git] / examples / mipmaps.lisp
blobd4637337925598dbdbf8c1f4211c69b9ac551f01
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
8 t1)
9 (glfw:do-window (:title "Mipmap Demo" :width 640 :height 480)
10 ((glfw:enable glfw:+sticky-keys+)
11 (glfw:swap-interval 0)
13 (unless (glfw:load-texture-2d (namestring (merge-pathnames "mipmaps.tga" (or *load-pathname* #P"examples/")))
14 glfw:+build-mipmaps-bit+)
15 (error "Unable to load texture!"))
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+)
21 (setf t1 (glfw:get-time)
22 t0 t1))
24 (unless (zerop (glfw:get-key glfw:+key-esc+))
25 (return-from glfw:do-window))
27 (setf t1 (glfw:get-time))
29 (when (or (> (- t1 t0) 1.0)
30 (zerop frames))
31 (glfw:set-window-title (format nil "Mipmap Demo (~,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:with-setup-projection
45 (glu:perspective 65.0d0 (coerce (/ width height) 'double-float) 1.0d0 50.0d0))
46 (gl:load-identity)
47 (glu:look-at 0.0d0 3.0d0 -20.0d0
48 0.0d0 -4.0d0 -11.0d0
49 0.0d0 1.0d0 0.0d0))
52 (destructuring-bind (x y) (glfw:get-mouse-pos)
53 (declare (ignore y))
54 (gl:rotate-f (+ (* x 0.05)
55 (* t1 5.0))
56 0 1 0))
58 (gl:with-begin gl:+quads+
59 (gl:tex-coord-2f -20.0 20.0) (gl:vertex-3f -50.0 0.0 -50.0)
60 (gl:tex-coord-2f 20.0 20.0) (gl:vertex-3f 50.0 0.0 -50.0)
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))))