From 5f9b31e2fa47e7a99216c0c8aa09a1d8d348a4f1 Mon Sep 17 00:00:00 2001 From: David Thompson Date: Sat, 28 Jun 2014 16:16:06 -0400 Subject: Add with-texture macro. * 2d/texture.scm (with-texture): New macro. --- sly/texture.scm | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/sly/texture.scm b/sly/texture.scm index bea005d..e4bd7cb 100644 --- a/sly/texture.scm +++ b/sly/texture.scm @@ -25,6 +25,7 @@ (define-module (sly texture) #:use-module (srfi srfi-9) #:use-module (gl) + #:use-module (gl low-level) #:use-module (gl contrib packed-struct) #:use-module (sly color) #:use-module (sly helpers) @@ -46,7 +47,8 @@ anchor-texture texture-vertex pack-texture-vertices - draw-texture-vertices)) + draw-texture-vertices + with-texture)) ;;; ;;; Textures @@ -205,6 +207,13 @@ texture." (pack vertices (+ offset 2) texture-vertex width height s2 t2) (pack vertices (+ offset 3) texture-vertex width 0 s2 t1)) +(define-syntax-rule (with-texture texture body ...) + (begin + (glBindTexture (texture-target texture-2d) (texture-id texture)) + body + ... + (glBindTexture (texture-target texture-2d) 0))) + (define (draw-texture-vertices texture vertices size) (let ((pointer-type (tex-coord-pointer-type float))) (gl-enable-client-state (enable-cap vertex-array)) -- cgit v1.2.3