summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Thompson <dthompson2@worcester.edu>2017-10-17 21:38:06 -0400
committerDavid Thompson <dthompson2@worcester.edu>2017-10-17 21:38:06 -0400
commitc8457c8c8a0341d9a89cfd13038c48f74c479c95 (patch)
tree8f27c33a97ed96fdca155c7c639f7a00346b2466
parent4b216e910f562c790dd59ddea8398d60bc2bd1b0 (diff)
render: texture: Add texture region data type.
* chickadee/render/texture.scm (<texture-region>): New record type.
-rw-r--r--chickadee/render/texture.scm35
1 files changed, 35 insertions, 0 deletions
diff --git a/chickadee/render/texture.scm b/chickadee/render/texture.scm
index e019aa7..c37fef9 100644
--- a/chickadee/render/texture.scm
+++ b/chickadee/render/texture.scm
@@ -48,6 +48,14 @@
texture-set!
texture-ref
+ make-texture-region
+ texture-region?
+ texture-region-texture
+ texture-region-x
+ texture-region-y
+ texture-region-width
+ texture-region-height
+
texture-atlas
list->texture-atlas
split-texture
@@ -219,6 +227,33 @@ magnification. Valid values are 'nearest and 'linear. By default,
;;;
+;;; Texture Regions
+;;;
+
+(define-record-type <texture-region>
+ (%make-texture-region texture x y width height gl-rect gl-size)
+ texture-region?
+ (texture texture-region-texture)
+ (x texture-region-x)
+ (y texture-region-y)
+ (width texture-region-width)
+ (height texture-region-height)
+ (gl-rect texture-region-gl-rect)
+ (gl-size texture-region-gl-size))
+
+(define (make-texture-region texture x y width height)
+ "Create a new texture region covering a section of TEXTURE defined
+by the bounding box X, Y, WIDTH, and HEIGHT. All coordinates are
+measured in pixels and must be integers."
+ (let* ((tw (texture-width texture))
+ (th (texture-height texture))
+ (gl-rect (make-rect (/ x tw) (/ y th)
+ (/ (+ x width) tw) (/ (+ y height) th))))
+ (%make-texture-region texture x y width height gl-rect
+ (f32vector width height))))
+
+
+;;;
;;; Texture Atlas
;;;