… | |
… | |
150 | typedef struct cf_layout { |
150 | typedef struct cf_layout { |
151 | PangoLayout *pl; |
151 | PangoLayout *pl; |
152 | float r, g, b, a; // default color for rgba mode |
152 | float r, g, b, a; // default color for rgba mode |
153 | int base_height; |
153 | int base_height; |
154 | CFPlus__Font font; |
154 | CFPlus__Font font; |
|
|
155 | rc_t *rc; |
155 | } *CFPlus__Layout; |
156 | } *CFPlus__Layout; |
156 | |
157 | |
157 | static CFPlus__Font default_font; |
158 | static CFPlus__Font default_font; |
158 | static PangoContext *opengl_context; |
159 | static PangoContext *opengl_context; |
159 | static PangoFontMap *opengl_fontmap; |
160 | static PangoFontMap *opengl_fontmap; |
… | |
… | |
202 | |
203 | |
203 | typedef uint16_t tileid; |
204 | typedef uint16_t tileid; |
204 | typedef uint16_t faceid; |
205 | typedef uint16_t faceid; |
205 | |
206 | |
206 | typedef struct { |
207 | typedef struct { |
207 | int name; |
208 | GLuint name; |
208 | int w, h; |
209 | int w, h; |
209 | float s, t; |
210 | float s, t; |
210 | uint8_t r, g, b, a; |
211 | uint8_t r, g, b, a; |
211 | tileid smoothtile; |
212 | tileid smoothtile; |
212 | uint8_t smoothlevel; |
213 | uint8_t smoothlevel; |
… | |
… | |
714 | |
715 | |
715 | if (RETVAL) |
716 | if (RETVAL) |
716 | { |
717 | { |
717 | av_clear (texture_av); |
718 | av_clear (texture_av); |
718 | |
719 | |
719 | SDL_WM_SetCaption ("Crossfire+ Client " VERSION, "Crossfire+"); |
720 | SDL_WM_SetCaption ("Crossfire TRT Client " VERSION, "Crossfire TRT"); |
720 | #define GL_FUNC(ptr,name) gl.name = (ptr)SDL_GL_GetProcAddress ("gl" # name); |
721 | #define GL_FUNC(ptr,name) gl.name = (ptr)SDL_GL_GetProcAddress ("gl" # name); |
721 | #include "glfunc.h" |
722 | #include "glfunc.h" |
722 | #undef GL_FUNC |
723 | #undef GL_FUNC |
723 | } |
724 | } |
724 | } |
725 | } |
… | |
… | |
1036 | RETVAL->g = 1.; |
1037 | RETVAL->g = 1.; |
1037 | RETVAL->b = 1.; |
1038 | RETVAL->b = 1.; |
1038 | RETVAL->a = 1.; |
1039 | RETVAL->a = 1.; |
1039 | RETVAL->base_height = MIN_FONT_HEIGHT; |
1040 | RETVAL->base_height = MIN_FONT_HEIGHT; |
1040 | RETVAL->font = 0; |
1041 | RETVAL->font = 0; |
|
|
1042 | RETVAL->rc = rc_alloc (); |
1041 | |
1043 | |
1042 | pango_layout_set_wrap (RETVAL->pl, PANGO_WRAP_WORD_CHAR); |
1044 | pango_layout_set_wrap (RETVAL->pl, PANGO_WRAP_WORD_CHAR); |
1043 | layout_update_font (RETVAL); |
1045 | layout_update_font (RETVAL); |
1044 | OUTPUT: |
1046 | OUTPUT: |
1045 | RETVAL |
1047 | RETVAL |
1046 | |
1048 | |
1047 | void |
1049 | void |
1048 | DESTROY (CFPlus::Layout self) |
1050 | DESTROY (CFPlus::Layout self) |
1049 | CODE: |
1051 | CODE: |
1050 | g_object_unref (self->pl); |
1052 | g_object_unref (self->pl); |
|
|
1053 | rc_free (self->rc); |
1051 | Safefree (self); |
1054 | Safefree (self); |
1052 | |
1055 | |
1053 | void |
1056 | void |
1054 | set_text (CFPlus::Layout self, SV *text_) |
1057 | set_text (CFPlus::Layout self, SV *text_) |
1055 | CODE: |
1058 | CODE: |
… | |
… | |
1307 | } |
1310 | } |
1308 | } |
1311 | } |
1309 | |
1312 | |
1310 | void |
1313 | void |
1311 | render (CFPlus::Layout self, float x, float y, int flags = 0) |
1314 | render (CFPlus::Layout self, float x, float y, int flags = 0) |
1312 | PPCODE: |
1315 | CODE: |
|
|
1316 | rc_clear (self->rc); |
1313 | pango_opengl_render_layout_subpixel ( |
1317 | pango_opengl_render_layout_subpixel ( |
1314 | self->pl, |
1318 | self->pl, |
|
|
1319 | self->rc, |
1315 | x * PANGO_SCALE, y * PANGO_SCALE, |
1320 | x * PANGO_SCALE, y * PANGO_SCALE, |
1316 | self->r, self->g, self->b, self->a, |
1321 | self->r, self->g, self->b, self->a, |
1317 | flags |
1322 | flags |
1318 | ); |
1323 | ); |
|
|
1324 | // we assume that context_change actually clears/frees stuff |
|
|
1325 | // and does not do any recomputation... |
|
|
1326 | pango_layout_context_changed (self->pl); |
|
|
1327 | |
|
|
1328 | void |
|
|
1329 | draw (CFPlus::Layout self) |
|
|
1330 | CODE: |
|
|
1331 | { |
|
|
1332 | glEnable (GL_TEXTURE_2D); |
|
|
1333 | glTexEnvi (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); |
|
|
1334 | glEnable (GL_BLEND); |
|
|
1335 | gl_BlendFuncSeparate (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, |
|
|
1336 | GL_ONE , GL_ONE_MINUS_SRC_ALPHA); |
|
|
1337 | glEnable (GL_ALPHA_TEST); |
|
|
1338 | glAlphaFunc (GL_GREATER, 7.f / 255.f); |
|
|
1339 | |
|
|
1340 | rc_draw (self->rc); |
|
|
1341 | |
|
|
1342 | glDisable (GL_ALPHA_TEST); |
|
|
1343 | glDisable (GL_BLEND); |
|
|
1344 | glDisable (GL_TEXTURE_2D); |
|
|
1345 | } |
1319 | |
1346 | |
1320 | MODULE = CFPlus PACKAGE = CFPlus::Texture |
1347 | MODULE = CFPlus PACKAGE = CFPlus::Texture |
1321 | |
1348 | |
1322 | PROTOTYPES: ENABLE |
1349 | PROTOTYPES: ENABLE |
1323 | |
1350 | |
… | |
… | |
1718 | { |
1745 | { |
1719 | int x, y, z; |
1746 | int x, y, z; |
1720 | |
1747 | |
1721 | HV *smooth = (HV *)sv_2mortal ((SV *)newHV ()); |
1748 | HV *smooth = (HV *)sv_2mortal ((SV *)newHV ()); |
1722 | uint32_t smooth_level[256 / 32]; // one bit for every possible smooth level |
1749 | uint32_t smooth_level[256 / 32]; // one bit for every possible smooth level |
1723 | static uint8_t smooth_max[256][256]; // egad, fats and wasteful on memory (64k) |
1750 | static uint8_t smooth_max[256][256]; // egad, fast and wasteful on memory (64k) |
1724 | smooth_key skey; |
1751 | smooth_key skey; |
1725 | |
1752 | |
1726 | rc_t *rc = rc_alloc (); |
1753 | rc_t *rc = rc_alloc (); |
1727 | rc_key_t key; |
1754 | rc_key_t key; |
1728 | rc_array_t *arr; |
1755 | rc_array_t *arr; |
… | |
… | |
1790 | if (tile) |
1817 | if (tile) |
1791 | { |
1818 | { |
1792 | maptex tex = self->tex [tile]; |
1819 | maptex tex = self->tex [tile]; |
1793 | int px, py; |
1820 | int px, py; |
1794 | |
1821 | |
1795 | // suppressing texture state switches here |
|
|
1796 | // is only moderately effective, but worth the extra effort |
|
|
1797 | if (key.texname != tex.name) |
1822 | if (key.texname != tex.name) |
1798 | { |
1823 | { |
1799 | if (!tex.name) |
1824 | if (!tex.name) |
1800 | tex = self->tex [2]; /* missing, replace by noface */ |
1825 | tex = self->tex [2]; /* missing, replace by noface */ |
1801 | |
1826 | |
… | |
… | |
1876 | } |
1901 | } |
1877 | } |
1902 | } |
1878 | } |
1903 | } |
1879 | } |
1904 | } |
1880 | |
1905 | |
|
|
1906 | rc_draw (rc); |
|
|
1907 | rc_clear (rc); |
|
|
1908 | |
1881 | // go through all smoothlevels, lowest to highest, then draw. |
1909 | // go through all smoothlevels, lowest to highest, then draw. |
1882 | // this is basically counting sort |
1910 | // this is basically counting sort |
1883 | { |
1911 | { |
1884 | int w, b; |
1912 | int w, b; |
1885 | |
1913 | |
|
|
1914 | glEnable (GL_TEXTURE_2D); |
|
|
1915 | glBegin (GL_QUADS); |
1886 | for (w = 0; w < 256 / 32; ++w) |
1916 | for (w = 0; w < 256 / 32; ++w) |
1887 | { |
1917 | { |
1888 | uint32_t smask = smooth_level [w]; |
1918 | uint32_t smask = smooth_level [w]; |
1889 | if (smask) |
1919 | if (smask) |
1890 | for (b = 0; b < 32; ++b) |
1920 | for (b = 0; b < 32; ++b) |
… | |
… | |
1915 | { |
1945 | { |
1916 | // this time avoiding texture state changes |
1946 | // this time avoiding texture state changes |
1917 | // save gobs of state changes. |
1947 | // save gobs of state changes. |
1918 | if (key.texname != tex.name) |
1948 | if (key.texname != tex.name) |
1919 | { |
1949 | { |
|
|
1950 | glEnd (); |
1920 | key.texname = tex.name; |
1951 | glBindTexture (GL_TEXTURE_2D, key.texname = tex.name); |
1921 | arr = rc_array (rc, &key); |
1952 | glBegin (GL_QUADS); |
1922 | } |
1953 | } |
1923 | |
1954 | |
1924 | if (border) |
1955 | if (border) |
1925 | { |
1956 | { |
1926 | float ox = border * dx; |
1957 | float ox = border * dx; |
1927 | |
1958 | |
1928 | rc_t2f_v3f (arr, ox , 0.f , px , py , 0); |
1959 | glTexCoord2f (ox , 0.f ); glVertex2i (px , py ); |
1929 | rc_t2f_v3f (arr, ox , dy , px , py + T, 0); |
1960 | glTexCoord2f (ox , dy ); glVertex2i (px , py + T); |
1930 | rc_t2f_v3f (arr, ox + dx, dy , px + T, py + T, 0); |
1961 | glTexCoord2f (ox + dx, dy ); glVertex2i (px + T, py + T); |
1931 | rc_t2f_v3f (arr, ox + dx, 0.f , px + T, py , 0); |
1962 | glTexCoord2f (ox + dx, 0.f ); glVertex2i (px + T, py ); |
1932 | } |
1963 | } |
1933 | |
1964 | |
1934 | if (corner) |
1965 | if (corner) |
1935 | { |
1966 | { |
1936 | float ox = corner * dx; |
1967 | float ox = corner * dx; |
1937 | |
1968 | |
1938 | rc_t2f_v3f (arr, ox , dy , px , py , 0); |
1969 | glTexCoord2f (ox , dy ); glVertex2i (px , py ); |
1939 | rc_t2f_v3f (arr, ox , dy * 2.f, px , py + T, 0); |
1970 | glTexCoord2f (ox , dy * 2.f); glVertex2i (px , py + T); |
1940 | rc_t2f_v3f (arr, ox + dx, dy * 2.f, px + T, py + T, 0); |
1971 | glTexCoord2f (ox + dx, dy * 2.f); glVertex2i (px + T, py + T); |
1941 | rc_t2f_v3f (arr, ox + dx, dy , px + T, py , 0); |
1972 | glTexCoord2f (ox + dx, dy ); glVertex2i (px + T, py ); |
1942 | } |
1973 | } |
1943 | } |
1974 | } |
1944 | } |
1975 | } |
1945 | } |
1976 | } |
1946 | } |
1977 | } |
1947 | } |
1978 | } |
|
|
1979 | |
|
|
1980 | glEnd (); |
|
|
1981 | glDisable (GL_TEXTURE_2D); |
|
|
1982 | key.texname = -1; |
1948 | } |
1983 | } |
1949 | |
1984 | |
1950 | hv_clear (smooth); |
1985 | hv_clear (smooth); |
1951 | rc_draw (rc); |
|
|
1952 | rc_clear (rc); |
|
|
1953 | } |
1986 | } |
1954 | |
1987 | |
1955 | glDisable (GL_BLEND); |
1988 | glDisable (GL_BLEND); |
1956 | rc_free (rc); |
1989 | rc_free (rc); |
1957 | |
1990 | |
… | |
… | |
2210 | int x, y, z; |
2243 | int x, y, z; |
2211 | int w, h; |
2244 | int w, h; |
2212 | int x1, y1; |
2245 | int x1, y1; |
2213 | |
2246 | |
2214 | if (*data++ != 0) |
2247 | if (*data++ != 0) |
2215 | return; /* version mismatch */ |
2248 | XSRETURN_EMPTY; /* version mismatch */ |
2216 | |
2249 | |
2217 | w = *data++ << 8; w |= *data++; |
2250 | w = *data++ << 8; w |= *data++; |
2218 | h = *data++ << 8; h |= *data++; |
2251 | h = *data++ << 8; h |= *data++; |
2219 | |
2252 | |
2220 | // we need to do this 'cause we don't keep an absolute coord system for rows |
2253 | // we need to do this 'cause we don't keep an absolute coord system for rows |
… | |
… | |
2516 | const_iv (GL_INTENSITY), |
2549 | const_iv (GL_INTENSITY), |
2517 | const_iv (GL_LUMINANCE), |
2550 | const_iv (GL_LUMINANCE), |
2518 | const_iv (GL_LUMINANCE_ALPHA), |
2551 | const_iv (GL_LUMINANCE_ALPHA), |
2519 | const_iv (GL_FLOAT), |
2552 | const_iv (GL_FLOAT), |
2520 | const_iv (GL_UNSIGNED_INT_8_8_8_8_REV), |
2553 | const_iv (GL_UNSIGNED_INT_8_8_8_8_REV), |
|
|
2554 | const_iv (GL_COMPRESSED_ALPHA_ARB), |
|
|
2555 | const_iv (GL_COMPRESSED_LUMINANCE_ARB), |
|
|
2556 | const_iv (GL_COMPRESSED_LUMINANCE_ALPHA_ARB), |
|
|
2557 | const_iv (GL_COMPRESSED_INTENSITY_ARB), |
|
|
2558 | const_iv (GL_COMPRESSED_RGB_ARB), |
|
|
2559 | const_iv (GL_COMPRESSED_RGBA_ARB), |
2521 | const_iv (GL_COMPILE), |
2560 | const_iv (GL_COMPILE), |
2522 | const_iv (GL_PROXY_TEXTURE_1D), |
2561 | const_iv (GL_PROXY_TEXTURE_1D), |
2523 | const_iv (GL_PROXY_TEXTURE_2D), |
2562 | const_iv (GL_PROXY_TEXTURE_2D), |
2524 | const_iv (GL_TEXTURE_1D), |
2563 | const_iv (GL_TEXTURE_1D), |
2525 | const_iv (GL_TEXTURE_2D), |
2564 | const_iv (GL_TEXTURE_2D), |
… | |
… | |
2564 | const_iv (GL_PERSPECTIVE_CORRECTION_HINT), |
2603 | const_iv (GL_PERSPECTIVE_CORRECTION_HINT), |
2565 | const_iv (GL_POINT_SMOOTH_HINT), |
2604 | const_iv (GL_POINT_SMOOTH_HINT), |
2566 | const_iv (GL_LINE_SMOOTH_HINT), |
2605 | const_iv (GL_LINE_SMOOTH_HINT), |
2567 | const_iv (GL_POLYGON_SMOOTH_HINT), |
2606 | const_iv (GL_POLYGON_SMOOTH_HINT), |
2568 | const_iv (GL_GENERATE_MIPMAP_HINT), |
2607 | const_iv (GL_GENERATE_MIPMAP_HINT), |
|
|
2608 | const_iv (GL_TEXTURE_COMPRESSION_HINT), |
2569 | const_iv (GL_FASTEST), |
2609 | const_iv (GL_FASTEST), |
2570 | const_iv (GL_DONT_CARE), |
2610 | const_iv (GL_DONT_CARE), |
2571 | const_iv (GL_NICEST), |
2611 | const_iv (GL_NICEST), |
2572 | const_iv (GL_V2F), |
2612 | const_iv (GL_V2F), |
2573 | const_iv (GL_V3F), |
2613 | const_iv (GL_V3F), |
… | |
… | |
2581 | |
2621 | |
2582 | texture_av = newAV (); |
2622 | texture_av = newAV (); |
2583 | AvREAL_off (texture_av); |
2623 | AvREAL_off (texture_av); |
2584 | } |
2624 | } |
2585 | |
2625 | |
|
|
2626 | void |
|
|
2627 | disable_GL_EXT_blend_func_separate () |
|
|
2628 | CODE: |
|
|
2629 | gl.BlendFuncSeparate = 0; |
|
|
2630 | gl.BlendFuncSeparateEXT = 0; |
|
|
2631 | |
2586 | char * |
2632 | char * |
2587 | gl_vendor () |
2633 | gl_vendor () |
2588 | CODE: |
2634 | CODE: |
2589 | RETVAL = (char *)glGetString (GL_VENDOR); |
2635 | RETVAL = (char *)glGetString (GL_VENDOR); |
2590 | OUTPUT: |
2636 | OUTPUT: |
… | |
… | |
2711 | |
2757 | |
2712 | void glRect (float x1, float y1, float x2, float y2) |
2758 | void glRect (float x1, float y1, float x2, float y2) |
2713 | CODE: |
2759 | CODE: |
2714 | glRectf (x1, y1, x2, y2); |
2760 | glRectf (x1, y1, x2, y2); |
2715 | |
2761 | |
|
|
2762 | void glRect_lineloop (float x1, float y1, float x2, float y2) |
|
|
2763 | CODE: |
|
|
2764 | glBegin (GL_LINE_LOOP); |
|
|
2765 | glVertex2f (x1, y1); |
|
|
2766 | glVertex2f (x2, y1); |
|
|
2767 | glVertex2f (x2, y2); |
|
|
2768 | glVertex2f (x1, y2); |
|
|
2769 | glEnd (); |
|
|
2770 | |
2716 | PROTOTYPES: ENABLE |
2771 | PROTOTYPES: ENABLE |
2717 | |
2772 | |
2718 | void glBegin (int mode) |
2773 | void glBegin (int mode) |
2719 | |
2774 | |
2720 | void glEnd () |
2775 | void glEnd () |
… | |
… | |
2821 | NV x, y, w, h; |
2876 | NV x, y, w, h; |
2822 | SV *draw_x_sv = GvSV (draw_x_gv); |
2877 | SV *draw_x_sv = GvSV (draw_x_gv); |
2823 | SV *draw_y_sv = GvSV (draw_y_gv); |
2878 | SV *draw_y_sv = GvSV (draw_y_gv); |
2824 | SV *draw_w_sv = GvSV (draw_w_gv); |
2879 | SV *draw_w_sv = GvSV (draw_w_gv); |
2825 | SV *draw_h_sv = GvSV (draw_h_gv); |
2880 | SV *draw_h_sv = GvSV (draw_h_gv); |
2826 | SV *hover; |
|
|
2827 | double draw_x, draw_y, draw_w, draw_h; |
2881 | double draw_x, draw_y; |
2828 | |
2882 | |
2829 | if (!SvROK (self)) |
2883 | if (!SvROK (self)) |
2830 | croak ("CFPlus::Base::draw: %s not a reference", SvPV_nolen (self)); |
2884 | croak ("CFPlus::Base::draw: %s not a reference", SvPV_nolen (self)); |
2831 | |
2885 | |
2832 | hv = (HV *)SvRV (self); |
2886 | hv = (HV *)SvRV (self); |
… | |
… | |
2860 | { |
2914 | { |
2861 | svp = hv_fetch (hv, "can_hover", sizeof ("can_hover") - 1, 0); |
2915 | svp = hv_fetch (hv, "can_hover", sizeof ("can_hover") - 1, 0); |
2862 | |
2916 | |
2863 | if (svp && SvTRUE (*svp)) |
2917 | if (svp && SvTRUE (*svp)) |
2864 | { |
2918 | { |
2865 | glColor4f (1*0.2f, 0.8*0.2f, 0.5*0.2f, 0.2f); |
2919 | glColor4f (1.0f * 0.2f, 0.8f * 0.2f, 0.5f * 0.2f, 0.2f); |
2866 | glEnable (GL_BLEND); |
2920 | glEnable (GL_BLEND); |
2867 | glBlendFunc (GL_ONE, GL_ONE_MINUS_SRC_ALPHA); |
2921 | glBlendFunc (GL_ONE, GL_ONE_MINUS_SRC_ALPHA); |
2868 | glBegin (GL_QUADS); |
2922 | glBegin (GL_QUADS); |
2869 | glVertex2f (0, 0); |
2923 | glVertex2f (0, 0); |
2870 | glVertex2f (w, 0); |
2924 | glVertex2f (w, 0); |
… | |
… | |
2873 | glEnd (); |
2927 | glEnd (); |
2874 | glDisable (GL_BLEND); |
2928 | glDisable (GL_BLEND); |
2875 | } |
2929 | } |
2876 | } |
2930 | } |
2877 | #if 0 |
2931 | #if 0 |
2878 | if ($ENV{CFPLUS_DEBUG} & 1) { |
2932 | // draw borders, for debugging |
2879 | glPushMatrix; |
2933 | glPushMatrix (); |
2880 | glColor 1, 1, 0, 1; |
2934 | glColor4f (1., 1., 0., 1.); |
2881 | glTranslate 0.375, 0.375; |
2935 | glTranslatef (.5, .5, 0.); |
2882 | glBegin GL_LINE_LOOP; |
2936 | glBegin (GL_LINE_LOOP); |
2883 | glVertex 0 , 0; |
2937 | glVertex2f (0 , 0); |
2884 | glVertex $self->{w} - 1, 0; |
2938 | glVertex2f (w - 1, 0); |
2885 | glVertex $self->{w} - 1, $self->{h} - 1; |
2939 | glVertex2f (w - 1, h - 1); |
2886 | glVertex 0 , $self->{h} - 1; |
2940 | glVertex2f (0 , h - 1); |
2887 | glEnd; |
2941 | glEnd (); |
2888 | glPopMatrix; |
2942 | glPopMatrix (); |
2889 | #CFPlus::UI::Label->new (w => $self->{w}, h => $self->{h}, text => $self, fontsize => 0)->_draw; |
|
|
2890 | } |
|
|
2891 | #endif |
2943 | #endif |
2892 | PUSHMARK (SP); |
2944 | PUSHMARK (SP); |
2893 | XPUSHs (self); |
2945 | XPUSHs (self); |
2894 | PUTBACK; |
2946 | PUTBACK; |
2895 | call_method ("_draw", G_VOID | G_DISCARD); |
2947 | call_method ("_draw", G_VOID | G_DISCARD); |