diff options
-rw-r--r-- | 2d/font.scm | 17 | ||||
-rw-r--r-- | 2d/texture.scm | 2 | ||||
-rw-r--r-- | 2d/window.scm | 2 | ||||
-rw-r--r-- | 2d/wrappers/ftgl.scm | 16 |
4 files changed, 32 insertions, 5 deletions
diff --git a/2d/font.scm b/2d/font.scm index 70b0904..8bf66a3 100644 --- a/2d/font.scm +++ b/2d/font.scm @@ -47,11 +47,21 @@ (ftgl-set-font-face-size ftgl-font size 72) (make-font ftgl-font size))) +(define (flip-text font) + "Flips current GL matrix about the x-axis and translates by the +negative font ascender value. This is necessary before rendering text +because guile-2d flips the y-axis so that the origin is in the +upper-left corner rather than the bottom-left." + (gl-scale 1 -1 1) + (gl-translate 0 (- (ftgl-get-font-ascender (font-ftgl-font font))) 0)) + (define (draw-font font text) "Renders the string text using the given font." - (ftgl-render-font (font-ftgl-font font) - text - (ftgl-render-mode all))) + (with-gl-push-matrix + (flip-text font) + (ftgl-render-font (font-ftgl-font font) + text + (ftgl-render-mode all)))) (export <font> make-font @@ -88,6 +98,7 @@ (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) diff --git a/2d/texture.scm b/2d/texture.scm index 19c26c8..8df5e51 100644 --- a/2d/texture.scm +++ b/2d/texture.scm @@ -141,6 +141,8 @@ (bitmap (freeimage-load image-type filename)) (32bit-bitmap (freeimage-convert-to-32-bits bitmap))) (freeimage-unload bitmap) + ;; Need to flip because y-axis is reversed. + (freeimage-flip-vertical 32bit-bitmap) 32bit-bitmap)) (define (load-texture filename) diff --git a/2d/window.scm b/2d/window.scm index de824d8..9c863f6 100644 --- a/2d/window.scm +++ b/2d/window.scm @@ -45,7 +45,7 @@ initializes OpenGL state." (gl-viewport 0 0 width height) (set-gl-matrix-mode (matrix-mode projection)) (gl-load-identity) - (gl-ortho 0 width 0 height -1 1) + (gl-ortho 0 width height 0 -1 1) (set-gl-matrix-mode (matrix-mode modelview)) (gl-load-identity) ;; Enable texturing and alpha blending diff --git a/2d/wrappers/ftgl.scm b/2d/wrappers/ftgl.scm index 1d18fad..537655c 100644 --- a/2d/wrappers/ftgl.scm +++ b/2d/wrappers/ftgl.scm @@ -73,6 +73,12 @@ (define-foreign %ftgl-render-font void "ftglRenderFont" (list '* '* unsigned-int)) +(define-foreign %ftgl-get-font-descender + float "ftglGetFontDescender" '(*)) + +(define-foreign %ftgl-get-font-ascender + float "ftglGetFontAscender" '(*)) + (define (ftgl-create-texture-font filename) (wrap-ftgl-font (%ftgl-create-texture-font (string->pointer filename)))) @@ -85,9 +91,17 @@ (string->pointer text) render-mode)) +(define (ftgl-get-font-descender font) + (%ftgl-get-font-descender (unwrap-ftgl-font font))) + +(define (ftgl-get-font-ascender font) + (%ftgl-get-font-ascender (unwrap-ftgl-font font))) + (export ftgl-create-texture-font ftgl-set-font-face-size - ftgl-render-font) + ftgl-render-font + ftgl-get-font-descender + ftgl-get-font-ascender) ;;; ;;; SimpleLayout |