summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-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
;;;