ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/Deliantra-Client/Client.xs
Revision: 1.6
Committed: Sun Apr 9 00:06:51 2006 UTC (18 years, 1 month ago) by root
Branch: MAIN
Changes since 1.5: +2 -1 lines
Log Message:
use pango for rendering, instead of broken sdl_ttf

File Contents

# User Rev Content
1 root 1.1 #include "EXTERN.h"
2     #include "perl.h"
3     #include "XSUB.h"
4    
5 root 1.5 #include <string.h>
6    
7 root 1.2 #include <SDL.h>
8 root 1.3 #include <SDL_opengl.h>
9 root 1.5
10     #include <pango/pango.h>
11     #include <pango/pangoft2.h>
12    
13     static PangoContext *context;
14     static PangoFontMap *fontmap;
15 root 1.2
16 root 1.1 MODULE = Crossfire::Client PACKAGE = Crossfire::Client
17    
18 root 1.5 BOOT:
19     {
20     fontmap = pango_ft2_font_map_new ();
21     context = pango_context_new ();
22     pango_context_set_font_map (context, fontmap);
23     }
24    
25 root 1.3 char *
26 root 1.4 gl_version ()
27     CODE:
28 root 1.5 RETVAL = (char *)glGetString (GL_VERSION);
29 root 1.4 OUTPUT:
30     RETVAL
31    
32     char *
33 root 1.3 gl_extensions ()
34     CODE:
35 root 1.5 RETVAL = (char *)glGetString (GL_EXTENSIONS);
36 root 1.3 OUTPUT:
37     RETVAL
38    
39 root 1.5 void
40     font_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);
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 root 1.6 if (!w) w = 1;
58     if (!h) h = 1;
59 root 1.5
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 root 1.1
76 root 1.5 EXTEND (SP, 3);
77     PUSHs (sv_2mortal (newSViv (w)));
78     PUSHs (sv_2mortal (newSViv (h)));
79     PUSHs (sv_2mortal (retval));
80     }