1 | #include "EXTERN.h" |
1 | #include "EXTERN.h" |
2 | #include "perl.h" |
2 | #include "perl.h" |
3 | #include "XSUB.h" |
3 | #include "XSUB.h" |
4 | |
4 | |
|
|
5 | #include <string.h> |
|
|
6 | |
5 | #include <SDL.h> |
7 | #include <SDL.h> |
6 | #include <SDL_image.h> |
8 | #include <SDL_opengl.h> |
|
|
9 | |
|
|
10 | #include <pango/pango.h> |
|
|
11 | #include <pango/pangoft2.h> |
|
|
12 | |
|
|
13 | static PangoContext *context; |
|
|
14 | static PangoFontMap *fontmap; |
7 | |
15 | |
8 | MODULE = Crossfire::Client PACKAGE = Crossfire::Client |
16 | MODULE = Crossfire::Client PACKAGE = Crossfire::Client |
9 | |
17 | |
|
|
18 | BOOT: |
|
|
19 | { |
|
|
20 | fontmap = pango_ft2_font_map_new (); |
|
|
21 | context = pango_context_new (); |
|
|
22 | pango_context_set_font_map (context, fontmap); |
|
|
23 | } |
10 | |
24 | |
|
|
25 | char * |
|
|
26 | gl_version () |
|
|
27 | CODE: |
|
|
28 | RETVAL = (char *)glGetString (GL_VERSION); |
|
|
29 | OUTPUT: |
|
|
30 | RETVAL |
|
|
31 | |
|
|
32 | char * |
|
|
33 | gl_extensions () |
|
|
34 | CODE: |
|
|
35 | RETVAL = (char *)glGetString (GL_EXTENSIONS); |
|
|
36 | OUTPUT: |
|
|
37 | RETVAL |
|
|
38 | |
|
|
39 | void |
|
|
40 | font_render (SV *text_, int height = 10) |
|
|
41 | PPCODE: |
|
|
42 | { |
|
|
43 | STRLEN textlen; |
|
|
44 | char *text = SvPVutf8 (text_, textlen); |
|
|
45 | SV *retval; |
|
|
46 | int w, h; |
|
|
47 | FT_Bitmap bitmap; |
|
|
48 | PangoLayout *layout; |
|
|
49 | PangoFontDescription *font = pango_context_get_font_description (context); |
|
|
50 | pango_font_description_set_absolute_size (font, height * PANGO_SCALE); |
|
|
51 | |
|
|
52 | layout = pango_layout_new (context); |
|
|
53 | pango_layout_set_markup (layout, text, textlen); |
|
|
54 | pango_layout_get_pixel_size (layout, &w, &h); |
|
|
55 | |
|
|
56 | w = (w + 3) & ~3; |
|
|
57 | if (!w) w = 1; |
|
|
58 | if (!h) h = 1; |
|
|
59 | |
|
|
60 | retval = newSV (w * h); |
|
|
61 | SvPOK_only (retval); |
|
|
62 | SvCUR_set (retval, w * h); |
|
|
63 | |
|
|
64 | bitmap.rows = h; |
|
|
65 | bitmap.width = w; |
|
|
66 | bitmap.pitch = w; |
|
|
67 | bitmap.buffer = (unsigned char*)SvPVX (retval); |
|
|
68 | bitmap.num_grays = 256; |
|
|
69 | bitmap.pixel_mode = FT_PIXEL_MODE_GRAY; |
|
|
70 | |
|
|
71 | memset (bitmap.buffer, 0, w * h); |
|
|
72 | |
|
|
73 | pango_ft2_render_layout (&bitmap, layout, 0 * PANGO_SCALE, 0 * PANGO_SCALE); |
|
|
74 | g_object_unref (layout); |
|
|
75 | |
|
|
76 | EXTEND (SP, 3); |
|
|
77 | PUSHs (sv_2mortal (newSViv (w))); |
|
|
78 | PUSHs (sv_2mortal (newSViv (h))); |
|
|
79 | PUSHs (sv_2mortal (retval)); |
|
|
80 | } |