X-Git-Url: https://git.jsancho.org/?a=blobdiff_plain;f=src%2Fvideo.scm;h=a9db7be0b7e03dce39f93e0c0bb611acbd9331a9;hb=6ecc92491ec58e41fc41e3620f2e7cc6bd1534e6;hp=e65d6bdcecaeb787b003764932237c03663a718c;hpb=bdc03bcc2da4d01745fb542d7a7d642b888b691e;p=gacela.git diff --git a/src/video.scm b/src/video.scm index e65d6bd..a9db7be 100644 --- a/src/video.scm +++ b/src/video.scm @@ -353,7 +353,7 @@ #:texture-coord texture-coord #:color color))) -(define* (draw-square #:key (size 1) texture color) +(define* (draw-square size #:key texture color) (draw-rectangle size size #:texture texture #:color color)) (define* (draw-cube #:key (size 1) @@ -455,9 +455,7 @@ '(draw translate turn rotate inner-properties inner-property properties properties-set! property property-set!) (lambda (record port) (format port "#" port)))) @@ -555,20 +553,51 @@ mesh) +;;; Advanced meshes + +(define (mesh-join . meshes) + (make-mesh + 'joined-meshes + (lambda (props) + (for-each (lambda (m) (glmatrix-block (mesh-draw m))) meshes)))) + + ;;; Primitives -(define-macro (define-mesh header . body) - (let ((name (car header)) - (args (cdr header))) - `(define* ,header +(define-macro (primitive header . body) + (let* ((type (car header)) + (args (cdr header)) + (list-args (names-arguments args))) + `(lambda* ,args (let ((m (make-mesh - ',name + ',type (lambda (props) - (apply (lambda* ,args ,@body) - ((@ (gacela utils) arguments-apply) ,name props)))))) - (mesh-properties-set! m (list ,@(map (lambda (a) `(cons ',a ,a)) (names-arguments args)))) + (apply (lambda* ,(cons #:key list-args) ,@body) + (list + ,@(let get-params ((l list-args)) + (cond ((null? l) '()) + (else + (cons (symbol->keyword (car l)) + (cons `(assoc-ref props ',(car l)) + (get-params (cdr l))))))))))))) + (mesh-properties-set! m (list ,@(map (lambda (a) `(cons ',a ,a)) list-args))) m)))) +(define-macro (define-primitive header . body) + `(define ,(car header) (primitive ,header ,@body))) + + +;;; Primitives definition + +(define-primitive (square size #:key texture color) + (draw-square size #:texture texture #:color color)) + +(define-primitive (rectangle width height #:key texture color texture-coord) + (draw-rectangle width height #:texture texture #:color color #:texture-coord texture-coord)) + +(define-primitive (picture filename #:key (min-filter GL_LINEAR) (mag-filter GL_LINEAR) (zoom 1) (sprite '((0 0) (1 1)))) + (draw-texture (load-texture filename #:min-filter min-filter #:mag-filter mag-filter) #:zoom zoom #:sprite sprite)) + (module-map (lambda (sym var) (if (not (eq? sym '%module-public-interface))