From d6c0426458d72c4627b8721bbc0cf28d01bcd181 Mon Sep 17 00:00:00 2001 From: William Robinson Date: Fri, 19 Oct 2007 23:43:40 +0100 Subject: [PATCH] Added some convenience wrappers and a very simple example using them. --- cl-glfw.asd | 1 + examples/simple.lisp | 15 +++++++++++ lib/opengl-convenience.lisp | 61 +++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 77 insertions(+) create mode 100644 examples/simple.lisp create mode 100644 lib/opengl-convenience.lisp diff --git a/cl-glfw.asd b/cl-glfw.asd index a536d25..3208b7a 100644 --- a/cl-glfw.asd +++ b/cl-glfw.asd @@ -12,5 +12,6 @@ :components ((:module "lib" :components ((:file "opengl") (:file "opengl-version_1_1" :depends-on ("opengl")) + (:file "opengl-convenience" :depends-on ("opengl")) (:file "glu" :depends-on ("opengl-version_1_1")) (:file "glfw" :depends-on ("opengl-version_1_1")))))) \ No newline at end of file diff --git a/examples/simple.lisp b/examples/simple.lisp new file mode 100644 index 0000000..9b7c5a1 --- /dev/null +++ b/examples/simple.lisp @@ -0,0 +1,15 @@ +(require '#:asdf) +(asdf:oos 'asdf:load-op '#:cl-glfw) + +(glfw:do-window ("A Simple Example") + ((gl:with-setup-projection + (glu:perspective 45.0d0 (/ 4.0d0 3.0d0) 0.1d0 50.0d0))) + (gl:clear gl:+color-buffer-bit+) + (gl:load-identity) + (gl:translate-f 0.0 0.0 -5.0) + (gl:rotate-d (* 10.0d0 (glfw:get-time)) 1d0 1d0 0d0) + (gl:rotate-d (* 90.0d0 (glfw:get-time)) 0d0 0d0 1d0) + (gl:with-begin gl:+triangles+ + (gl:color-3f 1.0 0.0 0.0) (gl:vertex-3f 1.0 0.0 0.0) + (gl:color-3f 0.0 1.0 0.0) (gl:vertex-3f -1.0 1.0 0.0) + (gl:color-3f 0.0 0.0 1.0) (gl:vertex-3f -1.0 -1.0 0.0))) \ No newline at end of file diff --git a/lib/opengl-convenience.lisp b/lib/opengl-convenience.lisp new file mode 100644 index 0000000..e6bc1f0 --- /dev/null +++ b/lib/opengl-convenience.lisp @@ -0,0 +1,61 @@ +(in-package #:opengl) + +(defmacro with-new-list (list mode &body forms) + "New/End-List wrapper." + `(progn + (gl:new-list ,list ,mode) + (unwind-protect (progn ,@forms) + (gl:end-list)))) + +(defmacro with-push-name (name &body forms) + "Select name push/pop wrapper" + `(progn + (gl:push-name ,name) + (unwind-protect (progn ,@forms) + (gl:pop-name)))) + +(defmacro with-begin (mode &body forms) + "Immediate mode block wrapper." + `(progn + (gl:begin ,mode) + (unwind-protect (progn ,@forms) + (gl:end)))) + +(defmacro with-push-attrib ((&rest attrib-bits) &body forms) + "Pushes the bitwise or of attrib-bits, executing forms and clean up with pop-attrib." + `(progn + (gl:push-attrib (logior ,@attrib-bits)) + (unwind-protect (progn ,@forms) + (gl:pop-attrib)))) + +(defmacro with-push-matrix (&body forms) + "Pushes the current matrix onto the stack, executes forms and clean up with pop-matrix." + `(progn + (gl:push-matrix) + (unwind-protect (progn ,@forms) + (gl:pop-matrix)))) + +(defmacro with-setup-projection (&body forms) + "Switch to projection mode, load identity, execute forms and return to modelview matrix mode." + `(progn + (gl:matrix-mode gl:+projection+) + (gl:load-identity) + (unwind-protect (progn ,@forms) + (gl:matrix-mode gl:+modelview+)))) + +;; 1.1 Conveniences + +(defmacro with-push-client-attrib ((&rest attrib-bits) &body forms) + "Pushes the bitwise or of the client attrib-bits, executing forms and clean up with pop-client-attrib." + `(progn + (gl:push-client-attrib (logior ,@attrib-bits)) + (unwind-protect (progn ,@forms) + (gl:pop-client-attrib)))) + +;; 1.5 Conveniences +(defmacro with-begin-query ((target id) &body forms) + (gl:begin-query target id) + (unwind-protect (progn ,@forms) + (gl:end-query))) + +(export '(with-new-list with-push-name with-begin with-push-attrib with-push-matrix with-setup-projection with-push-client-attrib)) \ No newline at end of file -- 2.11.4.GIT