]> git.jsancho.org Git - gacela.git/blobdiff - gacela_ttf.lisp
(no commit message)
[gacela.git] / gacela_ttf.lisp
index 89d9b6803873520b641c4d9748246f60c269def6..0077ad42aa4c372cb5056bf9e9132c387199e9d6 100644 (file)
 
 (in-package :gacela)
 
-(defun open-font (font-file &optional (size 80) (encoding ft_encoding_unicode))
-  (let ((font (ftglCreateTextureFont font-file)))
-    (cond ((/= font 0)
-          (ftglSetFontFaceSize font size 72)
-          (ftglSetFontCharMap font encoding)
-          font))))
+(defun open-font (font-file &key (size 80) (encoding ft_encoding_unicode) static)
+  (let ((key (make-resource-font :filename font-file :size size :encoding encoding)))
+    (cond ((get-resource key) key)
+         (t
+          (let ((font (ftglCreateTextureFont font-file)))
+            (cond ((/= font 0)
+                   (ftglSetFontFaceSize font size 72)
+                   (ftglSetFontCharMap font encoding)
+                   (set-resource key
+                                 `(:id-font ,font)
+                                 (lambda () (open-font font-file :size size :encoding encoding :static static))
+                                 (lambda () (ftglDestroyFont font))
+                                 :static static)
+                   key)))))))
 
 (defun render-text (text font)
-  (ftglRenderFont font text FTGL_RENDER_ALL))
+  (ftglRenderFont (getf font :id-font) text FTGL_RENDER_ALL))