summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Thompson <dthompson2@worcester.edu>2018-01-17 13:33:10 -0500
committerDavid Thompson <dthompson2@worcester.edu>2018-01-17 13:33:10 -0500
commitdf2872c456185090f3b4a7ceba408d576526ba32 (patch)
tree53f965cfe0b3f44bbe40e84cdc6133adb55afb6c
parent4a7d9c49f3454a01487ab3661e9d9cd9d6850a7e (diff)
render: sprite: Fix bug in rendering texture regions.
The texture-rect procedure contains the pixel location of the texture region, so if you use that rect to render a sprite the result is a sprite offset by its location in the greater texture, which is very very very wrong. * chickadee/render/sprite.scm (draw-sprite): Dynamically configure rendering rect based on the texture region's width and height.
-rw-r--r--chickadee/render/sprite.scm12
1 files changed, 9 insertions, 3 deletions
diff --git a/chickadee/render/sprite.scm b/chickadee/render/sprite.scm
index c284ff4..78a2ce5 100644
--- a/chickadee/render/sprite.scm
+++ b/chickadee/render/sprite.scm
@@ -341,7 +341,8 @@ void main (void) {
(define %default-scale (vec2 1.0 1.0))
(define draw-sprite
- (let ((matrix (make-null-matrix4)))
+ (let ((matrix (make-null-matrix4))
+ (%rect (make-rect 0.0 0.0 0.0 0.0)))
(lambda* (texture
position
#:key
@@ -349,7 +350,12 @@ void main (void) {
(scale %default-scale)
(rotation 0.0)
(blend-mode 'alpha)
- (rect (texture-rect texture))
+ ;; Default to an area that is the same size of the
+ ;; texture. 99% of the time that's what you want.
+ (rect (let ((r (texture-rect texture)))
+ (set-rect-width! %rect (rect-width r))
+ (set-rect-height! %rect (rect-height r))
+ %rect))
(shader (force default-shader)))
"Draw TEXTURE at POSITION.
@@ -368,7 +374,7 @@ rendered entirely."
#:position position
#:rotation rotation
#:scale scale)
- (draw-sprite* texture (texture-rect texture) matrix
+ (draw-sprite* texture rect matrix
#:blend-mode blend-mode
#:shader shader))))