From 6ec7869abaada6e555c17b64a7b64f2b052b5da2 Mon Sep 17 00:00:00 2001 From: Bill Robinson Date: Tue, 1 Feb 2011 21:57:09 +0000 Subject: [PATCH] Added FTGL for convenience --- cl-glfw-ftgl.asd | 9 +++++++ examples/ftgl-text.lisp | 18 ++++++++++++++ lib/ftgl-package.lisp | 43 ++++++++++++++++++++++++++++++++ lib/ftgl.lisp | 65 +++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 135 insertions(+) create mode 100644 cl-glfw-ftgl.asd create mode 100644 examples/ftgl-text.lisp create mode 100644 lib/ftgl-package.lisp create mode 100644 lib/ftgl.lisp diff --git a/cl-glfw-ftgl.asd b/cl-glfw-ftgl.asd new file mode 100644 index 0000000..59721e1 --- /dev/null +++ b/cl-glfw-ftgl.asd @@ -0,0 +1,9 @@ +(defpackage #:cl-glfw-ftgl-system + (:use #:cl #:asdf)) +(in-package #:cl-glfw-ftgl-system) + +(defsystem cl-glfw-ftgl + :depends-on (cffi) + :components ((:module lib :serial t + :components ((:file "ftgl-package") + (:file "ftgl"))))) diff --git a/examples/ftgl-text.lisp b/examples/ftgl-text.lisp new file mode 100644 index 0000000..dc4fd85 --- /dev/null +++ b/examples/ftgl-text.lisp @@ -0,0 +1,18 @@ +(require '#:asdf) +(asdf:oos 'asdf:load-op '#:cl-glfw) +(asdf:oos 'asdf:load-op '#:cl-glfw-opengl-version_1_1) +(asdf:oos 'asdf:load-op '#:cl-glfw-glu) +(asdf:oos 'asdf:load-op '#:cl-glfw-ftgl) + +(let (font) + (glfw:do-window (:title "FTGL Text example") + ((gl:with-setup-projection + (glu:perspective 45 4/3 10 500)) + (setf font (ftgl:create-texture-font "/usr/share/fonts/truetype/freefont/FreeSans.ttf")) + (ftgl:set-font-face-size font 20 0)) + (gl:clear gl:+color-buffer-bit+) + (gl:load-identity) + (gl:translate-f 0 0 -400) + (gl:rotate-f (* 10 (glfw:get-time)) 1 1 0) + (gl:rotate-f (* 90 (glfw:get-time)) 0 0 1) + (ftgl:render-font font "Hello world!" :all))) \ No newline at end of file diff --git a/lib/ftgl-package.lisp b/lib/ftgl-package.lisp new file mode 100644 index 0000000..4501072 --- /dev/null +++ b/lib/ftgl-package.lisp @@ -0,0 +1,43 @@ + +(defpackage #:cl-glfw-ftgl + (:nicknames #:ftgl) + (:use #:cl #:cffi) + (:export + ;; our own stuff + #:with-font + ;; bindings + #:create-custom-font + #:destroy-font + #:attach-file + #:attach-data + #:set-font-char-map + #:get-font-char-map-count + #:get-font-char-map-list + #:set-font-face-size + #:get-font-face-size + #:set-font-depth + #:set-font-outset + #:set-font-display-list + #:get-font-ascender + #:get-font-descender + #:get-font-line-height + #:get-font-bbox + #:get-font-advance + #:render-font + #:get-font-error + #:create-pixmap-font + #:create-polygon-font + #:create-outline-font + #:create-extrude-font + #:create-buffer-font + #:create-texture-font + #:create-custom-glyph + #:destroy-glyph + #:render-glyph + #:get-glyph-advance + #:get-glyph-bbox + #:get-glyph-error + #:destroy-layout + #:get-layout-bbox + #:render-layout + #:get-layout-error)) \ No newline at end of file diff --git a/lib/ftgl.lisp b/lib/ftgl.lisp new file mode 100644 index 0000000..db04911 --- /dev/null +++ b/lib/ftgl.lisp @@ -0,0 +1,65 @@ +(in-package :cl-glfw-ftgl) + +(define-foreign-library ftgl + (:unix (:or "libftgl" "libftgl.so.2")) + (t (:default "libftgl"))) +(use-foreign-library ftgl) + +(defctype font :pointer) +(defctype glyph :pointer) +(defctype layout :pointer) +(defcenum encoding + (:none 0) + (:unicode #x756e6963) ; unic + (:adobe-latin-1 #x6c617431)) ; lat1 +(defcenum render-mode + (:front 1) + (:back 2) + (:side 4) + (:all #xffff)) +(defcenum text-alignment + (:left 0) + (:center 1) + (:right 2) + (:justify 3)) + +(defcfun ("ftglCreateCustomFont" create-custom-font) font "Create a custom FTGL font object." + (font-file-path :string) (data :pointer) (make-glyph-callback :pointer)) +(defcfun ("ftglDestroyFont" destroy-font) :void "Destroy an FTGL font object." (font font)) +(defcfun ("ftglAttachFile" attach-file) :int "Attach auxilliary file to font e.g." (font font) (path :string)) +;; XXX size is actually size_t +(defcfun ("ftglAttachData" attach-data) :int "Attach auxilliary data to font, e.g." (font font) (data (:pointer :uint8)) (size :int)) +(defcfun ("ftglSetFontCharMap" set-font-char-map) :int "Set the character map for the face." (font font) (encoding encoding)) +(defcfun ("ftglGetFontCharMapCount" get-font-char-map-count) :unsigned-int "Get the number of character maps in this face." (font font)) +(defcfun ("ftglGetFontCharMapList" get-font-char-map-list) encoding "Get a list of character maps in this face." (font font)) +(defcfun ("ftglSetFontFaceSize" set-font-face-size) :int "Set the char size for the current face." (font font) (size :unsigned-int) (res :unsigned-int)) +(defcfun ("ftglGetFontFaceSize" get-font-face-size) :unsigned-int "Get the current face size in points (1/72 inch)." (font font)) +(defcfun ("ftglSetFontDepth" set-font-depth) :void "Set the extrusion distance for the font." (font font) (depth :float)) +(defcfun ("ftglSetFontOutset" set-font-outset) :void "Set the outset distance for the font." (font font) (front :float) (back :float)) +(defcfun ("ftglSetFontDisplayList" set-font-display-list) :void "Enable or disable the use of Display Lists inside FTGL." (font font) (use-list :boolean)) +(defcfun ("ftglGetFontAscender" get-font-ascender) :float "Get the global ascender height for the face." (font font)) +(defcfun ("ftglGetFontDescender" get-font-descender) :float "Gets the global descender height for the face." (font font)) +(defcfun ("ftglGetFontLineHeight" get-font-line-height) :float "Gets the line spacing for the font." (font font)) +(defcfun ("ftglGetFontBBox" %get-font-bbox) :void "Get the bounding box for a string." (font font) (string :string) (len :int) (bounds (:pointer :float))) +(defcfun ("ftglGetFontAdvance" get-font-advance) :float "Get the advance width for a string." (font font) (string :string)) +(defcfun ("ftglRenderFont" render-font) :void "Render a string of characters." (font font) (string :string) (mode render-mode)) +(defcfun ("ftglGetFontError" get-font-error) :int "Query a font for errors." (font font)) + +(defcfun ("ftglCreatePixmapFont" create-pixmap-font) font "Create a specialised FTGLfont object for handling pixmap (grey scale) fonts." (file :string)) +(defcfun ("ftglCreatePolygonFont" create-polygon-font) font "Create a specialised FTGLfont object for handling tesselated polygon mesh fonts." (file :string)) +(defcfun ("ftglCreateOutlineFont" create-outline-font) font "Create a specialised FTGLfont object for handling vector outline fonts." (file :string)) +(defcfun ("ftglCreateExtrudeFont" create-extrude-font) font "Create a specialised FTGLfont object for handling extruded poygon fonts." (file :string)) +(defcfun ("ftglCreateTextureFont" create-texture-font) font "Create a specialised FTGLfont object for handling texture-mapped fonts." (file :string)) +(defcfun ("ftglCreateBufferFont" create-buffer-font) font "Create a specialised FTGLfont object for handling buffered fonts." (file :string)) + +(defcfun ("ftglCreateCustomGlyph" create-custom-glyph) glyph "Create a custom FTGL glyph object." (base glyph) (data :pointer) (render-callback :pointer) (destroy-callback :pointer)) +(defcfun ("ftglDestroyGlyph" destroy-glyph) :void "Destroy an FTGL glyph object." (glyph glyph)) +(defcfun ("ftglRenderGlyph" render-glyph) :void "Render a glyph at the current pen position and compute the corresponding advance." (glyph glyph) (penx :double) (peny :double) (render-mode render-mode) (advance-x (:pointer :double)) (advance-y (:pointer :double))) +(defcfun ("ftglGetGlyphAdvance" get-glyph-advance) :float "Return the advance for a glyph." (glyph glyph)) +(defcfun ("ftglGetGlyphBBox" get-glyph-bbox) :void "Return the bounding box for a glyph." (glyph glyph) (bounds (:pointer :float))) +(defcfun ("ftglGetGlyphError" get-glyph-error) :int "Query a glyph for errors." (glyph glyph)) + +(defcfun ("ftglDestroyLayout" destroy-layout) :void "Destroy an FTGL layout object." (layout layout)) +;;(defcfun ("ftglGetLayoutBBox" get-layout-bbox) :void "Get the bounding box for a string." (layout layout) (string :string) (bounds (:pointer :float))) +(defcfun ("ftglRenderLayout" render-layout) :void "Render a string of characters." (layout layout) (string :string) (mode render-mode)) +(defcfun ("ftglGetLayoutError" get-layout-error) :int "Query a layout for errors." (layout layout)) -- 2.11.4.GIT