summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Thompson <dthompson@member.fsf.org>2013-07-06 16:42:16 -0400
committerDavid Thompson <dthompson@member.fsf.org>2013-07-06 16:42:16 -0400
commit9d6d69e8067a8f10e155b271021f78a3cf7e8609 (patch)
tree9672ab9e98292ace85ce47f6425108efa82f037e
parent29adec1693fd4dd8135e2b0ae9733eeb822978b0 (diff)
Add optional texture coordinate parameters to texture-quad and sprite-batch-draw.
-rw-r--r--2d/sprite.scm13
-rw-r--r--2d/texture.scm11
2 files changed, 13 insertions, 11 deletions
diff --git a/2d/sprite.scm b/2d/sprite.scm
index bcf09b6..5a0cf00 100644
--- a/2d/sprite.scm
+++ b/2d/sprite.scm
@@ -187,8 +187,9 @@
;; TODO add transformation logic for scaling and rotating.
;; TODO add support for colors
;; TODO add support for different blending modes.
-(define (sprite-batch-draw batch texture x y center-x center-y
- width height scale-x scale-y rotation)
+(define* (sprite-batch-draw batch texture x y center-x center-y
+ width height scale-x scale-y rotation
+ #:optional (u 0) (v 0) (u2 1) (v2 1))
;; Render the batch when it's full or the texture changes.
(cond ((= (sprite-batch-size batch) (sprite-batch-max-size batch))
(sprite-batch-render batch))
@@ -204,19 +205,19 @@
(pack vertices base sprite-vertex
x y
1 1 1 1
- 0 0)
+ u v)
(pack vertices (+ base 1) sprite-vertex
x2 y
1 1 1 1
- 1 0)
+ u2 v)
(pack vertices (+ base 2) sprite-vertex
x2 y2
1 1 1 1
- 1 1)
+ u2 v2)
(pack vertices (+ base 3) sprite-vertex
x y2
1 1 1 1
- 0 1))
+ u v2))
;; Increment batch size
(set-sprite-batch-size! batch (1+ (sprite-batch-size batch))))
diff --git a/2d/texture.scm b/2d/texture.scm
index 0db72a2..2276025 100644
--- a/2d/texture.scm
+++ b/2d/texture.scm
@@ -108,20 +108,21 @@ Currently only works with RGBA format surfaces."
"Loads a texture from a file."
(surface->texture (SDL:load-image filename)))
-(define* (texture-quad texture x y w h #:optional (color '(1 1 1)))
+(define* (texture-quad texture x y w h #:optional (color '(1 1 1))
+ (u 0) (v 0) (u2 1) (v2 1))
"Renders a textured quad."
(let ((x2 (+ x w))
(y2 (+ y h)))
(with-gl-bind-texture (texture-target texture-2d) (texture-id texture)
(gl-begin (begin-mode quads)
(apply gl-color color)
- (gl-texture-coordinates 0 0)
+ (gl-texture-coordinates u v)
(gl-vertex x y)
- (gl-texture-coordinates 1 0)
+ (gl-texture-coordinates u2 v)
(gl-vertex x2 y)
- (gl-texture-coordinates 1 1)
+ (gl-texture-coordinates u2 v2)
(gl-vertex x2 y2)
- (gl-texture-coordinates 0 1)
+ (gl-texture-coordinates u v2)
(gl-vertex x y2)))))
;;;