From c8457c8c8a0341d9a89cfd13038c48f74c479c95 Mon Sep 17 00:00:00 2001 From: David Thompson Date: Tue, 17 Oct 2017 21:38:06 -0400 Subject: render: texture: Add texture region data type. * chickadee/render/texture.scm (): New record type. --- chickadee/render/texture.scm | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) 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 @@ -217,6 +225,33 @@ magnification. Valid values are 'nearest and 'linear. By default, (lambda (surface) (surface->texture surface min-filter mag-filter wrap-s wrap-t)))) + +;;; +;;; Texture Regions +;;; + +(define-record-type + (%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 -- cgit v1.2.3