diff options
author | David Thompson <dthompson@member.fsf.org> | 2013-08-27 18:39:38 -0400 |
---|---|---|
committer | David Thompson <dthompson@member.fsf.org> | 2013-08-27 18:39:38 -0400 |
commit | cd9a3d80d8443b4e9a2fbab8f15235fd91e69052 (patch) | |
tree | 541cecc4b435294c4a3ca0d566d1dd57c64be0be | |
parent | 5841889f53465b4096830f3778b209063e1fe8bc (diff) |
Add procedures to perform a gl-translate or gl-scale given a vector2 object.
-rw-r--r-- | 2d/font.scm | 15 | ||||
-rw-r--r-- | 2d/vector2.scm | 14 |
2 files changed, 20 insertions, 9 deletions
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 <textbox> 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 (<vector2> @@ -38,7 +39,9 @@ vmag vnorm vdot - vcross)) + vcross + vector2-translate + vector2-scale)) (define-record-type <vector2> (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)) |