… | |
… | |
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 | |
|
|
1664 | void |
|
|
1665 | draw_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 | |
1663 | IV texture_valid_2d (GLint internalformat, GLsizei w, GLsizei h, GLenum format, GLenum type) |
1753 | IV 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); |
… | |
… | |
2366 | }; |
2456 | }; |
2367 | |
2457 | |
2368 | int x, y; |
2458 | int x, y; |
2369 | |
2459 | |
2370 | glEnable (GL_TEXTURE_2D); |
2460 | glEnable (GL_TEXTURE_2D); |
|
|
2461 | /* GL_REPLACE would be correct, as we don't need to modulate alpha, |
|
|
2462 | * but the nvidia driver (185.18.14) mishandles alpha textures |
|
|
2463 | * ansd takes the colour from god knows where instead of using |
|
|
2464 | * Cp. MODULATE results in the same colour, but slightly different |
|
|
2465 | * alpha, but atcually gives us the correct colour with nvidia. |
|
|
2466 | */ |
2371 | glTexEnvi (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE); |
2467 | glTexEnvi (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); |
2372 | glEnable (GL_BLEND); |
2468 | glEnable (GL_BLEND); |
2373 | glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); |
2469 | glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); |
2374 | glBegin (GL_QUADS); |
2470 | glBegin (GL_QUADS); |
2375 | |
2471 | |
2376 | for (y = 0; y < h; y++) |
2472 | for (y = 0; y < h; y++) |
… | |
… | |
2383 | float *c = color [m & 15]; |
2479 | float *c = color [m & 15]; |
2384 | |
2480 | |
2385 | float tx1 = m & 0x40 ? 0.5 : 0.; |
2481 | float tx1 = m & 0x40 ? 0.5 : 0.; |
2386 | float tx2 = tx1 + 0.5; |
2482 | float tx2 = tx1 + 0.5; |
2387 | |
2483 | |
2388 | glColor4f (c[0], c[1], c[2], 0.75); |
2484 | glColor4f (c[0], c[1], c[2], 1); |
2389 | glTexCoord2f (tx1, 0.); glVertex2i (x , y ); |
2485 | glTexCoord2f (tx1, 0.); glVertex2i (x , y ); |
2390 | glTexCoord2f (tx1, 1.); glVertex2i (x , y + 1); |
2486 | glTexCoord2f (tx1, 1.); glVertex2i (x , y + 1); |
2391 | glTexCoord2f (tx2, 1.); glVertex2i (x + 1, y + 1); |
2487 | glTexCoord2f (tx2, 1.); glVertex2i (x + 1, y + 1); |
2392 | glTexCoord2f (tx2, 0.); glVertex2i (x + 1, y ); |
2488 | glTexCoord2f (tx2, 0.); glVertex2i (x + 1, y ); |
2393 | } |
2489 | } |
… | |
… | |
2415 | SvCUR_set (darkness3_sv, sw34 * sh3); |
2511 | SvCUR_set (darkness3_sv, sw34 * sh3); |
2416 | |
2512 | |
2417 | mx += self->x - 1; |
2513 | mx += self->x - 1; |
2418 | my += self->y - 1; |
2514 | my += self->y - 1; |
2419 | |
2515 | |
2420 | memset (darkness1, 255 - FOW_DARKNESS, sw1 * sh1); |
2516 | memset (darkness1, DARKNESS_ADJUST (255 - FOW_DARKNESS), sw1 * sh1); |
2421 | |
2517 | |
2422 | for (y = 0; y < sh1; y++) |
2518 | for (y = 0; y < sh1; y++) |
2423 | if (0 <= y + my && y + my < self->rows) |
2519 | if (0 <= y + my && y + my < self->rows) |
2424 | { |
2520 | { |
2425 | maprow *row = self->row + (y + my); |
2521 | maprow *row = self->row + (y + my); |
… | |
… | |
2428 | if (row->c0 <= x + mx && x + mx < row->c1) |
2524 | if (row->c0 <= x + mx && x + mx < row->c1) |
2429 | { |
2525 | { |
2430 | mapcell *cell = row->col + (x + mx - row->c0); |
2526 | mapcell *cell = row->col + (x + mx - row->c0); |
2431 | |
2527 | |
2432 | darkness1 [y * sw1 + x] = cell->darkness |
2528 | darkness1 [y * sw1 + x] = cell->darkness |
2433 | ? 255 - (cell->darkness - 1) |
2529 | ? DARKNESS_ADJUST (255 - (cell->darkness - 1)) |
2434 | : 255 - FOW_DARKNESS; |
2530 | : DARKNESS_ADJUST (255 - FOW_DARKNESS); |
2435 | } |
2531 | } |
2436 | } |
2532 | } |
2437 | |
2533 | |
2438 | for (y = 0; y < sh; ++y) |
2534 | for (y = 0; y < sh; ++y) |
2439 | for (x = 0; x < sw; ++x) |
2535 | for (x = 0; x < sw; ++x) |
… | |
… | |
2852 | } *civ, const_iv[] = { |
2948 | } *civ, const_iv[] = { |
2853 | # define const_iv(name) { # name, (IV)name } |
2949 | # define const_iv(name) { # name, (IV)name } |
2854 | const_iv (GL_VENDOR), |
2950 | const_iv (GL_VENDOR), |
2855 | const_iv (GL_VERSION), |
2951 | const_iv (GL_VERSION), |
2856 | const_iv (GL_EXTENSIONS), |
2952 | const_iv (GL_EXTENSIONS), |
|
|
2953 | const_iv (GL_MAX_TEXTURE_UNITS), |
2857 | const_iv (GL_COLOR_MATERIAL), |
2954 | const_iv (GL_COLOR_MATERIAL), |
2858 | const_iv (GL_SMOOTH), |
2955 | const_iv (GL_SMOOTH), |
2859 | const_iv (GL_FLAT), |
2956 | const_iv (GL_FLAT), |
2860 | const_iv (GL_DITHER), |
2957 | const_iv (GL_DITHER), |
2861 | const_iv (GL_BLEND), |
2958 | const_iv (GL_BLEND), |
… | |
… | |
2873 | const_iv (GL_ZERO), |
2970 | const_iv (GL_ZERO), |
2874 | const_iv (GL_SRC_ALPHA), |
2971 | const_iv (GL_SRC_ALPHA), |
2875 | const_iv (GL_DST_ALPHA), |
2972 | const_iv (GL_DST_ALPHA), |
2876 | const_iv (GL_ONE_MINUS_SRC_ALPHA), |
2973 | const_iv (GL_ONE_MINUS_SRC_ALPHA), |
2877 | 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), |
2878 | const_iv (GL_SRC_ALPHA_SATURATE), |
2979 | const_iv (GL_SRC_ALPHA_SATURATE), |
2879 | const_iv (GL_RGB), |
2980 | const_iv (GL_RGB), |
2880 | const_iv (GL_RGBA), |
2981 | const_iv (GL_RGBA), |
2881 | const_iv (GL_RGBA4), |
2982 | const_iv (GL_RGBA4), |
2882 | const_iv (GL_RGBA8), |
2983 | const_iv (GL_RGBA8), |
… | |
… | |
2950 | const_iv (GL_NICEST), |
3051 | const_iv (GL_NICEST), |
2951 | const_iv (GL_V2F), |
3052 | const_iv (GL_V2F), |
2952 | const_iv (GL_V3F), |
3053 | const_iv (GL_V3F), |
2953 | const_iv (GL_T2F_V3F), |
3054 | const_iv (GL_T2F_V3F), |
2954 | const_iv (GL_T2F_N3F_V3F), |
3055 | const_iv (GL_T2F_N3F_V3F), |
|
|
3056 | const_iv (GL_FUNC_ADD), |
|
|
3057 | const_iv (GL_FUNC_SUBTRACT), |
|
|
3058 | const_iv (GL_FUNC_REVERSE_SUBTRACT), |
2955 | # undef const_iv |
3059 | # undef const_iv |
2956 | }; |
3060 | }; |
2957 | |
3061 | |
2958 | for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ-- > const_iv; ) |
3062 | for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ-- > const_iv; ) |
2959 | newCONSTSUB (stash, (char *)civ->name, newSViv (civ->iv)); |
3063 | newCONSTSUB (stash, (char *)civ->name, newSViv (civ->iv)); |
… | |
… | |
2966 | disable_GL_EXT_blend_func_separate () |
3070 | disable_GL_EXT_blend_func_separate () |
2967 | CODE: |
3071 | CODE: |
2968 | gl.BlendFuncSeparate = 0; |
3072 | gl.BlendFuncSeparate = 0; |
2969 | gl.BlendFuncSeparateEXT = 0; |
3073 | gl.BlendFuncSeparateEXT = 0; |
2970 | |
3074 | |
|
|
3075 | void |
|
|
3076 | apple_nvidia_bug (int enable) |
|
|
3077 | |
2971 | char * |
3078 | char * |
2972 | gl_vendor () |
3079 | gl_vendor () |
2973 | CODE: |
3080 | CODE: |
2974 | RETVAL = (char *)glGetString (GL_VENDOR); |
3081 | RETVAL = (char *)glGetString (GL_VENDOR); |
2975 | OUTPUT: |
3082 | OUTPUT: |
… | |
… | |
3023 | void glBlendFunc (int sfactor, int dfactor) |
3130 | void glBlendFunc (int sfactor, int dfactor) |
3024 | |
3131 | |
3025 | void glBlendFuncSeparate (int sa, int da, int saa, int daa) |
3132 | void glBlendFuncSeparate (int sa, int da, int saa, int daa) |
3026 | CODE: |
3133 | CODE: |
3027 | gl_BlendFuncSeparate (sa, da, saa, daa); |
3134 | gl_BlendFuncSeparate (sa, da, saa, daa); |
|
|
3135 | |
|
|
3136 | # void glBlendEquation (int se) |
3028 | |
3137 | |
3029 | void glDepthMask (int flag) |
3138 | void glDepthMask (int flag) |
3030 | |
3139 | |
3031 | void glLogicOp (int opcode) |
3140 | void glLogicOp (int opcode) |
3032 | |
3141 | |