X-Git-Url: https://git.jsancho.org/?a=blobdiff_plain;f=gacela%2Fimage.scm;h=236ac744fd420e83bf770e606346c46c02cf0d3a;hb=1a2289c59c999b73d932a60137967961c635c90a;hp=278a7d767846db11e4a92af2d6fe3f7769593cfb;hpb=e1e0e1c4a98a9b27391eeef40dea40a59d983710;p=gacela.git diff --git a/gacela/image.scm b/gacela/image.scm index 278a7d7..236ac74 100644 --- a/gacela/image.scm +++ b/gacela/image.scm @@ -24,8 +24,14 @@ #:use-module ((sdl2 surface) #:prefix sdl2:) #:use-module (gl) #:export (image - move-xy - scale)) + move + scale + over)) + +(define (calculate proc-or-value) + (if (procedure? proc-or-value) + (proc-or-value) + proc-or-value)) (define (image filename) (make-scene @@ -41,6 +47,9 @@ (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) @@ -50,21 +59,33 @@ (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-xy" + "move" (lambda () - (let ((xy (list (to-integer (if (procedure? x) (x) x)) - (to-integer (if (procedure? y) (y) y))))) - (display-scene scene #:xy xy))))) + (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 x y z) + (gl-scale (calculate x) + (calculate y) + (calculate z)) (display-scene scene)))) + +(define (over . scenes) + (make-scene + "over" + (lambda () + (let display ((sc scenes)) + (cond ((not (null? sc)) + (with-gl-push-matrix + (display-scene (car sc))) + (display (cdr sc))))))))