--- deliantra/Deliantra-Client/Client.xs 2006/05/17 15:18:57 1.84 +++ deliantra/Deliantra-Client/Client.xs 2006/07/05 03:01:01 1.128 @@ -12,6 +12,7 @@ #include #include #include +#include #include #include @@ -19,12 +20,12 @@ #include #include +#define PANGO_ENABLE_BACKEND +#define G_DISABLE_CAST_CHECKS + #include #include -#include -#include -#include #ifndef _WIN32 # include @@ -43,6 +44,8 @@ #include "glext.h" +#define OBJ_STR "\xef\xbf\xbc" /* U+FFFC, objetc replacement character */ + #define FOW_DARKNESS 32 #define MAP_EXTEND_X 32 @@ -50,47 +53,77 @@ #define MIN_FONT_HEIGHT 10 -#define GL_CALL(type,func,args) \ - { \ - static int init_; \ - static type fptr_; \ - \ - if (!init_) \ - { \ - init_ = 1; \ - fptr_ = (type)SDL_GL_GetProcAddress (# func); \ - } \ - \ - if (fptr_) \ - fptr_ args; \ - } +#if 0 +# define PARACHUTE SDL_INIT_NOPARACHUTE +#else +# define PARACHUTE 0 +#endif + +static struct +{ +#define GL_FUNC(ptr,name) ptr name; +#include "glfunc.h" +#undef GL_FUNC +} gl; + +static void gl_BlendFuncSeparate (GLenum sa, GLenum da, GLenum saa, GLenum daa) +{ + if (gl.BlendFuncSeparate) + gl.BlendFuncSeparate (sa, da, saa, daa); + else if (gl.BlendFuncSeparateEXT) + gl.BlendFuncSeparateEXT (sa, da, saa, daa); + else + glBlendFunc (sa, da); +} + +#include "texcache.c" + +#include "pango-font.c" +#include "pango-fontmap.c" +#include "pango-render.c" typedef Mix_Chunk *CFClient__MixChunk; typedef Mix_Music *CFClient__MixMusic; typedef PangoFontDescription *CFClient__Font; +static int +shape_attr_p (PangoLayoutRun *run) +{ + GSList *attrs = run->item->analysis.extra_attrs; + + while (attrs) + { + PangoAttribute *attr = attrs->data; + + if (attr->klass->type == PANGO_ATTR_SHAPE) + return 1; + + attrs = attrs->next; + } + + return 0; +} + typedef struct cf_layout { - PangoLayout *pl; // either derived from a cairo or ft2 context - int rgba; // wether we use rgba (cairo) or grayscale (ft2) + PangoLayout *pl; float r, g, b, a; // default color for rgba mode int base_height; CFClient__Font font; } *CFClient__Layout; static CFClient__Font default_font; -static PangoContext *ft2_context, *cairo_context; -static PangoFontMap *ft2_fontmap, *cairo_fontmap; +static PangoContext *opengl_context; +static PangoFontMap *opengl_fontmap; static void substitute_func (FcPattern *pattern, gpointer data) { - FcPatternAddBool (pattern, FC_HINTING , 1); -#ifdef _WIN32 - FcPatternAddBool (pattern, FC_AUTOHINT, 1); -#else - FcPatternAddBool (pattern, FC_AUTOHINT, 0); + FcPatternAddBool (pattern, FC_HINTING, 1); +#ifdef FC_HINT_STYLE + FcPatternAddBool (pattern, FC_HINT_STYLE, FC_HINT_FULL); #endif + FcPatternAddBool (pattern, FC_AUTOHINT, 0); } static void @@ -298,6 +331,23 @@ SDL_PushEvent ((SDL_Event *)&ev); } +static unsigned int +minpot (unsigned int n) +{ + if (!n) + return 0; + + --n; + + n |= n >> 1; + n |= n >> 2; + n |= n >> 4; + n |= n >> 8; + n |= n >> 16; + + return n + 1; +} + MODULE = CFClient PACKAGE = CFClient PROTOTYPES: ENABLE @@ -415,21 +465,21 @@ newCONSTSUB (stash, (char *)civ->name, newSViv (civ->iv)); } +NV floor (NV x) + +NV ceil (NV x) + void pango_init () CODE: { - // delayed, so it can pick up new fonts added by AddFontResourceEx - ft2_fontmap = pango_ft2_font_map_new (); - pango_ft2_font_map_set_default_substitute ((PangoFT2FontMap *)ft2_fontmap, substitute_func, 0, 0); - ft2_context = pango_ft2_font_map_create_context ((PangoFT2FontMap *)ft2_fontmap); - - cairo_fontmap = pango_cairo_font_map_get_default (); - cairo_context = pango_cairo_font_map_create_context ((PangoCairoFontMap *)cairo_fontmap); + opengl_fontmap = pango_opengl_font_map_new (); + pango_opengl_font_map_set_default_substitute ((PangoOpenGLFontMap *)opengl_fontmap, substitute_func, 0, 0); + opengl_context = pango_opengl_font_map_create_context ((PangoOpenGLFontMap *)opengl_fontmap); } int -SDL_Init (U32 flags = SDL_INIT_VIDEO | SDL_INIT_AUDIO) +SDL_Init (U32 flags = SDL_INIT_VIDEO | SDL_INIT_AUDIO | PARACHUTE) void SDL_Quit () @@ -445,14 +495,15 @@ SDL_GL_SetAttribute (SDL_GL_BLUE_SIZE, 5); SDL_GL_SetAttribute (SDL_GL_ALPHA_SIZE, 1); + SDL_GL_SetAttribute (SDL_GL_BUFFER_SIZE, 15); + SDL_GL_SetAttribute (SDL_GL_DEPTH_SIZE, 0); + SDL_GL_SetAttribute (SDL_GL_ACCUM_RED_SIZE, 0); SDL_GL_SetAttribute (SDL_GL_ACCUM_GREEN_SIZE, 0); SDL_GL_SetAttribute (SDL_GL_ACCUM_BLUE_SIZE, 0); SDL_GL_SetAttribute (SDL_GL_ACCUM_ALPHA_SIZE, 0); SDL_GL_SetAttribute (SDL_GL_DOUBLEBUFFER, 1); - SDL_GL_SetAttribute (SDL_GL_BUFFER_SIZE, 15); - SDL_GL_SetAttribute (SDL_GL_DEPTH_SIZE, 0); SDL_EnableUNICODE (1); SDL_EnableKeyRepeat (SDL_DEFAULT_REPEAT_DELAY, SDL_DEFAULT_REPEAT_INTERVAL); @@ -471,19 +522,31 @@ } } +char * +SDL_GetError () + int SDL_SetVideoMode (int w, int h, int fullscreen) CODE: RETVAL = !!SDL_SetVideoMode ( w, h, 0, SDL_OPENGL | (fullscreen ? SDL_FULLSCREEN : 0) ); - SDL_WM_SetCaption ("Crossfire+ Client " VERSION, "Crossfire+"); + if (RETVAL) + { + SDL_WM_SetCaption ("Crossfire+ Client " VERSION, "Crossfire+"); +# define GL_FUNC(ptr,name) gl.name = (ptr)SDL_GL_GetProcAddress ("gl" # name); +# include "glfunc.h" +# undef GL_FUNC + } OUTPUT: RETVAL void SDL_GL_SwapBuffers () +char * +SDL_GetKeyName (int sym) + void SDL_PollEvent () PPCODE: @@ -511,6 +574,8 @@ break; case SDL_MOUSEMOTION: + hv_store (hv, "mod", 3, newSViv (SDL_GetModState ()), 0); + hv_store (hv, "state", 5, newSViv (ev.motion.state), 0); hv_store (hv, "x", 1, newSViv (ev.motion.x), 0); hv_store (hv, "y", 1, newSViv (ev.motion.y), 0); @@ -520,6 +585,8 @@ case SDL_MOUSEBUTTONDOWN: case SDL_MOUSEBUTTONUP: + hv_store (hv, "mod", 3, newSViv (SDL_GetModState ()), 0); + hv_store (hv, "button", 6, newSViv (ev.button.button), 0); hv_store (hv, "state", 5, newSViv (ev.button.state), 0); hv_store (hv, "x", 1, newSViv (ev.button.x), 0); @@ -556,28 +623,10 @@ setsockopt (fd, IPPROTO_TCP, TCP_NODELAY, &val, sizeof (val)); #endif -char * -gl_version () - CODE: - RETVAL = (char *)glGetString (GL_VERSION); - OUTPUT: - RETVAL - -char * -gl_extensions () - CODE: - RETVAL = (char *)glGetString (GL_EXTENSIONS); - OUTPUT: - RETVAL - void add_font (char *file) CODE: FcConfigAppFontAddFile (0, (const FcChar8 *)file); /* no idea wether this is required */ -#ifdef _WIN32 - // cairo... sigh... requires win2000 - AddFontResourceEx (file, FR_PRIVATE, 0); -#endif void load_image_inline (SV *image_) @@ -671,21 +720,24 @@ void error (char *message) CODE: -#ifdef _WIN32 - MessageBox (0, message, "Crossfire+ Error", MB_OK | MB_ICONERROR | MB_SETFOREGROUND); -#else fprintf (stderr, "ERROR: %s\n", message); +#ifdef _WIN32 + MessageBox (0, message, "Crossfire+ Error", MB_OK | MB_ICONERROR); #endif void fatal (char *message) CODE: -#ifdef _WIN32 - MessageBox (0, message, "Crossfire+ Fatal Error", MB_OK | MB_ICONERROR | MB_SETFOREGROUND); -#else fprintf (stderr, "FATAL: %s\n", message); +#ifdef _WIN32 + MessageBox (0, message, "Crossfire+ Fatal Error", MB_OK | MB_ICONERROR); #endif - exit (1); + _exit (1); + +void +_exit (int retval) + CODE: + _exit (retval); MODULE = CFClient PACKAGE = CFClient::Font @@ -713,13 +765,17 @@ MODULE = CFClient PACKAGE = CFClient::Layout +void +clear_font_cache () + CODE: + tc_clear (); + CFClient::Layout -new (SV *class, int rgba = 0) +new (SV *class) CODE: New (0, RETVAL, 1, struct cf_layout); - RETVAL->pl = pango_layout_new (rgba ? cairo_context : ft2_context); - RETVAL->rgba = rgba; + RETVAL->pl = pango_layout_new (opengl_context); RETVAL->r = 1.; RETVAL->g = 1.; RETVAL->b = 1.; @@ -738,13 +794,6 @@ g_object_unref (self->pl); Safefree (self); -int -is_rgba (CFClient::Layout self) - CODE: - RETVAL = self->rgba; - OUTPUT: - RETVAL - void set_text (CFClient::Layout self, SV *text_) CODE: @@ -765,11 +814,95 @@ pango_layout_set_markup (self->pl, text, textlen); } +void +set_shapes (CFClient::Layout self, ...) + CODE: +{ + PangoAttrList *attrs = 0; + const char *text = pango_layout_get_text (self->pl); + const char *pos = text; + int arg = 4; + + while (arg < items && (pos = strstr (pos, OBJ_STR))) + { + PangoRectangle inkrect, rect; + PangoAttribute *attr; + + int x = SvIV (ST (arg - 3)); + int y = SvIV (ST (arg - 2)); + int w = SvIV (ST (arg - 1)); + int h = SvIV (ST (arg )); + + inkrect.x = 0; + inkrect.y = 0; + inkrect.width = 0; + inkrect.height = 0; + + rect.x = x * PANGO_SCALE; + rect.y = y * PANGO_SCALE; + rect.width = w * PANGO_SCALE; + rect.height = h * PANGO_SCALE; + + if (!attrs) + attrs = pango_layout_get_attributes (self->pl); + + attr = pango_attr_shape_new (&inkrect, &rect); + attr->start_index = pos - text; + attr->end_index = attr->start_index + sizeof (OBJ_STR) - 1; + pango_attr_list_insert (attrs, attr); + + arg += 4; + pos += sizeof (OBJ_STR) - 1; + } + + if (attrs) + pango_layout_set_attributes (self->pl, attrs); +} + +void +get_shapes (CFClient::Layout self) + PPCODE: +{ + PangoLayoutIter *iter = pango_layout_get_iter (self->pl); + + do + { + PangoLayoutRun *run = pango_layout_iter_get_run (iter); + + if (run && shape_attr_p (run)) + { + PangoRectangle extents; + pango_layout_iter_get_run_extents (iter, 0, &extents); + + PUSHs (sv_2mortal (newSViv (PANGO_PIXELS (extents.x)))); + PUSHs (sv_2mortal (newSViv (PANGO_PIXELS (extents.y)))); + } + } + while (pango_layout_iter_next_run (iter)); + + pango_layout_iter_free (iter); +} + +int +has_wrapped (CFClient::Layout self) + CODE: +{ + int lines = 1; + const char *text = pango_layout_get_text (self->pl); + + while (*text) + lines += *text++ == '\n'; + + RETVAL = lines < pango_layout_get_line_count (self->pl); +} + OUTPUT: + RETVAL + SV * get_text (CFClient::Layout self) CODE: RETVAL = newSVpv (pango_layout_get_text (self->pl), 0); - SvUTF8_on (RETVAL); + sv_utf8_decode (RETVAL); OUTPUT: RETVAL @@ -843,6 +976,18 @@ } int +descent (CFClient::Layout self) + CODE: +{ + PangoRectangle rect; + PangoLayoutLine *line = pango_layout_get_line (self->pl, 0); + pango_layout_line_get_pixel_extents (line, 0, &rect); + RETVAL = PANGO_DESCENT (rect); +} + OUTPUT: + RETVAL + +int xy_to_index (CFClient::Layout self, int x, int y) CODE: { @@ -867,88 +1012,55 @@ } void -render (CFClient::Layout self) +render (CFClient::Layout self, float x, float y) PPCODE: -{ - SV *retval; - int w, h; - - layout_get_pixel_size (self, &w, &h); - - if (self->rgba) - { - cairo_surface_t *surface; - cairo_t *cairo; - - retval = newSV (w * h * 4); - SvPOK_only (retval); - SvCUR_set (retval, w * h * 4); - - memset (SvPVX (retval), 0, w * h * 4); - - surface = cairo_image_surface_create_for_data ( - (void*)SvPVX (retval), CAIRO_FORMAT_ARGB32, w, h, w * 4); - cairo = cairo_create (surface); - cairo_set_source_rgba (cairo, self->r, self->g, self->b, self->a); - - pango_cairo_show_layout (cairo, self->pl); - - cairo_destroy (cairo); - cairo_surface_destroy (surface); + pango_opengl_render_layout_subpixel ( + self->pl, + x * PANGO_SCALE, y * PANGO_SCALE, + self->r, self->g, self->b, self->a + ); - // what a mess, and its premultiplied, too :( - { - uint32_t *p = (uint32_t *)SvPVX (retval); - uint32_t *e = p + w * h; +MODULE = CFClient PACKAGE = CFClient::Texture - while (p < e) - { - uint32_t rgba = *p; - rgba = (rgba >> 24) | (rgba << 8); - rgba = SDL_SwapBE32 (rgba); - *p++ = rgba; - } - } +void +pad2pot (SV *data_, SV *w_, SV *h_) + CODE: +{ + int ow = SvIV (w_); + int oh = SvIV (h_); - EXTEND (SP, 5); - PUSHs (sv_2mortal (newSViv (w))); - PUSHs (sv_2mortal (newSViv (h))); - PUSHs (sv_2mortal (retval)); - PUSHs (sv_2mortal (newSViv (GL_RGBA))); - PUSHs (sv_2mortal (newSViv (GL_RGBA))); - } - else + if (ow && oh) { - FT_Bitmap bitmap; + int nw = minpot (ow); + int nh = minpot (oh); - retval = newSV (w * h); - SvPOK_only (retval); - SvCUR_set (retval, w * h); - - bitmap.rows = h; - bitmap.width = w; - bitmap.pitch = w; - bitmap.buffer = (unsigned char*)SvPVX (retval); - bitmap.num_grays = 256; - bitmap.pixel_mode = FT_PIXEL_MODE_GRAY; + if (nw != ow || nh != oh) + { + if (SvOK (data_)) + { + STRLEN datalen; + char *data = SvPVbyte (data_, datalen); + int bpp = datalen / (ow * oh); + SV *result_ = sv_2mortal (newSV (nw * nh * bpp)); + + SvPOK_only (result_); + SvCUR_set (result_, nw * nh * bpp); + + memset (SvPVX (result_), 0, nw * nh * bpp); + while (oh--) + memcpy (SvPVX (result_) + oh * nw * bpp, data + oh * ow * bpp, ow * bpp); - memset (bitmap.buffer, 0, w * h); - - pango_ft2_render_layout (&bitmap, self->pl, 0 * PANGO_SCALE, 0 * PANGO_SCALE); + sv_setsv (data_, result_); + } - EXTEND (SP, 5); - PUSHs (sv_2mortal (newSViv (w))); - PUSHs (sv_2mortal (newSViv (h))); - PUSHs (sv_2mortal (retval)); - PUSHs (sv_2mortal (newSViv (GL_ALPHA))); - PUSHs (sv_2mortal (newSViv (GL_ALPHA))); + sv_setiv (w_, nw); + sv_setiv (h_, nh); + } } } -MODULE = CFClient PACKAGE = CFClient::Texture - void -draw_quad (SV *self, float x, float y, float w = 0, float h = 0) +draw_quad (SV *self, float x, float y, float w = 0., float h = 0.) PROTOTYPE: $$$;$$ ALIAS: draw_quad_alpha = 1 @@ -959,7 +1071,6 @@ float s = SvNV (*hv_fetch (hv, "s", 1, 1)); float t = SvNV (*hv_fetch (hv, "t", 1, 1)); int name = SvIV (*hv_fetch (hv, "name", 4, 1)); - int wrap_mode = SvIV (*hv_fetch (hv, "wrap_mode", 9, 1)); if (items < 5) { @@ -970,17 +1081,19 @@ if (ix) { glEnable (GL_BLEND); - glBlendFunc (ix == 1 ? GL_SRC_ALPHA : GL_ONE, GL_ONE_MINUS_SRC_ALPHA); - } - glBindTexture (GL_TEXTURE_2D, name); + if (ix == 2) + glBlendFunc (GL_ONE, GL_ONE_MINUS_SRC_ALPHA); + else + gl_BlendFuncSeparate (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, + GL_ONE , GL_ONE_MINUS_SRC_ALPHA); - if (wrap_mode) - { - glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); - glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); + glEnable (GL_ALPHA_TEST); + glAlphaFunc (GL_GREATER, 0.01f); } + glBindTexture (GL_TEXTURE_2D, name); + glBegin (GL_QUADS); glTexCoord2f (0, 0); glVertex2f (x , y ); glTexCoord2f (0, t); glVertex2f (x , y + h); @@ -989,7 +1102,10 @@ glEnd (); if (ix) - glDisable (GL_BLEND); + { + glDisable (GL_ALPHA_TEST); + glDisable (GL_BLEND); + } } MODULE = CFClient PACKAGE = CFClient::Map @@ -1019,6 +1135,7 @@ { map_clear (self); Safefree (self->face); + Safefree (self->tex); Safefree (self); } @@ -1063,17 +1180,34 @@ tex->b = b; tex->a = a; } + + // somewhat hackish, but for textures that require it, it really + // improves the look, and most others don't suffer. + glBindTexture (GL_TEXTURE_2D, name); + //glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); + //glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); + // use uglier nearest interpolation because linear suffers + // from transparent color bleeding and ugly wrapping effects. + glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); } int ox (CFClient::Map self) ALIAS: oy = 1 + x = 2 + y = 3 + w = 4 + h = 5 CODE: switch (ix) { case 0: RETVAL = self->ox; break; case 1: RETVAL = self->oy; break; + case 2: RETVAL = self->x; break; + case 3: RETVAL = self->y; break; + case 4: RETVAL = self->w; break; + case 5: RETVAL = self->h; break; } OUTPUT: RETVAL @@ -1117,8 +1251,8 @@ { flags = (data [0] << 8) + data [1]; data += 2; - x = ((flags >> 10) & 63) + self->x; - y = ((flags >> 4) & 63) + self->y; + x = self->x + ((flags >> 10) & 63); + y = self->y + ((flags >> 4) & 63); cell = map_get_cell (self, x, y); @@ -1218,22 +1352,15 @@ void draw (CFClient::Map self, int shift_x, int shift_y, int x0, int y0, int sw, int sh) - PPCODE: + CODE: { int vx, vy; int x, y, z; int last_name; mapface face; - int sw4 = (sw + 3) & ~3; - SV *darkness_sv = sv_2mortal (newSV (sw4 * sh)); - uint8_t *darkness = (uint8_t *)SvPVX (darkness_sv); - - memset (darkness, 255, sw4 * sh); - SvPOK_only (darkness_sv); - SvCUR_set (darkness_sv, sw4 * sh); - vx = self->x + (self->w - sw) / 2 - shift_x; - vy = self->y + (self->h - sh) / 2 - shift_y; + vx = self->x + self->w / 2 - sw / 2 - shift_x; + vy = self->y + self->h / 2 - sh / 2 - shift_y; /* int vx = self->vx = self->w >= sw @@ -1247,8 +1374,8 @@ glColor4ub (255, 255, 255, 255); - glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glEnable (GL_BLEND); + glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glEnable (GL_TEXTURE_2D); glTexEnvi (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE); @@ -1267,10 +1394,6 @@ { mapcell *cell = row->col + (x + vx - row->c0); - darkness[y * sw4 + x] = cell->darkness < 0 - ? 255 - FOW_DARKNESS - : 255 - cell->darkness; - face = cell->face [z]; if (face) @@ -1300,6 +1423,100 @@ glDisable (GL_TEXTURE_2D); glDisable (GL_BLEND); +} + +void +draw_magicmap (CFClient::Map self, int dx, int dy, int w, int h, unsigned char *data) + CODE: +{ + static float color[16][3] = { + { 0.00F, 0.00F, 0.00F }, + { 1.00F, 1.00F, 1.00F }, + { 0.00F, 0.00F, 0.55F }, + { 1.00F, 0.00F, 0.00F }, + + { 1.00F, 0.54F, 0.00F }, + { 0.11F, 0.56F, 1.00F }, + { 0.93F, 0.46F, 0.00F }, + { 0.18F, 0.54F, 0.34F }, + + { 0.56F, 0.73F, 0.56F }, + { 0.80F, 0.80F, 0.80F }, + { 0.55F, 0.41F, 0.13F }, + { 0.99F, 0.77F, 0.26F }, + + { 0.74F, 0.65F, 0.41F }, + + { 0.00F, 1.00F, 1.00F }, + { 1.00F, 0.00F, 1.00F }, + { 1.00F, 1.00F, 0.00F }, + }; + + int x, y; + + glEnable (GL_TEXTURE_2D); + glTexEnvi (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE); + glEnable (GL_BLEND); + glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); + glBegin (GL_QUADS); + + for (y = 0; y < h; y++) + for (x = 0; x < w; x++) + { + unsigned char m = data [x + y * w]; + + if (m) + { + float *c = color [m & 15]; + + float tx1 = m & 0x40 ? 0.5 : 0.; + float tx2 = tx1 + 0.5; + + glColor4f (c[0], c[1], c[2], 0.75); + glTexCoord2f (tx1, 0.); glVertex2i (x , y ); + glTexCoord2f (tx1, 1.); glVertex2i (x , y + 1); + glTexCoord2f (tx2, 1.); glVertex2i (x + 1, y + 1); + glTexCoord2f (tx2, 0.); glVertex2i (x + 1, y ); + } + } + + glEnd (); + glDisable (GL_BLEND); + glDisable (GL_TEXTURE_2D); +} + +void +fow_texture (CFClient::Map self, int shift_x, int shift_y, int x0, int y0, int sw, int sh) + PPCODE: +{ + int vx, vy; + int x, y; + int sw4 = (sw + 3) & ~3; + SV *darkness_sv = sv_2mortal (newSV (sw4 * sh)); + uint8_t *darkness = (uint8_t *)SvPVX (darkness_sv); + + memset (darkness, 255, sw4 * sh); + SvPOK_only (darkness_sv); + SvCUR_set (darkness_sv, sw4 * sh); + + vx = self->x + (self->w - sw + 1) / 2 - shift_x; + vy = self->y + (self->h - sh + 1) / 2 - shift_y; + + for (y = 0; y < sh; y++) + if (0 <= y + vy && y + vy < self->rows) + { + maprow *row = self->row + (y + vy); + + for (x = 0; x < sw; x++) + if (row->c0 <= x + vx && x + vx < row->c1) + { + mapcell *cell = row->col + (x + vx - row->c0); + + darkness[y * sw4 + x] = cell->darkness < 0 + ? 255 - FOW_DARKNESS + : 255 - cell->darkness; + } + } EXTEND (SP, 3); PUSHs (sv_2mortal (newSViv (sw4))); @@ -1510,19 +1727,34 @@ const_iv (GL_FLAT), const_iv (GL_DITHER), const_iv (GL_BLEND), + const_iv (GL_CULL_FACE), const_iv (GL_SCISSOR_TEST), + const_iv (GL_DEPTH_TEST), + const_iv (GL_ALPHA_TEST), + const_iv (GL_NORMALIZE), + const_iv (GL_RESCALE_NORMAL), + const_iv (GL_FRONT), + const_iv (GL_BACK), const_iv (GL_AND), const_iv (GL_ONE), const_iv (GL_ZERO), const_iv (GL_SRC_ALPHA), - const_iv (GL_SRC_ALPHA_SATURATE), + const_iv (GL_DST_ALPHA), const_iv (GL_ONE_MINUS_SRC_ALPHA), const_iv (GL_ONE_MINUS_DST_ALPHA), + const_iv (GL_SRC_ALPHA_SATURATE), const_iv (GL_RGB), const_iv (GL_RGBA), + const_iv (GL_RGBA4), + const_iv (GL_RGBA8), + const_iv (GL_RGB5_A1), const_iv (GL_UNSIGNED_BYTE), + const_iv (GL_UNSIGNED_SHORT), + const_iv (GL_UNSIGNED_INT), const_iv (GL_ALPHA), + const_iv (GL_INTENSITY), const_iv (GL_LUMINANCE), + const_iv (GL_LUMINANCE_ALPHA), const_iv (GL_FLOAT), const_iv (GL_UNSIGNED_INT_8_8_8_8_REV), const_iv (GL_COMPILE), @@ -1534,8 +1766,9 @@ const_iv (GL_TEXTURE_ENV_MODE), const_iv (GL_TEXTURE_WRAP_S), const_iv (GL_TEXTURE_WRAP_T), - const_iv (GL_CLAMP), const_iv (GL_REPEAT), + const_iv (GL_CLAMP), + const_iv (GL_CLAMP_TO_EDGE), const_iv (GL_NEAREST), const_iv (GL_LINEAR), const_iv (GL_NEAREST_MIPMAP_NEAREST), @@ -1546,6 +1779,7 @@ const_iv (GL_MODULATE), const_iv (GL_DECAL), const_iv (GL_REPLACE), + const_iv (GL_DEPTH_BUFFER_BIT), const_iv (GL_COLOR_BUFFER_BIT), const_iv (GL_PROJECTION), const_iv (GL_MODELVIEW), @@ -1555,10 +1789,18 @@ const_iv (GL_CONVOLUTION_BORDER_MODE), const_iv (GL_CONSTANT_BORDER), const_iv (GL_LINES), - const_iv (GL_QUADS), const_iv (GL_LINE_LOOP), + const_iv (GL_QUADS), + const_iv (GL_QUAD_STRIP), + const_iv (GL_TRIANGLES), + const_iv (GL_TRIANGLE_STRIP), + const_iv (GL_TRIANGLE_FAN), const_iv (GL_PERSPECTIVE_CORRECTION_HINT), const_iv (GL_FASTEST), + const_iv (GL_V2F), + const_iv (GL_V3F), + const_iv (GL_T2F_V3F), + const_iv (GL_T2F_N3F_V3F), # undef const_iv }; @@ -1566,8 +1808,31 @@ newCONSTSUB (stash, (char *)civ->name, newSViv (civ->iv)); } +char * +gl_vendor () + CODE: + RETVAL = (char *)glGetString (GL_VENDOR); + OUTPUT: + RETVAL + +char * +gl_version () + CODE: + RETVAL = (char *)glGetString (GL_VERSION); + OUTPUT: + RETVAL + +char * +gl_extensions () + CODE: + RETVAL = (char *)glGetString (GL_EXTENSIONS); + OUTPUT: + RETVAL + int glGetError () +void glFinish () + void glClear (int mask) void glClearColor (float r, float g, float b, float a = 1.0) @@ -1583,6 +1848,12 @@ void glBlendFunc (int sfactor, int dfactor) +void glBlendFuncSeparate (int sa, int da, int saa, int daa) + CODE: + gl_BlendFuncSeparate (sa, da, saa, daa); + +void glDepthMask (int flag) + void glLogicOp (int opcode) void glColorMask (int red, int green, int blue, int alpha) @@ -1595,7 +1866,14 @@ void glLoadIdentity () -# near and far are due to microsofts buggy c compiler +void glDrawBuffer (int buffer) + +void glReadBuffer (int buffer) + +# near_ and far_ are due to microsofts buggy "c" compiler +void glFrustum (double left, double right, double bottom, double top, double near_, double far_) + +# near_ and far_ are due to microsofts buggy "c" compiler void glOrtho (double left, double right, double bottom, double top, double near_, double far_) void glViewport (int x, int y, int width, int height) @@ -1620,11 +1898,31 @@ void glColor (float r, float g, float b, float a = 1.0) PROTOTYPE: @ + ALIAS: + glColor_premultiply = 1 CODE: - glColor4ub (MIN ((int)(r * 255.f), 255), - MIN ((int)(g * 255.f), 255), - MIN ((int)(b * 255.f), 255), - MIN ((int)(a * 255.f), 255)); + if (ix) + { + r *= a; + g *= a; + b *= a; + } + // microsoft visual "c" rounds instead of truncating... + glColor4ub (MIN ((int)(r * 256.f), 255), + MIN ((int)(g * 256.f), 255), + MIN ((int)(b * 256.f), 255), + MIN ((int)(a * 256.f), 255)); + +void glInterleavedArrays (int format, int stride, char *data) + +void glDrawElements (int mode, int count, int type, char *indices) + +# 1.2 void glDrawRangeElements (int mode, int start, int end + +void glRasterPos (float x, float y, float z = 0.) + CODE: + glRasterPos3f (0, 0, z); + glBitmap (0, 0, 0, 0, x, y, 0); void glVertex (float x, float y, float z = 0.) CODE: @@ -1646,25 +1944,24 @@ void glConvolutionParameter (int target, int pname, float params) CODE: - GL_CALL (PFNGLCONVOLUTIONPARAMETERFEXTPROC, glConvolutionParameterf, (target, pname, params)); + if (gl.ConvolutionParameterf) + gl.ConvolutionParameterf (target, pname, params); void glConvolutionFilter2D (int target, int internalformat, int width, int height, int format, int type, char *data) CODE: - GL_CALL (PFNGLCONVOLUTIONFILTER2DEXTPROC, glConvolutionFilter2D, - (target, internalformat, width, height, format, type, data)); + if (gl.ConvolutionFilter2D) + gl.ConvolutionFilter2D (target, internalformat, width, height, format, type, data); void glSeparableFilter2D (int target, int internalformat, int width, int height, int format, int type, char *row, char *column) CODE: - GL_CALL (PFNGLSEPARABLEFILTER2DEXTPROC, glSeparableFilter2D, - (target, internalformat, width, height, format, type, row, column)); + if (gl.SeparableFilter2D) + gl.SeparableFilter2D (target, internalformat, width, height, format, type, row, column); void glTexImage2D (int target, int level, int internalformat, int width, int height, int border, int format, int type, char *data) void glCopyTexImage2D (int target, int level, int internalformat, int x, int y, int width, int height, int border) -void glRasterPos (int x, int y) - CODE: - glRasterPos2i (x, y); +void glDrawPixels (int width, int height, int format, int type, char *pixels) void glCopyPixels (int x, int y, int width, int height, int type = GL_COLOR) @@ -1701,3 +1998,4 @@ void glCallList (int list) +