]> git.jsancho.org Git - gacela.git/blobdiff - gacela_draw.lisp
(no commit message)
[gacela.git] / gacela_draw.lisp
index feaf0c39d75b063c6275e3396cf9637e8537a39e..40a6c4ccf0a5e7bbab41da7f4a01f587f000b267 100644 (file)
 ;;; You should have received a copy of the GNU General Public License
 ;;; along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
-
 (in-package :gacela)
 
+(let ((mode '2d))
+  (defun 2d-mode ()
+    (glDisable GL_DEPTH_TEST)
+    (setq mode '2d))
+
+  (defun 3d-mode ()
+    (glEnable GL_DEPTH_TEST)
+    (setq mode '3d))
+
+  (defun 3d-mode? ()
+    (eq mode '3d)))
+
 (defun draw (&rest vertexes)
   (begin-draw (length vertexes))
   (draw-vertexes vertexes)
           (draw-vertexes (cdr vertexes)))))
 
 (defun draw-vertex (vertex &key texture-coord)
-  (cond ((consp (car vertex)) (apply #'glColor3f (car vertex)) (apply #'glVertex3f (cadr vertex)))
+  (cond ((consp (car vertex)) (draw-color (car vertex)) (apply #'simple-draw-vertex (cadr vertex)))
        (t (cond (texture-coord (apply #'glTexCoord2f texture-coord)))
-          (apply #'glVertex3f vertex))))
+          (apply #'simple-draw-vertex vertex))))
+
+(defun simple-draw-vertex (x y &optional (z 0))
+  (cond ((3d-mode?) (glVertex3f x y z))
+       (t (glVertex2f x y))))
 
 (defun draw-color (color)
   (apply #'glColor3f color))
@@ -56,7 +71,9 @@
 (defun draw-image-function (filename)
   (multiple-value-bind
    (texture width height) (load-texture filename)
-        (cond (texture))))
+        (cond (texture
+              (lambda (&optional (f 1))
+                (draw-rectangle (* f width) (* f height) :texture texture))))))
 
 (defun draw-quad (v1 v2 v3 v4 &key texture color)
   (cond (texture (glBindTexture GL_TEXTURE_2D texture)
        (t (cond (color (draw-color color)))
           (draw v1 v2 v3 v4))))
 
-(defun draw-square (&key size texture color)
-  (let ((-size (neg size)))
-    (draw-quad (list -size size 0) (list size size 0) (list size -size 0) (list -size -size 0) :texture texture :color color)))
+(defun draw-rectangle (width height &key texture color)
+  (let* ((w (/ width 2)) (-w (neg w)) (h (/ height 2)) (-h (neg h)))
+    (draw-quad (list -w h 0) (list w h 0) (list w -h 0) (list -w -h 0) :texture texture :color color)))
+
+(defun draw-square (&key (size 1) texture color)
+  (draw-rectangle size size :texture texture :color color))
 
 (defun draw-cube (&key size texture color)
   (let ((-size (neg size)))