ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/Deliantra-Client/Client.xs
Revision: 1.39
Committed: Sat Apr 15 00:04:58 2006 UTC (18 years, 1 month ago) by root
Branch: MAIN
Changes since 1.38: +43 -6 lines
Log Message:
*** empty log message ***

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 root 1.25 #include <stdio.h>
7 root 1.5
8 root 1.2 #include <SDL.h>
9 root 1.23 #include <SDL_image.h>
10 root 1.3 #include <SDL_opengl.h>
11 root 1.5
12 root 1.30 #include <glib/gmacros.h>
13    
14 root 1.5 #include <pango/pango.h>
15 root 1.10 #include <pango/pangofc-fontmap.h>
16 root 1.5 #include <pango/pangoft2.h>
17    
18 root 1.10 #include <sys/types.h>
19     #include <sys/socket.h>
20     #include <netinet/in.h>
21     #include <netinet/tcp.h>
22    
23 root 1.28 #include <inttypes.h>
24    
25 root 1.29 #define FOW_DARKNESS 32
26    
27     #define MAP_EXTEND_X 32
28     #define MAP_EXTEND_Y 512
29    
30 root 1.5 static PangoContext *context;
31     static PangoFontMap *fontmap;
32 root 1.2
33 root 1.14 typedef struct cf_layout {
34     PangoLayout *pl;
35     int base_height;
36 root 1.15 } *CFClient__Layout;
37 root 1.14
38     static void
39 root 1.19 substitute_func (FcPattern *pattern, gpointer data)
40     {
41 root 1.20 FcPatternAddBool (pattern, FC_HINTING , 1);
42 root 1.35 FcPatternAddBool (pattern, FC_AUTOHINT, 0);
43 root 1.19 }
44    
45     static void
46 root 1.17 layout_update (CFClient__Layout self)
47     {
48 root 1.19 /* use a random scale factor to account for unknown descenders, 0.8 works
49     * reasonably well with bitstream vera
50     */
51 root 1.17 PangoFontDescription *font = pango_context_get_font_description (context);
52 root 1.19 pango_font_description_set_absolute_size (font, self->base_height * (PANGO_SCALE * 8 / 10));
53 root 1.17 }
54    
55     static void
56 root 1.15 layout_get_pixel_size (CFClient__Layout self, int *w, int *h)
57 root 1.14 {
58 root 1.19 layout_update (self);
59 root 1.16
60 root 1.14 pango_layout_get_pixel_size (self->pl, w, h);
61    
62     *w = (*w + 3) & ~3;
63     if (!*w) *w = 1;
64     if (!*h) *h = 1;
65     }
66    
67 root 1.28 typedef struct {
68 root 1.30 GLint name;
69     int w, h;
70     float s, t;
71 root 1.39 uint8_t r, g, b, a;
72 root 1.30 } mapface;
73    
74     typedef struct {
75 root 1.29 int16_t darkness;
76 root 1.28 uint16_t face[3];
77     } mapcell;
78    
79     typedef struct {
80 root 1.30 int32_t c0, c1;
81 root 1.28 mapcell *col;
82     } maprow;
83    
84     typedef struct map {
85     int x, y, w, h;
86 root 1.30 int vx, vy;
87 root 1.28 int faces;
88 root 1.30 mapface *face;
89 root 1.28
90     uint32_t rows;
91     maprow *row;
92     } *CFClient__Map;
93    
94 root 1.30 static char *
95     prepend (char *ptr, int sze, int inc)
96     {
97     char *p;
98    
99     New (0, p, sze + inc, char);
100     Zero (p, inc, char);
101     Move (ptr, p + inc, sze, char);
102     Safefree (ptr);
103    
104     return p;
105     }
106    
107     static char *
108     append (char *ptr, int sze, int inc)
109     {
110     Renew (ptr, sze + inc, char);
111     Zero (ptr + sze, inc, char);
112    
113     return ptr;
114     }
115    
116     #define Append(type,ptr,sze,inc) (ptr) = (type *)append ((char *)ptr, (sze) * sizeof (type), (inc) * sizeof (type))
117     #define Prepend(type,ptr,sze,inc) (ptr) = (type *)prepend ((char *)ptr, (sze) * sizeof (type), (inc) * sizeof (type))
118    
119     static void
120     map_clear (CFClient__Map self)
121     {
122     int r;
123    
124     for (r = 0; r < self->rows; r++)
125     Safefree (self->row[r].col);
126    
127     Safefree (self->row);
128    
129     self->x = 0;
130     self->y = 0;
131     self->vx = 0;
132     self->vy = 0;
133     self->row = 0;
134     self->rows = 0;
135     }
136    
137 root 1.29 static void
138     map_blank (CFClient__Map self, int x0, int y0, int w, int h)
139     {
140     int x, y;
141    
142     for (y = y0; y < y0 + h; y++)
143 root 1.30 if (y >= 0)
144     {
145     if (y >= self->rows)
146     break;
147    
148     maprow *row = self->row + y;
149    
150     for (x = x0; x < x0 + w; x++)
151     if (x >= row->c0)
152     {
153     if (x >= row->c1)
154     break;
155 root 1.29
156 root 1.31 row->col[x - row->c0].darkness = -1;
157 root 1.30 }
158     }
159 root 1.29 }
160    
161 root 1.15 MODULE = CFClient PACKAGE = CFClient
162 root 1.1
163 root 1.11 PROTOTYPES: ENABLE
164    
165 root 1.5 BOOT:
166     {
167     fontmap = pango_ft2_font_map_new ();
168 root 1.19 pango_ft2_font_map_set_default_substitute ((PangoFT2FontMap *)fontmap, substitute_func, 0, 0);
169 root 1.8 context = pango_ft2_font_map_create_context ((PangoFT2FontMap *)fontmap);
170 root 1.5 }
171    
172 root 1.10 void
173     lowdelay (int fd, int val = 1)
174     CODE:
175     setsockopt (fd, IPPROTO_TCP, TCP_NODELAY, &val, sizeof (val));
176    
177 root 1.3 char *
178 root 1.4 gl_version ()
179     CODE:
180 root 1.5 RETVAL = (char *)glGetString (GL_VERSION);
181 root 1.4 OUTPUT:
182     RETVAL
183    
184     char *
185 root 1.3 gl_extensions ()
186     CODE:
187 root 1.5 RETVAL = (char *)glGetString (GL_EXTENSIONS);
188 root 1.3 OUTPUT:
189     RETVAL
190    
191 root 1.5 void
192 root 1.13 add_font (char *file)
193     CODE:
194     FcConfigAppFontAddFile (0, (const FcChar8 *)file); /* no idea wether this is required */
195    
196     void
197 root 1.9 set_font (char *file)
198 root 1.8 CODE:
199     {
200 root 1.9 int count;
201     FcPattern *pattern = FcFreeTypeQuery ((const FcChar8 *)file, 0, 0, &count);
202 root 1.10 PangoFontDescription *font = pango_fc_font_description_from_pattern (pattern, 0);
203 root 1.9 FcPatternDestroy (pattern);
204 root 1.8 pango_context_set_font_description (context, font);
205     }
206    
207 root 1.23 void
208     load_image_inline (SV *image_)
209     ALIAS:
210     load_image_file = 1
211     PPCODE:
212     {
213     STRLEN image_len;
214     char *image = (char *)SvPVbyte (image_, image_len);
215     SDL_Surface *surface, *surface2;
216     SDL_PixelFormat fmt;
217     SDL_RWops *rw = ix
218     ? SDL_RWFromFile (image, "r")
219     : SDL_RWFromConstMem (image, image_len);
220    
221     if (!rw)
222     croak ("load_image: unable to open file");
223    
224     surface = IMG_Load_RW (rw, 1);
225     if (!surface)
226     croak ("load_image: unable to read file");
227    
228     fmt.palette = NULL;
229     fmt.BitsPerPixel = 32;
230     fmt.BytesPerPixel = 4;
231     fmt.Rmask = 0x000000ff;
232     fmt.Gmask = 0x0000ff00;
233     fmt.Bmask = 0x00ff0000;
234     fmt.Amask = 0xff000000;
235     fmt.Rloss = 0;
236     fmt.Gloss = 0;
237     fmt.Bloss = 0;
238     fmt.Aloss = 0;
239     fmt.Rshift = 0;
240     fmt.Gshift = 8;
241     fmt.Bshift = 16;
242     fmt.Ashift = 24;
243     fmt.colorkey = 0;
244     fmt.alpha = 0;
245    
246     surface2 = SDL_ConvertSurface (surface, &fmt, SDL_SWSURFACE);
247    
248 root 1.39 assert (surface2->pitch == surface2->w * 4);
249    
250 root 1.23 EXTEND (SP, 5);
251     PUSHs (sv_2mortal (newSViv (surface2->w)));
252     PUSHs (sv_2mortal (newSViv (surface2->h)));
253     SDL_LockSurface (surface2);
254     PUSHs (sv_2mortal (newSVpvn (surface2->pixels, surface2->h * surface2->pitch)));
255     SDL_UnlockSurface (surface2);
256 root 1.24 PUSHs (sv_2mortal (newSViv (surface->flags & (SDL_SRCCOLORKEY | SDL_SRCALPHA) ? GL_RGBA : GL_RGB)));
257 root 1.23 PUSHs (sv_2mortal (newSViv (GL_RGBA)));
258     PUSHs (sv_2mortal (newSViv (GL_UNSIGNED_INT_8_8_8_8_REV)));
259    
260     SDL_FreeSurface (surface);
261     SDL_FreeSurface (surface2);
262     }
263    
264 root 1.25 void
265 root 1.39 average (int x, int y, uint32_t *data)
266     PPCODE:
267     {
268     // only good for x * y < 32768
269     uint32_t r = 0, g = 0, b = 0, a = 0;
270    
271     x = y = x * y;
272    
273     assert (x < 32768);
274    
275     while (x--)
276     {
277     uint32_t p = *data++;
278    
279     r += (p ) & 255;
280     g += (p >> 8) & 255;
281     b += (p >> 16) & 255;
282     a += (p >> 24) & 255;
283     }
284    
285     EXTEND (SP, 4);
286     PUSHs (sv_2mortal (newSViv (r * 255 / y)));
287     PUSHs (sv_2mortal (newSViv (g * 255 / y)));
288     PUSHs (sv_2mortal (newSViv (b * 255 / y)));
289     PUSHs (sv_2mortal (newSViv (a * 255 / y)));
290     }
291    
292     void
293 root 1.25 fatal (char *message)
294     CODE:
295     #ifdef WIN32
296     MessageBox (0, message, "Crossfire+ Fatal Error", MB_OK | MB_ICONERROR | MB_SETFOREGROUND);
297     #else
298     fprintf (stderr, "%s\n", message);
299     #endif
300     exit (1);
301    
302 root 1.15 MODULE = CFClient PACKAGE = CFClient::Layout
303 root 1.14
304 root 1.15 CFClient::Layout
305 root 1.14 new (SV *class, int base_height = 10)
306     CODE:
307     New (0, RETVAL, 1, struct cf_layout);
308     RETVAL->base_height = base_height;
309     RETVAL->pl = pango_layout_new (context);
310     pango_layout_set_wrap (RETVAL->pl, PANGO_WRAP_WORD_CHAR);
311     OUTPUT:
312     RETVAL
313    
314     void
315 root 1.15 DESTROY (CFClient::Layout self)
316 root 1.14 CODE:
317     g_object_unref (self->pl);
318     Safefree (self);
319 root 1.13
320 root 1.8 void
321 root 1.35 set_text (CFClient::Layout self, SV *text_)
322     CODE:
323     {
324     STRLEN textlen;
325     char *text = SvPVutf8 (text_, textlen);
326    
327     pango_layout_set_text (self->pl, text, textlen);
328     }
329    
330     void
331 root 1.15 set_markup (CFClient::Layout self, SV *text_)
332 root 1.14 CODE:
333 root 1.5 {
334     STRLEN textlen;
335     char *text = SvPVutf8 (text_, textlen);
336 root 1.14
337     pango_layout_set_markup (self->pl, text, textlen);
338     }
339    
340     void
341 root 1.16 set_height (CFClient::Layout self, int base_height)
342     CODE:
343     self->base_height = base_height;
344    
345     void
346 root 1.15 set_width (CFClient::Layout self, int max_width = -1)
347 root 1.14 CODE:
348     pango_layout_set_width (self->pl, max_width < 0 ? max_width : max_width * PANGO_SCALE);
349    
350     void
351 root 1.15 size (CFClient::Layout self)
352 root 1.14 PPCODE:
353     {
354     int w, h;
355    
356 root 1.17 layout_update (self);
357 root 1.14 layout_get_pixel_size (self, &w, &h);
358    
359     EXTEND (SP, 2);
360     PUSHs (sv_2mortal (newSViv (w)));
361     PUSHs (sv_2mortal (newSViv (h)));
362     }
363    
364 root 1.17 int
365     xy_to_index (CFClient::Layout self, int x, int y)
366     CODE:
367     {
368     int index, trailing;
369    
370     layout_update (self);
371     pango_layout_xy_to_index (self->pl, x * PANGO_SCALE, y * PANGO_SCALE, &index, &trailing);
372    
373     RETVAL = index;
374     }
375     OUTPUT:
376     RETVAL
377    
378     void
379     cursor_pos (CFClient::Layout self, int index)
380     PPCODE:
381     {
382     PangoRectangle strong_pos;
383     layout_update (self);
384     pango_layout_get_cursor_pos (self->pl, index, &strong_pos, 0);
385 root 1.30
386 root 1.17 EXTEND (SP, 3);
387     PUSHs (sv_2mortal (newSViv (strong_pos.x / PANGO_SCALE)));
388     PUSHs (sv_2mortal (newSViv (strong_pos.y / PANGO_SCALE)));
389     PUSHs (sv_2mortal (newSViv (strong_pos.height / PANGO_SCALE)));
390     }
391    
392 root 1.14 void
393 root 1.15 render (CFClient::Layout self)
394 root 1.14 PPCODE:
395     {
396 root 1.5 SV *retval;
397     int w, h;
398     FT_Bitmap bitmap;
399    
400 root 1.17 layout_update (self);
401 root 1.14 layout_get_pixel_size (self, &w, &h);
402 root 1.5
403     retval = newSV (w * h);
404     SvPOK_only (retval);
405     SvCUR_set (retval, w * h);
406    
407     bitmap.rows = h;
408     bitmap.width = w;
409     bitmap.pitch = w;
410     bitmap.buffer = (unsigned char*)SvPVX (retval);
411     bitmap.num_grays = 256;
412     bitmap.pixel_mode = FT_PIXEL_MODE_GRAY;
413    
414     memset (bitmap.buffer, 0, w * h);
415    
416 root 1.14 pango_ft2_render_layout (&bitmap, self->pl, 0 * PANGO_SCALE, 0 * PANGO_SCALE);
417 root 1.1
418 root 1.5 EXTEND (SP, 3);
419     PUSHs (sv_2mortal (newSViv (w)));
420     PUSHs (sv_2mortal (newSViv (h)));
421     PUSHs (sv_2mortal (retval));
422     }
423 root 1.11
424 root 1.15 MODULE = CFClient PACKAGE = CFClient::Texture
425 root 1.11
426     void
427 root 1.37 draw_quad (SV *self, float x, float y, float w = 0, float h = 0)
428 root 1.12 PROTOTYPE: $$$;$$
429 root 1.11 CODE:
430     {
431 root 1.12 HV *hv = (HV *)SvRV (self);
432 root 1.37 float s = SvNV (*hv_fetch (hv, "s", 1, 1));
433     float t = SvNV (*hv_fetch (hv, "t", 1, 1));
434 root 1.12 int name = SvIV (*hv_fetch (hv, "name", 4, 1));
435 elmex 1.36 int wrap_mode = SvIV (*hv_fetch (hv, "wrap_mode", 9, 1));
436 root 1.12
437     if (items < 5)
438     {
439 root 1.18 w = SvNV (*hv_fetch (hv, "w", 1, 1));
440     h = SvNV (*hv_fetch (hv, "h", 1, 1));
441 root 1.12 }
442    
443     glBindTexture (GL_TEXTURE_2D, name);
444 elmex 1.36 if (wrap_mode) {
445     glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
446     glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
447     }
448 root 1.12 glBegin (GL_QUADS);
449 root 1.37 glTexCoord2f (0, 0); glVertex2f (x , y );
450     glTexCoord2f (0, t); glVertex2f (x , y + h);
451     glTexCoord2f (s, t); glVertex2f (x + w, y + h);
452     glTexCoord2f (s, 0); glVertex2f (x + w, y );
453 root 1.12 glEnd ();
454 root 1.11 }
455 root 1.28
456     MODULE = CFClient PACKAGE = CFClient::Map
457    
458     CFClient::Map
459     new (SV *class, int map_width, int map_height)
460     CODE:
461     New (0, RETVAL, 1, struct map);
462     RETVAL->x = 0;
463     RETVAL->y = 0;
464     RETVAL->w = map_width;
465     RETVAL->h = map_height;
466 root 1.30 RETVAL->vx = 0;
467     RETVAL->vy = 0;
468     RETVAL->faces = 8192;
469     Newz (0, RETVAL->face, RETVAL->faces, mapface);
470 root 1.28 RETVAL->rows = 0;
471     RETVAL->row = 0;
472     OUTPUT:
473     RETVAL
474    
475     void
476     DESTROY (CFClient::Map self)
477     CODE:
478     {
479 root 1.30 map_clear (self);
480 root 1.28 Safefree (self->face);
481 root 1.29 Safefree (self);
482     }
483    
484     void
485 root 1.30 clear (CFClient::Map self)
486     CODE:
487     map_clear (self);
488    
489     void
490 root 1.39 set_texture (CFClient::Map self, int face, int name, int w, int h, float s, float t, int r, int g, int b, int a)
491 root 1.29 CODE:
492     {
493 root 1.30 while (self->faces < face)
494 root 1.28 {
495 root 1.30 Append (mapface, self->face, self->faces, self->faces);
496 root 1.29 self->faces *= 2;
497     }
498 root 1.28
499 root 1.39 mapface *f = self->face + face;
500    
501     f->name = name;
502     f->w = w;
503     f->h = h;
504     f->s = s;
505     f->t = t;
506     f->r = r;
507     f->g = g;
508     f->b = b;
509     f->a = a;
510 root 1.29 }
511    
512     void
513     scroll (CFClient::Map self, int dx, int dy)
514     CODE:
515     {
516     if (dx > 0)
517     map_blank (self, self->x, self->y, dx - 1, self->h);
518     else if (dx < 0)
519     map_blank (self, self->x + self->w + dx + 1, self->y, 1 - dx, self->h);
520    
521     if (dy > 0)
522     map_blank (self, self->x, self->y, self->w, dy - 1);
523     else if (dy < 0)
524     map_blank (self, self->x, self->y + self->h + dy + 1, self->w, 1 - dy);
525    
526     self->x += dx;
527     self->y += dy;
528    
529     while (self->y < 0)
530     {
531 root 1.30 Prepend (maprow, self->row, self->rows, MAP_EXTEND_Y);
532 root 1.29
533     self->rows += MAP_EXTEND_Y;
534     self->y += MAP_EXTEND_Y;
535 root 1.28 }
536 root 1.29 }
537 root 1.28
538 root 1.29 void
539     map1a_update (CFClient::Map self, SV *data_)
540     CODE:
541     {
542 root 1.30 uint8_t *data = (uint8_t *)SvPVbyte_nolen (data_);
543     uint8_t *data_end = (uint8_t *)SvEND (data_);
544 root 1.29
545     while (data < data_end)
546     {
547     int flags = (data [0] << 8) + data [1]; data += 2;
548 root 1.30
549 root 1.29 int x = ((flags >> 10) & 63) + self->x;
550     int y = ((flags >> 4) & 63) + self->y;
551    
552     while (y >= self->rows)
553     {
554 root 1.30 Prepend (maprow, self->row, self->rows, MAP_EXTEND_Y);
555 root 1.29
556     self->rows += MAP_EXTEND_Y;
557     }
558    
559     maprow *row = self->row + y;
560    
561     if (!row->col)
562     {
563     Newz (0, row->col, MAP_EXTEND_X, mapcell);
564     row->c0 = self->x - MAP_EXTEND_X / 4;
565     row->c1 = row->c0 + MAP_EXTEND_X;
566     }
567    
568     if (row->c0 > x)
569     {
570     int extend = row->c0 - x + MAP_EXTEND_X;
571 root 1.30 Prepend (mapcell, row->col, row->c1 - row->c0, extend);
572 root 1.29 row->c0 -= extend;
573     }
574     else if (x >= row->c1)
575     {
576     int extend = x - row->c1 + MAP_EXTEND_X;
577 root 1.30 Append (mapcell, row->col, row->c1 - row->c0, extend);
578 root 1.29 row->c1 += extend;
579     }
580    
581 root 1.30 assert (y >= 0);
582     assert (y < self->rows);
583     assert (x >= row->c0);
584     assert (x < row->c1);
585 root 1.29 mapcell *cell = row->col + (x - row->c0);
586    
587     if (flags & 15)
588     {
589 root 1.30 if (cell->darkness < 0 && x < self->w && y < self->h)
590 root 1.29 {
591     cell->darkness = 0;
592     cell->face [0] = 0;
593     cell->face [1] = 0;
594     cell->face [2] = 0;
595     }
596    
597     cell->darkness = flags & 8 ? *data++ : 255;
598    
599     if (flags & 4)
600     {
601     cell->face [0] = (data [0] << 8) + data [1]; data += 2;
602     }
603    
604     if (flags & 2)
605     {
606     cell->face [1] = (data [0] << 8) + data [1]; data += 2;
607     }
608    
609     if (flags & 1)
610     {
611     cell->face [2] = (data [0] << 8) + data [1]; data += 2;
612     }
613     }
614     else
615 root 1.31 cell->darkness = -1;
616 root 1.29 }
617 root 1.28 }
618    
619 root 1.30 void
620 root 1.38 draw (CFClient::Map self, int shift_x, int shift_y, int x0, int y0, int sw, int sh)
621 root 1.32 PPCODE:
622 root 1.30 {
623 root 1.32 int sw4 = (sw + 3) & ~3;
624     SV *darkness_sv = sv_2mortal (newSV (sw4 * sh));
625 root 1.35 uint8_t *darkness = (uint8_t *)SvPVX (darkness_sv);
626 root 1.32
627     SvPOK_only (darkness_sv);
628     SvCUR_set (darkness_sv, sw4 * sh);
629    
630 root 1.38 int vx = self->x + (self->w - sw) / 2 - shift_x;
631     int vy = self->y + (self->h - sh) / 2 - shift_y;
632    
633     if (0)
634     {
635     int vx = self->vx = self->w >= sw
636     ? self->x + (self->w - sw) / 2
637     : MIN (self->x, MAX (self->x + self->w - sw + 1, self->vx));
638    
639     int vy = self->vy = self->h >= sh
640     ? self->y + (self->h - sh) / 2
641     : MIN (self->y, MAX (self->y + self->h - sh + 1, self->vy));
642     }
643 root 1.30
644     glColor4ub (255, 255, 255, 255);
645    
646     glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
647     glEnable (GL_BLEND);
648     glEnable (GL_TEXTURE_2D);
649     glTexEnvi (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
650    
651     int x, y, z;
652    
653     int last_name = 0;
654    
655     glBegin (GL_QUADS);
656    
657     for (z = 0; z < 3; z++)
658     for (y = 0; y < sh; y++)
659     if (0 <= y + vy && y + vy < self->rows)
660     {
661     maprow *row = self->row + (y + vy);
662    
663     for (x = 0; x < sw; x++)
664     if (row->c0 <= x + vx && x + vx < row->c1)
665     {
666     mapcell *cell = row->col + (x + vx - row->c0);
667 root 1.32
668     darkness[y * sw4 + x] = cell->darkness < 0
669 root 1.33 ? 255 - FOW_DARKNESS
670 root 1.32 : 255 - cell->darkness;
671    
672 root 1.30 uint16_t face = cell->face [z];
673    
674     if (face)
675     {
676     mapface tex = self->face [face];
677    
678     int px = (x + 1) * 32 - tex.w;
679     int py = (y + 1) * 32 - tex.h;
680    
681     if (last_name != tex.name)
682     {
683     glEnd ();
684     last_name = tex.name;
685     glBindTexture (GL_TEXTURE_2D, last_name);
686     glBegin (GL_QUADS);
687     }
688    
689     glTexCoord2f (0 , 0 ); glVertex2f (px , py );
690     glTexCoord2f (0 , tex.t); glVertex2f (px , py + tex.h);
691     glTexCoord2f (tex.s, tex.t); glVertex2f (px + tex.w, py + tex.h);
692     glTexCoord2f (tex.s, 0 ); glVertex2f (px + tex.w, py );
693     }
694     }
695     }
696    
697     glEnd ();
698 root 1.32
699 root 1.34 glDisable (GL_TEXTURE_2D);
700     glDisable (GL_BLEND);
701    
702 root 1.32 EXTEND (SP, 3);
703     PUSHs (sv_2mortal (newSViv (sw4)));
704     PUSHs (sv_2mortal (newSViv (sh)));
705     PUSHs (darkness_sv);
706 root 1.30 }
707