From 31b6f11b45d810a2e38e37f2f26ccd979166f356 Mon Sep 17 00:00:00 2001 From: David Thompson Date: Tue, 17 Oct 2017 21:41:40 -0400 Subject: render: texture: Use texture regions in texture atlas. * chickadee/render/texture.scm (list->texture-atlas): Create texture regions. Switch from rects to 4-tuples. (texture-atlas, texture-atlas-ref): Update docstring. (split-texture): Create texture regions. --- chickadee/render/texture.scm | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/chickadee/render/texture.scm b/chickadee/render/texture.scm index 2b4755e..9a1421a 100644 --- a/chickadee/render/texture.scm +++ b/chickadee/render/texture.scm @@ -274,17 +274,18 @@ coordinate rects denoting the various tiles within." (rects rects)) (match rects (() (%make-texture-atlas texture v)) - ((r . rest) - (vector-set! v i r) + (((x y width height) . rest) + (vector-set! v i (make-texture-region texture x y width height)) (loop (1+ i) rest)))))) (define (texture-atlas texture . rects) "Return a new atlas for TEXTURE containing RECTS, a series of -texture coordinate rect arguments denoting the various tiles within." +4-tuples in the form (x y width height) describing the various tiles +within." (list->texture-atlas texture rects)) (define (texture-atlas-ref atlas index) - "Return the texture coordinate rect associated with INDEX in + "Return the texture region associated with INDEX in ATLAS." (vector-ref (texture-atlas-vector atlas) index)) @@ -308,7 +309,7 @@ terrain." (define (make-tile tx ty) (let* ((x (+ (* tx (+ tile-width spacing)) margin)) (y (+ (* ty (+ tile-height spacing)) margin))) - (make-rect (/ x w) (/ y h) sw th))) + (make-texture-region texture x y tile-width tile-height))) (let y-loop ((y 0)) (when (< y rows) (let x-loop ((x 0)) -- cgit v1.2.3