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_opengl.h> |
8 | #include <SDL_opengl.h> |
7 | #include <SDL_image.h> |
9 | |
|
|
10 | #include <pango/pango.h> |
|
|
11 | #include <pango/pangofc-fontmap.h> |
|
|
12 | #include <pango/pangoft2.h> |
|
|
13 | |
|
|
14 | #include <sys/types.h> |
|
|
15 | #include <sys/socket.h> |
|
|
16 | #include <netinet/in.h> |
|
|
17 | #include <netinet/tcp.h> |
|
|
18 | |
|
|
19 | static PangoContext *context; |
|
|
20 | static PangoFontMap *fontmap; |
8 | |
21 | |
9 | MODULE = Crossfire::Client PACKAGE = Crossfire::Client |
22 | MODULE = Crossfire::Client PACKAGE = Crossfire::Client |
|
|
23 | |
|
|
24 | PROTOTYPES: ENABLE |
|
|
25 | |
|
|
26 | BOOT: |
|
|
27 | { |
|
|
28 | fontmap = pango_ft2_font_map_new (); |
|
|
29 | context = pango_ft2_font_map_create_context ((PangoFT2FontMap *)fontmap); |
|
|
30 | } |
|
|
31 | |
|
|
32 | void |
|
|
33 | lowdelay (int fd, int val = 1) |
|
|
34 | CODE: |
|
|
35 | setsockopt (fd, IPPROTO_TCP, TCP_NODELAY, &val, sizeof (val)); |
10 | |
36 | |
11 | char * |
37 | char * |
12 | gl_version () |
38 | gl_version () |
13 | CODE: |
39 | CODE: |
14 | RETVAL = glGetString (GL_VERSION); |
40 | RETVAL = (char *)glGetString (GL_VERSION); |
15 | OUTPUT: |
41 | OUTPUT: |
16 | RETVAL |
42 | RETVAL |
17 | |
43 | |
18 | char * |
44 | char * |
19 | gl_extensions () |
45 | gl_extensions () |
20 | CODE: |
46 | CODE: |
21 | RETVAL = glGetString (GL_EXTENSIONS); |
47 | RETVAL = (char *)glGetString (GL_EXTENSIONS); |
22 | OUTPUT: |
48 | OUTPUT: |
23 | RETVAL |
49 | RETVAL |
24 | |
50 | |
|
|
51 | void |
|
|
52 | set_font (char *file) |
|
|
53 | CODE: |
|
|
54 | { |
|
|
55 | int count; |
|
|
56 | FcPattern *pattern = FcFreeTypeQuery ((const FcChar8 *)file, 0, 0, &count); |
|
|
57 | FcConfigAppFontAddFile (0, (const FcChar8 *)file); /* no idea wether this is required */ |
|
|
58 | PangoFontDescription *font = pango_fc_font_description_from_pattern (pattern, 0); |
|
|
59 | FcPatternDestroy (pattern); |
|
|
60 | pango_context_set_font_description (context, font); |
|
|
61 | } |
25 | |
62 | |
|
|
63 | void |
|
|
64 | font_render (SV *text_, int height = 10) |
|
|
65 | PPCODE: |
|
|
66 | { |
|
|
67 | STRLEN textlen; |
|
|
68 | char *text = SvPVutf8 (text_, textlen); |
|
|
69 | SV *retval; |
|
|
70 | int w, h; |
|
|
71 | FT_Bitmap bitmap; |
|
|
72 | PangoLayout *layout; |
|
|
73 | PangoFontDescription *font = pango_context_get_font_description (context); |
|
|
74 | pango_font_description_set_absolute_size (font, height * PANGO_SCALE); |
|
|
75 | |
|
|
76 | layout = pango_layout_new (context); |
|
|
77 | pango_layout_set_markup (layout, text, textlen); |
|
|
78 | pango_layout_get_pixel_size (layout, &w, &h); |
|
|
79 | |
|
|
80 | w = (w + 3) & ~3; |
|
|
81 | if (!w) w = 1; |
|
|
82 | if (!h) h = 1; |
|
|
83 | |
|
|
84 | retval = newSV (w * h); |
|
|
85 | SvPOK_only (retval); |
|
|
86 | SvCUR_set (retval, w * h); |
|
|
87 | |
|
|
88 | bitmap.rows = h; |
|
|
89 | bitmap.width = w; |
|
|
90 | bitmap.pitch = w; |
|
|
91 | bitmap.buffer = (unsigned char*)SvPVX (retval); |
|
|
92 | bitmap.num_grays = 256; |
|
|
93 | bitmap.pixel_mode = FT_PIXEL_MODE_GRAY; |
|
|
94 | |
|
|
95 | memset (bitmap.buffer, 0, w * h); |
|
|
96 | |
|
|
97 | pango_ft2_render_layout (&bitmap, layout, 0 * PANGO_SCALE, 0 * PANGO_SCALE); |
|
|
98 | g_object_unref (layout); |
|
|
99 | |
|
|
100 | EXTEND (SP, 3); |
|
|
101 | PUSHs (sv_2mortal (newSViv (w))); |
|
|
102 | PUSHs (sv_2mortal (newSViv (h))); |
|
|
103 | PUSHs (sv_2mortal (retval)); |
|
|
104 | } |
|
|
105 | |
|
|
106 | MODULE = Crossfire::Client PACKAGE = Crossfire::Client::Texture |
|
|
107 | |
|
|
108 | void |
|
|
109 | texture_quad (SV *self, double x0, double y0, double w, double h) |
|
|
110 | CODE: |
|
|
111 | { |
|
|
112 | //glBegin |
|
|
113 | } |