]> git.jsancho.org Git - gacela.git/blobdiff - gacela/image.scm
Scale support variations over time
[gacela.git] / gacela / image.scm
index 40d407560a0b4a06e2aa2f26087569e3dd98a215..236ac744fd420e83bf770e606346c46c02cf0d3a 100644 (file)
   #:use-module ((sdl2 render) #:prefix sdl2:)
   #:use-module ((sdl2 surface) #:prefix sdl2:)
   #:use-module (gl)
-  #:export (bitmap
-            move-xy))
+  #:export (image
+            move
+            scale
+            over))
 
-(define (bitmap filename)
+(define (calculate proc-or-value)
+  (if (procedure? proc-or-value)
+      (proc-or-value)
+      proc-or-value))
+
+(define (image filename)
   (make-scene
-   "bitmap"
+   "image"
    (let ((image (sdl2:load-image filename))
          (texture #f)
          (w/2 0)
          (h/2 0))
-     (lambda* ()
+     (lambda ()
        (when (not texture)
          (set! texture (sdl2:surface->texture %sdl-renderer image))
          (set! w/2 (/ (sdl2:surface-width image) 2))
          (set! h/2 (/ (sdl2:surface-height image) 2)))
        (gl-enable (oes-framebuffer-object texture-2d))
        (sdl2:bind-texture texture)
+       (gl-enable (oes-framebuffer-object blend))
+       (set-gl-blend-function (blending-factor-src src-alpha)
+                              (blending-factor-dest one-minus-src-alpha))
        (gl-begin (begin-mode quads)
          (gl-texture-coordinates 0 0)
          (gl-vertex (- w/2) h/2 0)
          (gl-vertex w/2 (- h/2) 0)
          (gl-texture-coordinates 0 1)
          (gl-vertex (- w/2) (- h/2) 0))
+       (gl-disable (oes-framebuffer-object blend))
        (gl-disable (oes-framebuffer-object texture-2d))))))
 
-(define (move-xy x y scene)
-  (define (to-integer n)
-    (inexact->exact (round n)))
+(define* (move scene x y #:optional (z 0))
+  (make-scene
+   "move"
+   (lambda ()
+     (gl-translate (calculate x)
+                   (calculate y)
+                   (calculate z))
+     (display-scene scene))))
+
+(define* (scale scene x #:optional (y x) (z y))
+  (make-scene
+   "scale"
+   (lambda ()
+     (gl-scale (calculate x)
+               (calculate y)
+               (calculate z))
+     (display-scene scene))))
+
+(define (over . scenes)
   (make-scene
-   "move-xy"
+   "over"
    (lambda ()
-     (let ((xy (list (to-integer (if (procedure? x) (x) x))
-                     (to-integer (if (procedure? y) (y) y)))))
-       (display-scene scene #:xy xy)))))
+     (let display ((sc scenes))
+       (cond ((not (null? sc))
+              (with-gl-push-matrix
+               (display-scene (car sc)))
+              (display (cdr sc))))))))