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.17 by root, Tue Apr 11 17:02:35 2006 UTC vs.
Revision 1.26 by root, Wed Apr 12 23:15:38 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> 5#include <string.h>
6#include <stdio.h>
6 7
7#include <SDL.h> 8#include <SDL.h>
9#include <SDL_image.h>
8#include <SDL_opengl.h> 10#include <SDL_opengl.h>
9 11
10#include <pango/pango.h> 12#include <pango/pango.h>
11#include <pango/pangofc-fontmap.h> 13#include <pango/pangofc-fontmap.h>
12#include <pango/pangoft2.h> 14#include <pango/pangoft2.h>
23 PangoLayout *pl; 25 PangoLayout *pl;
24 int base_height; 26 int base_height;
25} *CFClient__Layout; 27} *CFClient__Layout;
26 28
27static void 29static void
30substitute_func (FcPattern *pattern, gpointer data)
31{
32 FcPatternAddBool (pattern, FC_HINTING , 1);
33 FcPatternAddBool (pattern, FC_AUTOHINT, 1);
34}
35
36static void
28layout_update (CFClient__Layout self) 37layout_update (CFClient__Layout self)
29{ 38{
39 /* use a random scale factor to account for unknown descenders, 0.8 works
40 * reasonably well with bitstream vera
41 */
30 PangoFontDescription *font = pango_context_get_font_description (context); 42 PangoFontDescription *font = pango_context_get_font_description (context);
31 pango_font_description_set_absolute_size (font, self->base_height * PANGO_SCALE); 43 pango_font_description_set_absolute_size (font, self->base_height * (PANGO_SCALE * 8 / 10));
32} 44}
33 45
34static void 46static void
35layout_get_pixel_size (CFClient__Layout self, int *w, int *h) 47layout_get_pixel_size (CFClient__Layout self, int *w, int *h)
36{ 48{
37 PangoFontDescription *font = pango_context_get_font_description (context); 49 layout_update (self);
38 pango_font_description_set_absolute_size (font, self->base_height * PANGO_SCALE);
39 50
40 pango_layout_get_pixel_size (self->pl, w, h); 51 pango_layout_get_pixel_size (self->pl, w, h);
41 52
42 *w = (*w + 3) & ~3; 53 *w = (*w + 3) & ~3;
43 if (!*w) *w = 1; 54 if (!*w) *w = 1;
49PROTOTYPES: ENABLE 60PROTOTYPES: ENABLE
50 61
51BOOT: 62BOOT:
52{ 63{
53 fontmap = pango_ft2_font_map_new (); 64 fontmap = pango_ft2_font_map_new ();
65 pango_ft2_font_map_set_default_substitute ((PangoFT2FontMap *)fontmap, substitute_func, 0, 0);
54 context = pango_ft2_font_map_create_context ((PangoFT2FontMap *)fontmap); 66 context = pango_ft2_font_map_create_context ((PangoFT2FontMap *)fontmap);
55} 67}
56 68
57void 69void
58lowdelay (int fd, int val = 1) 70lowdelay (int fd, int val = 1)
70gl_extensions () 82gl_extensions ()
71 CODE: 83 CODE:
72 RETVAL = (char *)glGetString (GL_EXTENSIONS); 84 RETVAL = (char *)glGetString (GL_EXTENSIONS);
73 OUTPUT: 85 OUTPUT:
74 RETVAL 86 RETVAL
87
88void
89glConvolutionParameteri (U32 target, U32 name, I32 value)
90
91void
92glConvolutionFilter2D (U32 target, U32 internalformat, I32 width, I32 height, U32 format, U32 type, char *image)
75 93
76void 94void
77add_font (char *file) 95add_font (char *file)
78 CODE: 96 CODE:
79 FcConfigAppFontAddFile (0, (const FcChar8 *)file); /* no idea wether this is required */ 97 FcConfigAppFontAddFile (0, (const FcChar8 *)file); /* no idea wether this is required */
86 FcPattern *pattern = FcFreeTypeQuery ((const FcChar8 *)file, 0, 0, &count); 104 FcPattern *pattern = FcFreeTypeQuery ((const FcChar8 *)file, 0, 0, &count);
87 PangoFontDescription *font = pango_fc_font_description_from_pattern (pattern, 0); 105 PangoFontDescription *font = pango_fc_font_description_from_pattern (pattern, 0);
88 FcPatternDestroy (pattern); 106 FcPatternDestroy (pattern);
89 pango_context_set_font_description (context, font); 107 pango_context_set_font_description (context, font);
90} 108}
109
110void
111load_image_inline (SV *image_)
112 ALIAS:
113 load_image_file = 1
114 PPCODE:
115{
116 STRLEN image_len;
117 char *image = (char *)SvPVbyte (image_, image_len);
118 SDL_Surface *surface, *surface2;
119 SDL_PixelFormat fmt;
120 SDL_RWops *rw = ix
121 ? SDL_RWFromFile (image, "r")
122 : SDL_RWFromConstMem (image, image_len);
123
124 if (!rw)
125 croak ("load_image: unable to open file");
126
127 surface = IMG_Load_RW (rw, 1);
128 if (!surface)
129 croak ("load_image: unable to read file");
130
131 fmt.palette = NULL;
132 fmt.BitsPerPixel = 32;
133 fmt.BytesPerPixel = 4;
134 fmt.Rmask = 0x000000ff;
135 fmt.Gmask = 0x0000ff00;
136 fmt.Bmask = 0x00ff0000;
137 fmt.Amask = 0xff000000;
138 fmt.Rloss = 0;
139 fmt.Gloss = 0;
140 fmt.Bloss = 0;
141 fmt.Aloss = 0;
142 fmt.Rshift = 0;
143 fmt.Gshift = 8;
144 fmt.Bshift = 16;
145 fmt.Ashift = 24;
146 fmt.colorkey = 0;
147 fmt.alpha = 0;
148
149 surface2 = SDL_ConvertSurface (surface, &fmt, SDL_SWSURFACE);
150
151 EXTEND (SP, 5);
152 PUSHs (sv_2mortal (newSViv (surface2->w)));
153 PUSHs (sv_2mortal (newSViv (surface2->h)));
154 SDL_LockSurface (surface2);
155 PUSHs (sv_2mortal (newSVpvn (surface2->pixels, surface2->h * surface2->pitch)));
156 SDL_UnlockSurface (surface2);
157 PUSHs (sv_2mortal (newSViv (surface->flags & (SDL_SRCCOLORKEY | SDL_SRCALPHA) ? GL_RGBA : GL_RGB)));
158 PUSHs (sv_2mortal (newSViv (GL_RGBA)));
159 PUSHs (sv_2mortal (newSViv (GL_UNSIGNED_INT_8_8_8_8_REV)));
160
161 SDL_FreeSurface (surface);
162 SDL_FreeSurface (surface2);
163}
164
165void
166fatal (char *message)
167 CODE:
168#ifdef WIN32
169 MessageBox (0, message, "Crossfire+ Fatal Error", MB_OK | MB_ICONERROR | MB_SETFOREGROUND);
170#else
171 fprintf (stderr, "%s\n", message);
172#endif
173 exit (1);
91 174
92MODULE = CFClient PACKAGE = CFClient::Layout 175MODULE = CFClient PACKAGE = CFClient::Layout
93 176
94CFClient::Layout 177CFClient::Layout
95new (SV *class, int base_height = 10) 178new (SV *class, int base_height = 10)
212 double t = SvNV (*hv_fetch (hv, "t", 1, 1)); 295 double t = SvNV (*hv_fetch (hv, "t", 1, 1));
213 int name = SvIV (*hv_fetch (hv, "name", 4, 1)); 296 int name = SvIV (*hv_fetch (hv, "name", 4, 1));
214 297
215 if (items < 5) 298 if (items < 5)
216 { 299 {
217 w = SvNV (*hv_fetch (hv, "width", 5, 1)); 300 w = SvNV (*hv_fetch (hv, "w", 1, 1));
218 h = SvNV (*hv_fetch (hv, "height", 6, 1)); 301 h = SvNV (*hv_fetch (hv, "h", 1, 1));
219 } 302 }
220 303
221 glBindTexture (GL_TEXTURE_2D, name); 304 glBindTexture (GL_TEXTURE_2D, name);
222 glBegin (GL_QUADS); 305 glBegin (GL_QUADS);
223 glTexCoord2d (0, 0); glVertex2d (x , y ); 306 glTexCoord2d (0, 0); glVertex2d (x , y );

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines