… | |
… | |
203 | |
203 | |
204 | typedef uint16_t tileid; |
204 | typedef uint16_t tileid; |
205 | typedef uint16_t faceid; |
205 | typedef uint16_t faceid; |
206 | |
206 | |
207 | typedef struct { |
207 | typedef struct { |
208 | int name; |
208 | GLuint name; |
209 | int w, h; |
209 | int w, h; |
210 | float s, t; |
210 | float s, t; |
211 | uint8_t r, g, b, a; |
211 | uint8_t r, g, b, a; |
212 | tileid smoothtile; |
212 | tileid smoothtile; |
213 | uint8_t smoothlevel; |
213 | uint8_t smoothlevel; |
… | |
… | |
438 | n |= n >> 4; |
438 | n |= n >> 4; |
439 | n |= n >> 8; |
439 | n |= n >> 8; |
440 | n |= n >> 16; |
440 | n |= n >> 16; |
441 | |
441 | |
442 | return n + 1; |
442 | return n + 1; |
|
|
443 | } |
|
|
444 | |
|
|
445 | static unsigned int |
|
|
446 | popcount (unsigned int n) |
|
|
447 | { |
|
|
448 | n -= (n >> 1) & 0x55555555U; |
|
|
449 | n = ((n >> 2) & 0x33333333U) + (n & 0x33333333U); |
|
|
450 | n = ((n >> 4) + n) & 0x0f0f0f0fU; |
|
|
451 | n *= 0x01010101U; |
|
|
452 | |
|
|
453 | return n >> 24; |
443 | } |
454 | } |
444 | |
455 | |
445 | /* SDL should provide this, really. */ |
456 | /* SDL should provide this, really. */ |
446 | #define SDLK_MODIFIER_MIN 300 |
457 | #define SDLK_MODIFIER_MIN 300 |
447 | #define SDLK_MODIFIER_MAX 314 |
458 | #define SDLK_MODIFIER_MAX 314 |
… | |
… | |
525 | |
536 | |
526 | const_iv (SDL_APPINPUTFOCUS), |
537 | const_iv (SDL_APPINPUTFOCUS), |
527 | const_iv (SDL_APPMOUSEFOCUS), |
538 | const_iv (SDL_APPMOUSEFOCUS), |
528 | const_iv (SDL_APPACTIVE), |
539 | const_iv (SDL_APPACTIVE), |
529 | |
540 | |
|
|
541 | const_iv (SDLK_FIRST), |
|
|
542 | const_iv (SDLK_LAST), |
530 | const_iv (SDLK_KP0), |
543 | const_iv (SDLK_KP0), |
531 | const_iv (SDLK_KP1), |
544 | const_iv (SDLK_KP1), |
532 | const_iv (SDLK_KP2), |
545 | const_iv (SDLK_KP2), |
533 | const_iv (SDLK_KP3), |
546 | const_iv (SDLK_KP3), |
534 | const_iv (SDLK_KP4), |
547 | const_iv (SDLK_KP4), |
… | |
… | |
633 | |
646 | |
634 | NV floor (NV x) |
647 | NV floor (NV x) |
635 | |
648 | |
636 | NV ceil (NV x) |
649 | NV ceil (NV x) |
637 | |
650 | |
|
|
651 | IV minpot (UV n) |
|
|
652 | |
|
|
653 | IV popcount (UV n) |
|
|
654 | |
638 | void |
655 | void |
639 | pango_init () |
656 | pango_init () |
640 | CODE: |
657 | CODE: |
641 | { |
658 | { |
642 | opengl_fontmap = pango_opengl_font_map_new (); |
659 | opengl_fontmap = pango_opengl_font_map_new (); |
… | |
… | |
715 | |
732 | |
716 | if (RETVAL) |
733 | if (RETVAL) |
717 | { |
734 | { |
718 | av_clear (texture_av); |
735 | av_clear (texture_av); |
719 | |
736 | |
720 | SDL_WM_SetCaption ("Crossfire+ Client " VERSION, "Crossfire+"); |
737 | SDL_WM_SetCaption ("Crossfire TRT Client " VERSION, "Crossfire TRT"); |
721 | #define GL_FUNC(ptr,name) gl.name = (ptr)SDL_GL_GetProcAddress ("gl" # name); |
738 | #define GL_FUNC(ptr,name) gl.name = (ptr)SDL_GL_GetProcAddress ("gl" # name); |
722 | #include "glfunc.h" |
739 | #include "glfunc.h" |
723 | #undef GL_FUNC |
740 | #undef GL_FUNC |
724 | } |
741 | } |
725 | } |
742 | } |
… | |
… | |
1346 | |
1363 | |
1347 | MODULE = CFPlus PACKAGE = CFPlus::Texture |
1364 | MODULE = CFPlus PACKAGE = CFPlus::Texture |
1348 | |
1365 | |
1349 | PROTOTYPES: ENABLE |
1366 | PROTOTYPES: ENABLE |
1350 | |
1367 | |
1351 | int minpot (int n) |
|
|
1352 | |
|
|
1353 | void |
1368 | void |
1354 | pad (SV *data_, int ow, int oh, int nw, int nh) |
1369 | pad (SV *data_, int ow, int oh, int nw, int nh) |
1355 | CODE: |
1370 | CODE: |
1356 | { |
1371 | { |
1357 | if ((nw != ow || nh != oh) && SvOK (data_)) |
1372 | if ((nw != ow || nh != oh) && SvOK (data_)) |
… | |
… | |
1745 | { |
1760 | { |
1746 | int x, y, z; |
1761 | int x, y, z; |
1747 | |
1762 | |
1748 | HV *smooth = (HV *)sv_2mortal ((SV *)newHV ()); |
1763 | HV *smooth = (HV *)sv_2mortal ((SV *)newHV ()); |
1749 | uint32_t smooth_level[256 / 32]; // one bit for every possible smooth level |
1764 | uint32_t smooth_level[256 / 32]; // one bit for every possible smooth level |
1750 | static uint8_t smooth_max[256][256]; // egad, fats and wasteful on memory (64k) |
1765 | static uint8_t smooth_max[256][256]; // egad, fast and wasteful on memory (64k) |
1751 | smooth_key skey; |
1766 | smooth_key skey; |
1752 | |
1767 | |
1753 | rc_t *rc = rc_alloc (); |
1768 | rc_t *rc = rc_alloc (); |
1754 | rc_key_t key; |
1769 | rc_key_t key; |
1755 | rc_array_t *arr; |
1770 | rc_array_t *arr; |
… | |
… | |
1817 | if (tile) |
1832 | if (tile) |
1818 | { |
1833 | { |
1819 | maptex tex = self->tex [tile]; |
1834 | maptex tex = self->tex [tile]; |
1820 | int px, py; |
1835 | int px, py; |
1821 | |
1836 | |
1822 | // suppressing texture state switches here |
|
|
1823 | // is only moderately effective, but worth the extra effort |
|
|
1824 | if (key.texname != tex.name) |
1837 | if (key.texname != tex.name) |
1825 | { |
1838 | { |
1826 | if (!tex.name) |
1839 | if (!tex.name) |
1827 | tex = self->tex [2]; /* missing, replace by noface */ |
1840 | tex = self->tex [2]; /* missing, replace by noface */ |
1828 | |
1841 | |
… | |
… | |
1911 | // go through all smoothlevels, lowest to highest, then draw. |
1924 | // go through all smoothlevels, lowest to highest, then draw. |
1912 | // this is basically counting sort |
1925 | // this is basically counting sort |
1913 | { |
1926 | { |
1914 | int w, b; |
1927 | int w, b; |
1915 | |
1928 | |
|
|
1929 | glEnable (GL_TEXTURE_2D); |
|
|
1930 | glBegin (GL_QUADS); |
1916 | for (w = 0; w < 256 / 32; ++w) |
1931 | for (w = 0; w < 256 / 32; ++w) |
1917 | { |
1932 | { |
1918 | uint32_t smask = smooth_level [w]; |
1933 | uint32_t smask = smooth_level [w]; |
1919 | if (smask) |
1934 | if (smask) |
1920 | for (b = 0; b < 32; ++b) |
1935 | for (b = 0; b < 32; ++b) |
… | |
… | |
1945 | { |
1960 | { |
1946 | // this time avoiding texture state changes |
1961 | // this time avoiding texture state changes |
1947 | // save gobs of state changes. |
1962 | // save gobs of state changes. |
1948 | if (key.texname != tex.name) |
1963 | if (key.texname != tex.name) |
1949 | { |
1964 | { |
|
|
1965 | glEnd (); |
1950 | key.texname = tex.name; |
1966 | glBindTexture (GL_TEXTURE_2D, key.texname = tex.name); |
1951 | arr = rc_array (rc, &key); |
1967 | glBegin (GL_QUADS); |
1952 | } |
1968 | } |
1953 | |
1969 | |
1954 | if (border) |
1970 | if (border) |
1955 | { |
1971 | { |
1956 | float ox = border * dx; |
1972 | float ox = border * dx; |
1957 | |
1973 | |
1958 | rc_t2f_v3f (arr, ox , 0.f , px , py , 0); |
1974 | glTexCoord2f (ox , 0.f ); glVertex2i (px , py ); |
1959 | rc_t2f_v3f (arr, ox , dy , px , py + T, 0); |
1975 | glTexCoord2f (ox , dy ); glVertex2i (px , py + T); |
1960 | rc_t2f_v3f (arr, ox + dx, dy , px + T, py + T, 0); |
1976 | glTexCoord2f (ox + dx, dy ); glVertex2i (px + T, py + T); |
1961 | rc_t2f_v3f (arr, ox + dx, 0.f , px + T, py , 0); |
1977 | glTexCoord2f (ox + dx, 0.f ); glVertex2i (px + T, py ); |
1962 | } |
1978 | } |
1963 | |
1979 | |
1964 | if (corner) |
1980 | if (corner) |
1965 | { |
1981 | { |
1966 | float ox = corner * dx; |
1982 | float ox = corner * dx; |
1967 | |
1983 | |
1968 | rc_t2f_v3f (arr, ox , dy , px , py , 0); |
1984 | glTexCoord2f (ox , dy ); glVertex2i (px , py ); |
1969 | rc_t2f_v3f (arr, ox , dy * 2.f, px , py + T, 0); |
1985 | glTexCoord2f (ox , dy * 2.f); glVertex2i (px , py + T); |
1970 | rc_t2f_v3f (arr, ox + dx, dy * 2.f, px + T, py + T, 0); |
1986 | glTexCoord2f (ox + dx, dy * 2.f); glVertex2i (px + T, py + T); |
1971 | rc_t2f_v3f (arr, ox + dx, dy , px + T, py , 0); |
1987 | glTexCoord2f (ox + dx, dy ); glVertex2i (px + T, py ); |
1972 | } |
1988 | } |
1973 | } |
1989 | } |
1974 | } |
1990 | } |
1975 | } |
1991 | } |
1976 | } |
1992 | } |
1977 | } |
1993 | } |
|
|
1994 | |
|
|
1995 | glEnd (); |
|
|
1996 | glDisable (GL_TEXTURE_2D); |
|
|
1997 | key.texname = -1; |
1978 | } |
1998 | } |
1979 | |
1999 | |
1980 | hv_clear (smooth); |
2000 | hv_clear (smooth); |
1981 | rc_draw (rc); |
|
|
1982 | rc_clear (rc); |
|
|
1983 | } |
2001 | } |
1984 | |
2002 | |
1985 | glDisable (GL_BLEND); |
2003 | glDisable (GL_BLEND); |
1986 | rc_free (rc); |
2004 | rc_free (rc); |
1987 | |
2005 | |
… | |
… | |
2240 | int x, y, z; |
2258 | int x, y, z; |
2241 | int w, h; |
2259 | int w, h; |
2242 | int x1, y1; |
2260 | int x1, y1; |
2243 | |
2261 | |
2244 | if (*data++ != 0) |
2262 | if (*data++ != 0) |
2245 | return; /* version mismatch */ |
2263 | XSRETURN_EMPTY; /* version mismatch */ |
2246 | |
2264 | |
2247 | w = *data++ << 8; w |= *data++; |
2265 | w = *data++ << 8; w |= *data++; |
2248 | h = *data++ << 8; h |= *data++; |
2266 | h = *data++ << 8; h |= *data++; |
2249 | |
2267 | |
2250 | // we need to do this 'cause we don't keep an absolute coord system for rows |
2268 | // we need to do this 'cause we don't keep an absolute coord system for rows |
… | |
… | |
2546 | const_iv (GL_INTENSITY), |
2564 | const_iv (GL_INTENSITY), |
2547 | const_iv (GL_LUMINANCE), |
2565 | const_iv (GL_LUMINANCE), |
2548 | const_iv (GL_LUMINANCE_ALPHA), |
2566 | const_iv (GL_LUMINANCE_ALPHA), |
2549 | const_iv (GL_FLOAT), |
2567 | const_iv (GL_FLOAT), |
2550 | const_iv (GL_UNSIGNED_INT_8_8_8_8_REV), |
2568 | const_iv (GL_UNSIGNED_INT_8_8_8_8_REV), |
|
|
2569 | const_iv (GL_COMPRESSED_ALPHA_ARB), |
|
|
2570 | const_iv (GL_COMPRESSED_LUMINANCE_ARB), |
|
|
2571 | const_iv (GL_COMPRESSED_LUMINANCE_ALPHA_ARB), |
|
|
2572 | const_iv (GL_COMPRESSED_INTENSITY_ARB), |
|
|
2573 | const_iv (GL_COMPRESSED_RGB_ARB), |
|
|
2574 | const_iv (GL_COMPRESSED_RGBA_ARB), |
2551 | const_iv (GL_COMPILE), |
2575 | const_iv (GL_COMPILE), |
2552 | const_iv (GL_PROXY_TEXTURE_1D), |
2576 | const_iv (GL_PROXY_TEXTURE_1D), |
2553 | const_iv (GL_PROXY_TEXTURE_2D), |
2577 | const_iv (GL_PROXY_TEXTURE_2D), |
2554 | const_iv (GL_TEXTURE_1D), |
2578 | const_iv (GL_TEXTURE_1D), |
2555 | const_iv (GL_TEXTURE_2D), |
2579 | const_iv (GL_TEXTURE_2D), |
… | |
… | |
2594 | const_iv (GL_PERSPECTIVE_CORRECTION_HINT), |
2618 | const_iv (GL_PERSPECTIVE_CORRECTION_HINT), |
2595 | const_iv (GL_POINT_SMOOTH_HINT), |
2619 | const_iv (GL_POINT_SMOOTH_HINT), |
2596 | const_iv (GL_LINE_SMOOTH_HINT), |
2620 | const_iv (GL_LINE_SMOOTH_HINT), |
2597 | const_iv (GL_POLYGON_SMOOTH_HINT), |
2621 | const_iv (GL_POLYGON_SMOOTH_HINT), |
2598 | const_iv (GL_GENERATE_MIPMAP_HINT), |
2622 | const_iv (GL_GENERATE_MIPMAP_HINT), |
|
|
2623 | const_iv (GL_TEXTURE_COMPRESSION_HINT), |
2599 | const_iv (GL_FASTEST), |
2624 | const_iv (GL_FASTEST), |
2600 | const_iv (GL_DONT_CARE), |
2625 | const_iv (GL_DONT_CARE), |
2601 | const_iv (GL_NICEST), |
2626 | const_iv (GL_NICEST), |
2602 | const_iv (GL_V2F), |
2627 | const_iv (GL_V2F), |
2603 | const_iv (GL_V3F), |
2628 | const_iv (GL_V3F), |
… | |
… | |
2611 | |
2636 | |
2612 | texture_av = newAV (); |
2637 | texture_av = newAV (); |
2613 | AvREAL_off (texture_av); |
2638 | AvREAL_off (texture_av); |
2614 | } |
2639 | } |
2615 | |
2640 | |
|
|
2641 | void |
|
|
2642 | disable_GL_EXT_blend_func_separate () |
|
|
2643 | CODE: |
|
|
2644 | gl.BlendFuncSeparate = 0; |
|
|
2645 | gl.BlendFuncSeparateEXT = 0; |
|
|
2646 | |
2616 | char * |
2647 | char * |
2617 | gl_vendor () |
2648 | gl_vendor () |
2618 | CODE: |
2649 | CODE: |
2619 | RETVAL = (char *)glGetString (GL_VENDOR); |
2650 | RETVAL = (char *)glGetString (GL_VENDOR); |
2620 | OUTPUT: |
2651 | OUTPUT: |
… | |
… | |
2741 | |
2772 | |
2742 | void glRect (float x1, float y1, float x2, float y2) |
2773 | void glRect (float x1, float y1, float x2, float y2) |
2743 | CODE: |
2774 | CODE: |
2744 | glRectf (x1, y1, x2, y2); |
2775 | glRectf (x1, y1, x2, y2); |
2745 | |
2776 | |
|
|
2777 | void glRect_lineloop (float x1, float y1, float x2, float y2) |
|
|
2778 | CODE: |
|
|
2779 | glBegin (GL_LINE_LOOP); |
|
|
2780 | glVertex2f (x1, y1); |
|
|
2781 | glVertex2f (x2, y1); |
|
|
2782 | glVertex2f (x2, y2); |
|
|
2783 | glVertex2f (x1, y2); |
|
|
2784 | glEnd (); |
|
|
2785 | |
2746 | PROTOTYPES: ENABLE |
2786 | PROTOTYPES: ENABLE |
2747 | |
2787 | |
2748 | void glBegin (int mode) |
2788 | void glBegin (int mode) |
2749 | |
2789 | |
2750 | void glEnd () |
2790 | void glEnd () |
… | |
… | |
2851 | NV x, y, w, h; |
2891 | NV x, y, w, h; |
2852 | SV *draw_x_sv = GvSV (draw_x_gv); |
2892 | SV *draw_x_sv = GvSV (draw_x_gv); |
2853 | SV *draw_y_sv = GvSV (draw_y_gv); |
2893 | SV *draw_y_sv = GvSV (draw_y_gv); |
2854 | SV *draw_w_sv = GvSV (draw_w_gv); |
2894 | SV *draw_w_sv = GvSV (draw_w_gv); |
2855 | SV *draw_h_sv = GvSV (draw_h_gv); |
2895 | SV *draw_h_sv = GvSV (draw_h_gv); |
2856 | SV *hover; |
|
|
2857 | double draw_x, draw_y, draw_w, draw_h; |
2896 | double draw_x, draw_y; |
2858 | |
2897 | |
2859 | if (!SvROK (self)) |
2898 | if (!SvROK (self)) |
2860 | croak ("CFPlus::Base::draw: %s not a reference", SvPV_nolen (self)); |
2899 | croak ("CFPlus::Base::draw: %s not a reference", SvPV_nolen (self)); |
2861 | |
2900 | |
2862 | hv = (HV *)SvRV (self); |
2901 | hv = (HV *)SvRV (self); |
… | |
… | |
2890 | { |
2929 | { |
2891 | svp = hv_fetch (hv, "can_hover", sizeof ("can_hover") - 1, 0); |
2930 | svp = hv_fetch (hv, "can_hover", sizeof ("can_hover") - 1, 0); |
2892 | |
2931 | |
2893 | if (svp && SvTRUE (*svp)) |
2932 | if (svp && SvTRUE (*svp)) |
2894 | { |
2933 | { |
2895 | glColor4f (1*0.2f, 0.8*0.2f, 0.5*0.2f, 0.2f); |
2934 | glColor4f (1.0f * 0.2f, 0.8f * 0.2f, 0.5f * 0.2f, 0.2f); |
2896 | glEnable (GL_BLEND); |
2935 | glEnable (GL_BLEND); |
2897 | glBlendFunc (GL_ONE, GL_ONE_MINUS_SRC_ALPHA); |
2936 | glBlendFunc (GL_ONE, GL_ONE_MINUS_SRC_ALPHA); |
2898 | glBegin (GL_QUADS); |
2937 | glBegin (GL_QUADS); |
2899 | glVertex2f (0, 0); |
2938 | glVertex2f (0, 0); |
2900 | glVertex2f (w, 0); |
2939 | glVertex2f (w, 0); |
… | |
… | |
2903 | glEnd (); |
2942 | glEnd (); |
2904 | glDisable (GL_BLEND); |
2943 | glDisable (GL_BLEND); |
2905 | } |
2944 | } |
2906 | } |
2945 | } |
2907 | #if 0 |
2946 | #if 0 |
2908 | if ($ENV{CFPLUS_DEBUG} & 1) { |
2947 | // draw borders, for debugging |
2909 | glPushMatrix; |
2948 | glPushMatrix (); |
2910 | glColor 1, 1, 0, 1; |
2949 | glColor4f (1., 1., 0., 1.); |
2911 | glTranslate 0.375, 0.375; |
2950 | glTranslatef (.5, .5, 0.); |
2912 | glBegin GL_LINE_LOOP; |
2951 | glBegin (GL_LINE_LOOP); |
2913 | glVertex 0 , 0; |
2952 | glVertex2f (0 , 0); |
2914 | glVertex $self->{w} - 1, 0; |
2953 | glVertex2f (w - 1, 0); |
2915 | glVertex $self->{w} - 1, $self->{h} - 1; |
2954 | glVertex2f (w - 1, h - 1); |
2916 | glVertex 0 , $self->{h} - 1; |
2955 | glVertex2f (0 , h - 1); |
2917 | glEnd; |
2956 | glEnd (); |
2918 | glPopMatrix; |
2957 | glPopMatrix (); |
2919 | #CFPlus::UI::Label->new (w => $self->{w}, h => $self->{h}, text => $self, fontsize => 0)->_draw; |
|
|
2920 | } |
|
|
2921 | #endif |
2958 | #endif |
2922 | PUSHMARK (SP); |
2959 | PUSHMARK (SP); |
2923 | XPUSHs (self); |
2960 | XPUSHs (self); |
2924 | PUTBACK; |
2961 | PUTBACK; |
2925 | call_method ("_draw", G_VOID | G_DISCARD); |
2962 | call_method ("_draw", G_VOID | G_DISCARD); |