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.291 by root, Thu Nov 26 07:19:11 2009 UTC vs.
Revision 1.294 by root, Sat Dec 19 05:06:56 2009 UTC

82#define expect_true(expr) expect ((expr) != 0, 1) 82#define expect_true(expr) expect ((expr) != 0, 1)
83 83
84#define OBJ_STR "\xef\xbf\xbc" /* U+FFFC, object replacement character */ 84#define OBJ_STR "\xef\xbf\xbc" /* U+FFFC, object replacement character */
85 85
86#define FOW_DARKNESS 64 86#define FOW_DARKNESS 64
87#define DARKNESS_ADJUST(n) ((29 * (int)(n)) >> 5) /* times 0.9 */
87 88
88#define MAP_EXTEND_X 32 89#define MAP_EXTEND_X 32
89#define MAP_EXTEND_Y 512 90#define MAP_EXTEND_Y 512
90 91
91#define MIN_FONT_HEIGHT 10 92#define MIN_FONT_HEIGHT 10
1658 glDisable (GL_ALPHA_TEST); 1659 glDisable (GL_ALPHA_TEST);
1659 glDisable (GL_BLEND); 1660 glDisable (GL_BLEND);
1660 } 1661 }
1661} 1662}
1662 1663
1664void
1665draw_fow_texture (float intensity, int name1, float s1, float t1, float w1, float h1, float blend = 0.f, float dx = 0.f, float dy = 0.f, int name2 = 0, float s2 = 0.f, float t2 = 0.f, float w2 = 0.f, float h2 = 0.f)
1666 PROTOTYPE: @
1667 CODE:
1668{
1669 glEnable (GL_TEXTURE_2D);
1670 glEnable (GL_BLEND);
1671 glBlendFunc (GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
1672 glBindTexture (GL_TEXTURE_2D, name1);
1673
1674 glColor3f (intensity, intensity, intensity);
1675 glPushMatrix ();
1676 glScalef (1./3, 1./3, 1.);
1677
1678 if (blend > 0.f)
1679 {
1680 float S2, T2; /* 0. 0. for texture 2 */
1681 float w = w1 > w2 ? w1 : w2;
1682 float h = h1 > h2 ? h1 : h2;
1683 GLfloat env_color[4] = { 0., 0., 0., blend };
1684
1685 /* interpolate the two shadow textures */
1686 /* stage 0 == rgb(glcolor) + alpha(t0) */
1687 glTexEnvi (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
1688
1689 /* stage 1 == rgb(glcolor) + alpha(interpolate t0, t1, texenv) */
1690 gl.ActiveTexture (GL_TEXTURE1);
1691 glEnable (GL_TEXTURE_2D);
1692 glBindTexture (GL_TEXTURE_2D, name2);
1693 glTexEnvi (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE);
1694
1695 /* rgb == rgb(glcolor) */
1696 glTexEnvi (GL_TEXTURE_ENV, GL_COMBINE_RGB, GL_REPLACE);
1697 glTexEnvi (GL_TEXTURE_ENV, GL_SOURCE0_RGB, GL_CONSTANT);
1698 glTexEnvi (GL_TEXTURE_ENV, GL_OPERAND0_RGB, GL_SRC_COLOR);
1699
1700 /* alpha = interpolate t0, t1 by env_alpha */
1701 glTexEnvfv (GL_TEXTURE_ENV, GL_TEXTURE_ENV_COLOR, env_color);
1702
1703 glTexEnvi (GL_TEXTURE_ENV, GL_COMBINE_ALPHA, GL_INTERPOLATE);
1704 glTexEnvi (GL_TEXTURE_ENV, GL_SOURCE0_ALPHA, GL_TEXTURE);
1705 glTexEnvi (GL_TEXTURE_ENV, GL_OPERAND0_ALPHA, GL_SRC_ALPHA);
1706
1707 glTexEnvi (GL_TEXTURE_ENV, GL_SOURCE1_ALPHA, GL_PREVIOUS);
1708 glTexEnvi (GL_TEXTURE_ENV, GL_OPERAND1_ALPHA, GL_SRC_ALPHA);
1709
1710 glTexEnvi (GL_TEXTURE_ENV, GL_SOURCE2_ALPHA, GL_CONSTANT);
1711 glTexEnvi (GL_TEXTURE_ENV, GL_OPERAND2_ALPHA, GL_SRC_ALPHA);
1712
1713 s1 *= w / w1;
1714 t1 *= h / h1;
1715
1716 dx *= -3.f / w2;
1717 dy *= -3.f / h2;
1718 dx *= w / w2;
1719 dy *= h / h2;
1720
1721 s2 *= w / w2;
1722 t2 *= h / h2;
1723
1724 glBegin (GL_QUADS);
1725 gl.MultiTexCoord2f (GL_TEXTURE0, 0, 0); gl.MultiTexCoord2f (GL_TEXTURE1, dx , dy ); glVertex2f ( 0, 0);
1726 gl.MultiTexCoord2f (GL_TEXTURE0, 0, t1); gl.MultiTexCoord2f (GL_TEXTURE1, dx , dy + t2); glVertex2f ( 0, h1);
1727 gl.MultiTexCoord2f (GL_TEXTURE0, s1, t1); gl.MultiTexCoord2f (GL_TEXTURE1, dx + s2, dy + t2); glVertex2f (w1, h1);
1728 gl.MultiTexCoord2f (GL_TEXTURE0, s1, 0); gl.MultiTexCoord2f (GL_TEXTURE1, dx + s2, dy ); glVertex2f (w1, 0);
1729 glEnd ();
1730
1731 glDisable (GL_TEXTURE_2D);
1732 gl.ActiveTexture (GL_TEXTURE0);
1733 }
1734 else
1735 {
1736 /* simple blending of one texture, also opengl <1.3 path */
1737 glTexEnvi (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
1738
1739 glBegin (GL_QUADS);
1740 glTexCoord2f ( 0, 0); glVertex2f ( 0, 0);
1741 glTexCoord2f ( 0, t1); glVertex2f ( 0, h1);
1742 glTexCoord2f (s1, t1); glVertex2f (w1, h1);
1743 glTexCoord2f (s1, 0); glVertex2f (w1, 0);
1744 glEnd ();
1745 }
1746
1747 glPopMatrix ();
1748
1749 glDisable (GL_TEXTURE_2D);
1750 glDisable (GL_BLEND);
1751}
1752
1663IV texture_valid_2d (GLint internalformat, GLsizei w, GLsizei h, GLenum format, GLenum type) 1753IV texture_valid_2d (GLint internalformat, GLsizei w, GLsizei h, GLenum format, GLenum type)
1664 CODE: 1754 CODE:
1665{ 1755{
1666 GLint width; 1756 GLint width;
1667 glTexImage2D (GL_PROXY_TEXTURE_2D, 0, internalformat, w, h, 0, format, type, 0); 1757 glTexImage2D (GL_PROXY_TEXTURE_2D, 0, internalformat, w, h, 0, format, type, 0);
2421 SvCUR_set (darkness3_sv, sw34 * sh3); 2511 SvCUR_set (darkness3_sv, sw34 * sh3);
2422 2512
2423 mx += self->x - 1; 2513 mx += self->x - 1;
2424 my += self->y - 1; 2514 my += self->y - 1;
2425 2515
2426 memset (darkness1, 255 - FOW_DARKNESS, sw1 * sh1); 2516 memset (darkness1, DARKNESS_ADJUST (255 - FOW_DARKNESS), sw1 * sh1);
2427 2517
2428 for (y = 0; y < sh1; y++) 2518 for (y = 0; y < sh1; y++)
2429 if (0 <= y + my && y + my < self->rows) 2519 if (0 <= y + my && y + my < self->rows)
2430 { 2520 {
2431 maprow *row = self->row + (y + my); 2521 maprow *row = self->row + (y + my);
2434 if (row->c0 <= x + mx && x + mx < row->c1) 2524 if (row->c0 <= x + mx && x + mx < row->c1)
2435 { 2525 {
2436 mapcell *cell = row->col + (x + mx - row->c0); 2526 mapcell *cell = row->col + (x + mx - row->c0);
2437 2527
2438 darkness1 [y * sw1 + x] = cell->darkness 2528 darkness1 [y * sw1 + x] = cell->darkness
2439 ? 255 - (cell->darkness - 1) 2529 ? DARKNESS_ADJUST (255 - (cell->darkness - 1))
2440 : 255 - FOW_DARKNESS; 2530 : DARKNESS_ADJUST (255 - FOW_DARKNESS);
2441 } 2531 }
2442 } 2532 }
2443 2533
2444 for (y = 0; y < sh; ++y) 2534 for (y = 0; y < sh; ++y)
2445 for (x = 0; x < sw; ++x) 2535 for (x = 0; x < sw; ++x)
2858 } *civ, const_iv[] = { 2948 } *civ, const_iv[] = {
2859# define const_iv(name) { # name, (IV)name } 2949# define const_iv(name) { # name, (IV)name }
2860 const_iv (GL_VENDOR), 2950 const_iv (GL_VENDOR),
2861 const_iv (GL_VERSION), 2951 const_iv (GL_VERSION),
2862 const_iv (GL_EXTENSIONS), 2952 const_iv (GL_EXTENSIONS),
2953 const_iv (GL_MAX_TEXTURE_UNITS),
2863 const_iv (GL_COLOR_MATERIAL), 2954 const_iv (GL_COLOR_MATERIAL),
2864 const_iv (GL_SMOOTH), 2955 const_iv (GL_SMOOTH),
2865 const_iv (GL_FLAT), 2956 const_iv (GL_FLAT),
2866 const_iv (GL_DITHER), 2957 const_iv (GL_DITHER),
2867 const_iv (GL_BLEND), 2958 const_iv (GL_BLEND),
2879 const_iv (GL_ZERO), 2970 const_iv (GL_ZERO),
2880 const_iv (GL_SRC_ALPHA), 2971 const_iv (GL_SRC_ALPHA),
2881 const_iv (GL_DST_ALPHA), 2972 const_iv (GL_DST_ALPHA),
2882 const_iv (GL_ONE_MINUS_SRC_ALPHA), 2973 const_iv (GL_ONE_MINUS_SRC_ALPHA),
2883 const_iv (GL_ONE_MINUS_DST_ALPHA), 2974 const_iv (GL_ONE_MINUS_DST_ALPHA),
2975 const_iv (GL_SRC_COLOR),
2976 const_iv (GL_DST_COLOR),
2977 const_iv (GL_ONE_MINUS_SRC_COLOR),
2978 const_iv (GL_ONE_MINUS_DST_COLOR),
2884 const_iv (GL_SRC_ALPHA_SATURATE), 2979 const_iv (GL_SRC_ALPHA_SATURATE),
2885 const_iv (GL_RGB), 2980 const_iv (GL_RGB),
2886 const_iv (GL_RGBA), 2981 const_iv (GL_RGBA),
2887 const_iv (GL_RGBA4), 2982 const_iv (GL_RGBA4),
2888 const_iv (GL_RGBA8), 2983 const_iv (GL_RGBA8),
3036 3131
3037void glBlendFuncSeparate (int sa, int da, int saa, int daa) 3132void glBlendFuncSeparate (int sa, int da, int saa, int daa)
3038 CODE: 3133 CODE:
3039 gl_BlendFuncSeparate (sa, da, saa, daa); 3134 gl_BlendFuncSeparate (sa, da, saa, daa);
3040 3135
3041void glBlendEquation (int se) 3136# void glBlendEquation (int se)
3042 3137
3043void glDepthMask (int flag) 3138void glDepthMask (int flag)
3044 3139
3045void glLogicOp (int opcode) 3140void glLogicOp (int opcode)
3046 3141

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines