X-Git-Url: https://git.jsancho.org/?a=blobdiff_plain;f=gacela_draw.lisp;h=d992ba5d57cbcca68a40f7d3f1f44e32368e3b74;hb=b63a5e5672e858e7a3689ebc4d66853d5151dfb6;hp=00eb5516208f950a952201b59a9f3a8dc06959a9;hpb=15dc6f156f90086f1f82655b43183f0d8647fa0e;p=gacela.git diff --git a/gacela_draw.lisp b/gacela_draw.lisp index 00eb551..d992ba5 100644 --- a/gacela_draw.lisp +++ b/gacela_draw.lisp @@ -17,10 +17,14 @@ (in-package :gacela) (defmacro with-color (color &body code) - `(let ((original-color (get-current-color))) - (apply #'set-current-color ,color) - ,@code - (apply #'set-current-color original-color))) + (cond (color + `(let ((original-color (get-current-color))) + (apply #'set-current-color ,color) + ,@code + (apply #'set-current-color original-color))) + (t + `(progn + ,@code)))) (defmacro progn-textures (&body code) `(let (values) @@ -105,14 +109,16 @@ (draw-rectangle (* f width) (* f height) :texture texture))))))) (defun draw-quad (v1 v2 v3 v4 &key texture) - (cond (texture (progn-textures - (glBindTexture GL_TEXTURE_2D (getf (get-resource texture) :id-texture)) - (begin-draw 4) - (draw-vertex v1 :texture-coord '(0 0)) - (draw-vertex v2 :texture-coord '(1 0)) - (draw-vertex v3 :texture-coord '(1 1)) - (draw-vertex v4 :texture-coord '(0 1)) - (glEnd))) + (cond ((consp texture) (with-color texture (draw v1 v2 v3 v4))) + (texture + (progn-textures + (glBindTexture GL_TEXTURE_2D (getf (get-resource texture) :id-texture)) + (begin-draw 4) + (draw-vertex v1 :texture-coord '(0 0)) + (draw-vertex v2 :texture-coord '(1 0)) + (draw-vertex v3 :texture-coord '(1 1)) + (draw-vertex v4 :texture-coord '(0 1)) + (glEnd))) (t (draw v1 v2 v3 v4)))) (defun draw-rectangle (width height &key texture) @@ -122,21 +128,21 @@ (defun draw-square (&key (size 1) texture) (draw-rectangle size size :texture texture)) -(defun draw-cube (&key size texture) +(defun draw-cube (&key (size 1) texture texture-1 texture-2 texture-3 texture-4 texture-5 texture-6) (let ((-size (neg size))) (progn-textures (glNormal3f 0 0 1) - (draw-quad (list -size size size) (list size size size) (list size -size size) (list -size -size size) :texture texture) + (draw-quad (list -size size size) (list size size size) (list size -size size) (list -size -size size) :texture (or texture-1 texture)) (glNormal3f 0 0 -1) - (draw-quad (list -size -size -size) (list size -size -size) (list size size -size) (list -size size -size) :texture texture) + (draw-quad (list -size -size -size) (list size -size -size) (list size size -size) (list -size size -size) :texture (or texture-2 texture)) (glNormal3f 0 1 0) - (draw-quad (list size size size) (list -size size size) (list -size size -size) (list size size -size) :texture texture) + (draw-quad (list size size size) (list -size size size) (list -size size -size) (list size size -size) :texture (or texture-3 texture)) (glNormal3f 0 -1 0) - (draw-quad (list -size -size size) (list size -size size) (list size -size -size) (list -size -size -size) :texture texture) + (draw-quad (list -size -size size) (list size -size size) (list size -size -size) (list -size -size -size) :texture (or texture-4 texture)) (glNormal3f 1 0 0) - (draw-quad (list size -size -size) (list size -size size) (list size size size) (list size size -size) :texture texture) + (draw-quad (list size -size -size) (list size -size size) (list size size size) (list size size -size) :texture (or texture-5 texture)) (glNormal3f -1 0 0) - (draw-quad (list -size -size size) (list -size -size -size) (list -size size -size) (list -size size size) :texture texture)))) + (draw-quad (list -size -size size) (list -size -size -size) (list -size size -size) (list -size size size) :texture (or texture-6 texture))))) (defun add-light (&key light position ambient (id GL_LIGHT1) (turn-on t)) (init-lighting)