]> git.jsancho.org Git - gacela.git/blob - src/gacela_FTGL.c
15232fac5eab4703c8e9fa1e26615280a802088f
[gacela.git] / src / gacela_FTGL.c
1 /* Gacela, a GNU Guile extension for fast games development
2    Copyright (C) 2009 by Javier Sancho Fernandez <jsf at jsancho dot org>
3
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.
8
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.
13
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/>.
16 */
17
18 #include <libguile.h>
19 #include <FTGL/ftgl.h>
20 #include "gacela_FTGL.h"
21
22 struct font
23 {
24   SCM filename;
25   FTGLfont *font_address;
26 };
27
28 static scm_t_bits font_tag;
29
30
31 SCM
32 gacela_ftglCreateTextureFont (SCM file)
33 {
34   SCM smob;
35   struct font *font;
36   FTGLfont *font_address = NULL;
37
38   font_address = ftglCreateTextureFont (scm_to_locale_string (file));
39
40   if (font_address) {
41     font = (struct font *) scm_gc_malloc (sizeof (struct font), "font");
42
43     font->filename = SCM_BOOL_F;
44     font->font_address = NULL;
45
46     SCM_NEWSMOB (smob, font_tag, font);
47
48     font->filename = file;
49     font->font_address = font_address;
50
51     return smob;
52   }
53   else {
54     return SCM_UNSPECIFIED;
55   }
56 }
57
58 SCM
59 gacela_ftglSetFontFaceSize (SCM font, SCM size, SCM res)
60 {
61   return scm_from_int (ftglSetFontFaceSize ((FTGLfont *)scm_to_int (font), scm_to_int (size), scm_to_int (res)));
62 }
63
64 SCM
65 gacela_ftglSetFontCharMap (SCM font, SCM encoding)
66 {
67   return scm_from_int (ftglSetFontCharMap ((FTGLfont *)scm_to_int (font), scm_to_int (encoding)));
68 }
69
70 SCM
71 gacela_ftglRenderFont (SCM font, SCM string, SCM mode)
72 {
73   ftglRenderFont ((FTGLfont *)scm_to_int (font), scm_to_locale_string(string), scm_to_int (mode));
74   return SCM_UNSPECIFIED;
75 }
76
77 SCM
78 gacela_ftglDestroyFont (SCM font)
79 {
80   ftglDestroyFont ((FTGLfont *)scm_to_int (font));
81   return SCM_UNSPECIFIED;
82 }
83
84 void*
85 FTGL_register_functions (void* data)
86 {
87   font_tag = scm_make_smob_type ("font", sizeof (struct font));
88   //  scm_set_smob_mark (surface_tag, mark_surface);
89   //  scm_set_smob_free (surface_tag, free_surface);
90   //  scm_set_smob_print (surface_tag, print_surface);
91   //  scm_set_smob_equalp (surface_tag, equalp_surface);
92
93   scm_c_define ("ft_encoding_unicode", scm_from_int (ft_encoding_unicode));
94   scm_c_define ("FTGL_RENDER_ALL", scm_from_int (FTGL_RENDER_ALL));
95
96   scm_c_define_gsubr ("ftglCreateTextureFont", 1, 0, 0, gacela_ftglCreateTextureFont);
97   scm_c_define_gsubr ("ftglSetFontFaceSize", 3, 0, 0, gacela_ftglSetFontFaceSize);
98   scm_c_define_gsubr ("ftglSetFontCharMap", 2, 0, 0, gacela_ftglSetFontCharMap);
99   scm_c_define_gsubr ("ftglRenderFont", 3, 0, 0, gacela_ftglRenderFont);
100   scm_c_define_gsubr ("ftglDestroyFont", 1, 0, 0, gacela_ftglDestroyFont);
101
102   return NULL;
103 }