ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/Deliantra-Client/Client.xs
(Generate patch)

Comparing deliantra/Deliantra-Client/Client.xs (file contents):
Revision 1.4 by root, Sat Apr 8 14:04:14 2006 UTC vs.
Revision 1.5 by root, Sun Apr 9 00:06:09 2006 UTC

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/pangoft2.h>
12
13static PangoContext *context;
14static PangoFontMap *fontmap;
8 15
9MODULE = Crossfire::Client PACKAGE = Crossfire::Client 16MODULE = Crossfire::Client PACKAGE = Crossfire::Client
17
18BOOT:
19{
20 fontmap = pango_ft2_font_map_new ();
21 context = pango_context_new ();
22 pango_context_set_font_map (context, fontmap);
23}
10 24
11char * 25char *
12gl_version () 26gl_version ()
13 CODE: 27 CODE:
14 RETVAL = glGetString (GL_VERSION); 28 RETVAL = (char *)glGetString (GL_VERSION);
15 OUTPUT: 29 OUTPUT:
16 RETVAL 30 RETVAL
17 31
18char * 32char *
19gl_extensions () 33gl_extensions ()
20 CODE: 34 CODE:
21 RETVAL = glGetString (GL_EXTENSIONS); 35 RETVAL = (char *)glGetString (GL_EXTENSIONS);
22 OUTPUT: 36 OUTPUT:
23 RETVAL 37 RETVAL
24 38
39void
40font_render (SV *text_, int height)
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, 40 * PANGO_SCALE);
25 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 (h == 0) h = 1;
58
59 retval = newSV (w * h);
60 SvPOK_only (retval);
61 SvCUR_set (retval, w * h);
62
63 bitmap.rows = h;
64 bitmap.width = w;
65 bitmap.pitch = w;
66 bitmap.buffer = (unsigned char*)SvPVX (retval);
67 bitmap.num_grays = 256;
68 bitmap.pixel_mode = FT_PIXEL_MODE_GRAY;
69
70 memset (bitmap.buffer, 0, w * h);
71
72 pango_ft2_render_layout (&bitmap, layout, 0 * PANGO_SCALE, 0 * PANGO_SCALE);
73 g_object_unref (layout);
74
75 EXTEND (SP, 3);
76 PUSHs (sv_2mortal (newSViv (w)));
77 PUSHs (sv_2mortal (newSViv (h)));
78 PUSHs (sv_2mortal (retval));
79}

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines