]> git.jsancho.org Git - gacela.git/blobdiff - src/gacela_draw.scm
(no commit message)
[gacela.git] / src / gacela_draw.scm
index b9a2c5a06967fb679132b5db4ee362be1a7d5f82..f72c75142ecc314c7cb6adf98dd4e0a93c6c6d28 100644 (file)
@@ -27,7 +27,7 @@
 
 (define-macro (progn-textures . code)
   `(let ((result #f))
-     (init-gacela)
+     (init-video-mode)
      (glEnable GL_TEXTURE_2D)
      (set! result (begin ,@code))
      (glDisable GL_TEXTURE_2D)
@@ -39,7 +39,8 @@
   (glEnd))
 
 (define (begin-draw number-of-points)
-  (cond ((= number-of-points 3) (glBegin GL_TRIANGLES))
+  (cond ((= number-of-points 2) (glBegin GL_LINES))
+       ((= number-of-points 3) (glBegin GL_TRIANGLES))
        ((= number-of-points 4) (glBegin GL_QUADS))))
 
 (define (draw-vertexes vertexes)
   (cond ((3d-mode?) (glVertex3f x y z))
        (else (glVertex2f x y))))
 
-(define (load-image-for-texture filename)
-  (init-gacela)
+(define (load-image filename)
+  (init-sdl)
   (let ((image (IMG_Load filename)))
+    (cond (image
+          (SDL_DisplayFormatAlpha image)))))
+  
+(define (load-image-for-texture filename)
+  (init-sdl)
+  (let ((image (load-image filename)))
     (cond (image
           (let* ((width (surface-w image)) (height (surface-h image))
                  (power-2 (nearest-power-of-two (min width height)))
                 (texture (car (glGenTextures 1))))
 
             (glBindTexture GL_TEXTURE_2D texture)
-            (glTexImage2D GL_TEXTURE_2D 0 3 width height 0 byteorder GL_UNSIGNED_BYTE (surface-pixels image))
+            (glTexImage2D GL_TEXTURE_2D 0 4 width height 0 byteorder GL_UNSIGNED_BYTE (surface-pixels image))
             (glTexParameteri GL_TEXTURE_2D GL_TEXTURE_MIN_FILTER min-filter)
             (glTexParameteri GL_TEXTURE_2D GL_TEXTURE_MAG_FILTER mag-filter)
+            (set-texture-size! texture real-w real-h)
             texture))))))
 
 (define* (draw-image filename #:optional (zoom 1))
               (height (texture-h texture)))
           (draw-rectangle (* zoom width) (* zoom height) #:texture texture)))))
 
+(define* (draw-line length #:optional color)
+  (let ((l (/ length 2)))
+    (cond (color
+          (with-color color (draw (list 0 l) (list 0 (- l)))))
+         (else
+          (draw (list 0 l) (list 0 (- l)))))))
+
 (define* (draw-quad v1 v2 v3 v4 #:key texture color)
   (cond (texture
         (progn-textures
         (draw v1 v2 v3 v4))))
 
 (define* (draw-rectangle width height #:key texture color)
-  (draw-quad (list (- width) height 0)
-            (list width height 0)
-            (list width (- height) 0)
-            (list (- width) (- height) 0)
-            #:texture texture
-            #:color color))
+  (let ((w (/ width 2)) (h (/ height 2)))
+    (draw-quad (list (- w) h 0)
+              (list w h 0)
+              (list w (- h) 0)
+              (list (- w) (- h) 0)
+              #:texture texture
+              #:color color)))
 
 (define* (draw-square #:key (size 1) texture color)
   (draw-rectangle size size #:texture texture #:color color))