From cd9a3d80d8443b4e9a2fbab8f15235fd91e69052 Mon Sep 17 00:00:00 2001 From: David Thompson Date: Tue, 27 Aug 2013 18:39:38 -0400 Subject: Add procedures to perform a gl-translate or gl-scale given a vector2 object. --- 2d/font.scm | 15 +++++++-------- 2d/vector2.scm | 14 +++++++++++++- 2 files changed, 20 insertions(+), 9 deletions(-) (limited to '2d') diff --git a/2d/font.scm b/2d/font.scm index 45b59d0..182f25b 100644 --- a/2d/font.scm +++ b/2d/font.scm @@ -95,14 +95,13 @@ upper-left corner rather than the bottom-left." (%make-textbox font text position color alignment line-length layout))) (define (draw-textbox textbox) - (let ((pos (textbox-position textbox))) - (with-gl-push-matrix - (gl-translate (vx pos) (vy pos) 0) - (flip-text (textbox-font textbox)) - (apply-color (textbox-color textbox)) - (ftgl-render-layout (textbox-layout textbox) - (textbox-text textbox) - (ftgl-render-mode all))))) + (with-gl-push-matrix + (vector2-translate (textbox-position textbox)) + (flip-text (textbox-font textbox)) + (apply-color (textbox-color textbox)) + (ftgl-render-layout (textbox-layout textbox) + (textbox-text textbox) + (ftgl-render-mode all)))) (export make-textbox diff --git a/2d/vector2.scm b/2d/vector2.scm index 7720095..d231f93 100644 --- a/2d/vector2.scm +++ b/2d/vector2.scm @@ -22,6 +22,7 @@ ;;; Code: (define-module (2d vector2) + #:use-module (figl gl) #:use-module (srfi srfi-1) #:use-module (srfi srfi-9) #:export ( @@ -38,7 +39,9 @@ vmag vnorm vdot - vcross)) + vcross + vector2-translate + vector2-scale)) (define-record-type (vector2 x y) @@ -105,3 +108,12 @@ vector is not defined. This function instead returns the Z coordinate of the cross product as if the vectors were in 3D space." (- (* (vx v1) (vy v2)) (* (vy v1) (vx v2)))) + +(define (vector2-translate v) + "Perform an OpenGL translate matrix operation with the given +vector2." + (gl-translate (vx v) (vy v) 0)) + +(define (vector2-scale v) + "Perform an OpenGL scale matrix operation with the given vector2." + (gl-scale (vx v) (vy v) 1)) -- cgit v1.2.3