X-Git-Url: https://git.jsancho.org/?a=blobdiff_plain;f=gacela%2Fimage.scm;h=236ac744fd420e83bf770e606346c46c02cf0d3a;hb=1a2289c59c999b73d932a60137967961c635c90a;hp=40d407560a0b4a06e2aa2f26087569e3dd98a215;hpb=8f33c32a7b23d245493f0879d181ab6661d64a2d;p=gacela.git diff --git a/gacela/image.scm b/gacela/image.scm index 40d4075..236ac74 100644 --- a/gacela/image.scm +++ b/gacela/image.scm @@ -23,23 +23,33 @@ #: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) @@ -49,14 +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" + (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))))))))