1 /* Gacela, a GNU Guile extension for fast games development
2 Copyright (C) 2009 by Javier Sancho Fernandez <jsf at jsancho dot org>
4 This program is free software: you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation, either version 3 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program. If not, see <http://www.gnu.org/licenses/>.
19 #include <FTGL/ftgl.h>
24 FTGLfont *font_address;
28 static scm_t_bits font_tag;
31 make_font (SCM file, SCM size, FTGLfont *font_address)
36 font = (struct font *) scm_gc_malloc (sizeof (struct font), "font");
38 font->filename = SCM_BOOL_F;
39 font->size = scm_to_int (size);
40 font->font_address = NULL;
42 SCM_NEWSMOB (smob, font_tag, font);
44 font->filename = file;
45 font->font_address = font_address;
51 get_font_address (SCM font_smob)
55 scm_assert_smob_type (font_tag, font_smob);
56 font = (struct font *) SCM_SMOB_DATA (font_smob);
57 return font->font_address;
61 get_font_size (SCM font_smob)
65 scm_assert_smob_type (font_tag, font_smob);
66 font = (struct font *) SCM_SMOB_DATA (font_smob);
67 return scm_from_int (font->size);
71 mark_font (SCM font_smob)
73 struct font *font = (struct font *) SCM_SMOB_DATA (font_smob);
75 scm_gc_mark (font->filename);
81 free_font (SCM font_smob)
83 struct font *font = (struct font *) SCM_SMOB_DATA (font_smob);
85 ftglDestroyFont (font->font_address);
86 scm_gc_free (font, sizeof (struct font), "font");
92 print_font (SCM font_smob, SCM port, scm_print_state *pstate)
94 struct font *font = (struct font *) SCM_SMOB_DATA (font_smob);
96 scm_puts ("#<font \"", port);
97 scm_display (font->filename, port);
98 scm_puts ("\", size ", port);
99 scm_display (scm_from_int (font->size), port);
100 scm_puts (">", port);
102 /* non-zero means success */
108 gacela_ftglCreateTextureFont (SCM file, SCM size)
110 FTGLfont *font_address = ftglCreateTextureFont (scm_to_locale_string (file));
113 return make_font (file, size, font_address);
121 gacela_ftglSetFontFaceSize (SCM font, SCM size, SCM res)
123 return scm_from_int (ftglSetFontFaceSize (get_font_address (font), scm_to_int (size), scm_to_int (res)));
127 gacela_ftglGetFontFaceSize (SCM font)
129 return scm_from_int (ftglGetFontFaceSize (get_font_address (font)));
133 gacela_ftglSetFontCharMap (SCM font, SCM encoding)
135 return scm_from_int (ftglSetFontCharMap (get_font_address (font), scm_to_int (encoding)));
139 gacela_ftglRenderFont (SCM font, SCM string, SCM mode)
141 ftglRenderFont (get_font_address (font), scm_to_locale_string(string), scm_to_int (mode));
142 return SCM_UNSPECIFIED;
147 init_gacela_ftgl (void *data)
149 font_tag = scm_make_smob_type ("font", sizeof (struct font));
150 scm_set_smob_mark (font_tag, mark_font);
151 scm_set_smob_free (font_tag, free_font);
152 scm_set_smob_print (font_tag, print_font);
153 // scm_set_smob_equalp (surface_tag, equalp_surface);
154 scm_c_define_gsubr ("font-size", 1, 0, 0, get_font_size);
156 scm_c_define ("ft_encoding_unicode", scm_from_int (ft_encoding_unicode));
157 scm_c_define ("FTGL_RENDER_ALL", scm_from_int (FTGL_RENDER_ALL));
159 scm_c_define_gsubr ("ftglCreateTextureFont", 2, 0, 0, gacela_ftglCreateTextureFont);
160 scm_c_define_gsubr ("ftglSetFontFaceSize", 3, 0, 0, gacela_ftglSetFontFaceSize);
161 scm_c_define_gsubr ("ftglGetFontFaceSize", 1, 0, 0, gacela_ftglGetFontFaceSize);
162 scm_c_define_gsubr ("ftglSetFontCharMap", 2, 0, 0, gacela_ftglSetFontCharMap);
163 scm_c_define_gsubr ("ftglRenderFont", 3, 0, 0, gacela_ftglRenderFont);
168 scm_init_gacela_ftgl ()
170 init_gacela_ftgl (NULL);