From 54493fb7dc845fcf68a868ec72cdc94999e2597b Mon Sep 17 00:00:00 2001 From: David Thompson Date: Sat, 17 Aug 2013 23:00:24 -0400 Subject: Create initial bindings for ftgl. --- 2d/wrappers/ftgl.scm | 89 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 89 insertions(+) create mode 100644 2d/wrappers/ftgl.scm (limited to '2d/wrappers/ftgl.scm') diff --git a/2d/wrappers/ftgl.scm b/2d/wrappers/ftgl.scm new file mode 100644 index 0000000..6c94840 --- /dev/null +++ b/2d/wrappers/ftgl.scm @@ -0,0 +1,89 @@ +;;; guile-2d +;;; Copyright (C) 2013 David Thompson +;;; +;;; Guile-2d is free software: you can redistribute it and/or modify it +;;; under the terms of the GNU Lesser General Public License as +;;; published by the Free Software Foundation, either version 3 of the +;;; License, or (at your option) any later version. +;;; +;;; Guile-2d is distributed in the hope that it will be useful, but +;;; WITHOUT ANY WARRANTY; without even the implied warranty of +;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +;;; Lesser General Public License for more details. +;;; +;;; You should have received a copy of the GNU Lesser General Public +;;; License along with this program. If not, see +;;; . + +;;; Commentary: +;; +;; Quick and dirty wrapper for the FTGL library. +;; +;;; Code: + +(define-module (2d wrappers ftgl) + #:use-module (system foreign) + #:use-module (2d wrappers util)) + +(define libftgl (dynamic-link "libftgl")) + +(define-syntax-rule (define-foreign name ret string-name args) + (define name + (pointer->procedure ret (dynamic-func string-name libftgl) args))) + +;;; +;;; Enums +;;; + +(define-enumeration ftgl-render-mode + (front #x0001) + (back #x0002) + (side #x0004) + (all #xffff)) + +(define-enumeration ftgl-text-alignment + (left 0) + (center 1) + (right 2) + (justify 3)) + +(export ftgl-render-mode + ftgl-text-alignment) + +;;; +;;; Fonts +;;; + +(define-wrapped-pointer-type + ftgl-font? + wrap-ftgl-font unwrap-ftgl-font + (lambda (r port) + (let ((font (unwrap-ftgl-font r))) + (format port + "" + (pointer-address font))))) + +(define-foreign %ftgl-create-texture-font + '* "ftglCreateTextureFont" '(*)) + +(define-foreign %ftgl-set-font-face-size + void "ftglSetFontFaceSize" (list '* unsigned-int unsigned-int)) + +(define-foreign %ftgl-render-font + void "ftglRenderFont" (list '* '* unsigned-int)) + +(define (ftgl-create-texture-font filename) + (wrap-ftgl-font + (%ftgl-create-texture-font (string->pointer filename)))) + +(define (ftgl-set-font-face-size font size res) + (%ftgl-set-font-face-size (unwrap-ftgl-font font) size res)) + +(define (ftgl-render-font font text render-mode) + (%ftgl-render-font (unwrap-ftgl-font font) + (string->pointer text) + render-mode)) + +(export ftgl-create-texture-font + ftgl-set-font-face-size + ftgl-render-font) -- cgit v1.2.3