… | |
… | |
17 | #include "perl.h" |
17 | #include "perl.h" |
18 | #include "XSUB.h" |
18 | #include "XSUB.h" |
19 | |
19 | |
20 | #ifdef _WIN32 |
20 | #ifdef _WIN32 |
21 | # undef pipe |
21 | # undef pipe |
|
|
22 | // microsoft vs. C |
|
|
23 | # define sqrtf(x) sqrt(x) |
|
|
24 | # define roundf(x) (int)(x) |
|
|
25 | # define atan2f(x,y) atan2(x,y) |
|
|
26 | # define M_PI 3.14159265f |
22 | #endif |
27 | #endif |
23 | |
28 | |
24 | #include <assert.h> |
29 | #include <assert.h> |
25 | #include <math.h> |
30 | #include <math.h> |
26 | #include <string.h> |
31 | #include <string.h> |
27 | #include <stdio.h> |
32 | #include <stdio.h> |
28 | #include <stdlib.h> |
33 | #include <stdlib.h> |
|
|
34 | |
|
|
35 | #define USE_RWOPS 1 // for SDL_mixer:LoadMUS_RW |
29 | |
36 | |
30 | #include <SDL.h> |
37 | #include <SDL.h> |
31 | #include <SDL_thread.h> |
38 | #include <SDL_thread.h> |
32 | #include <SDL_endian.h> |
39 | #include <SDL_endian.h> |
33 | #include <SDL_image.h> |
40 | #include <SDL_image.h> |
… | |
… | |
107 | av_push (texture_av, (SV *)(size_t)name); |
114 | av_push (texture_av, (SV *)(size_t)name); |
108 | glDeleteTextures (1, &name); |
115 | glDeleteTextures (1, &name); |
109 | } |
116 | } |
110 | |
117 | |
111 | #include "texcache.c" |
118 | #include "texcache.c" |
|
|
119 | #include "rendercache.c" |
112 | |
120 | |
113 | #include "pango-font.c" |
121 | #include "pango-font.c" |
114 | #include "pango-fontmap.c" |
122 | #include "pango-fontmap.c" |
115 | #include "pango-render.c" |
123 | #include "pango-render.c" |
116 | |
124 | |
|
|
125 | typedef IV CFPlus__Channel; |
|
|
126 | typedef SDL_RWops *CFPlus__RW; |
117 | typedef Mix_Chunk *CFPlus__MixChunk; |
127 | typedef Mix_Chunk *CFPlus__MixChunk; |
118 | typedef Mix_Music *CFPlus__MixMusic; |
128 | typedef Mix_Music *CFPlus__MixMusic; |
119 | |
129 | |
120 | typedef PangoFontDescription *CFPlus__Font; |
130 | typedef PangoFontDescription *CFPlus__Font; |
121 | |
131 | |
… | |
… | |
140 | typedef struct cf_layout { |
150 | typedef struct cf_layout { |
141 | PangoLayout *pl; |
151 | PangoLayout *pl; |
142 | float r, g, b, a; // default color for rgba mode |
152 | float r, g, b, a; // default color for rgba mode |
143 | int base_height; |
153 | int base_height; |
144 | CFPlus__Font font; |
154 | CFPlus__Font font; |
|
|
155 | rc_t *rc; |
145 | } *CFPlus__Layout; |
156 | } *CFPlus__Layout; |
146 | |
157 | |
147 | static CFPlus__Font default_font; |
158 | static CFPlus__Font default_font; |
148 | static PangoContext *opengl_context; |
159 | static PangoContext *opengl_context; |
149 | static PangoFontMap *opengl_fontmap; |
160 | static PangoFontMap *opengl_fontmap; |
… | |
… | |
192 | |
203 | |
193 | typedef uint16_t tileid; |
204 | typedef uint16_t tileid; |
194 | typedef uint16_t faceid; |
205 | typedef uint16_t faceid; |
195 | |
206 | |
196 | typedef struct { |
207 | typedef struct { |
197 | int name; |
208 | GLuint name; |
198 | int w, h; |
209 | int w, h; |
199 | float s, t; |
210 | float s, t; |
200 | uint8_t r, g, b, a; |
211 | uint8_t r, g, b, a; |
201 | tileid smoothtile; |
212 | tileid smoothtile; |
202 | uint8_t smoothlevel; |
213 | uint8_t smoothlevel; |
… | |
… | |
434 | /* SDL should provide this, really. */ |
445 | /* SDL should provide this, really. */ |
435 | #define SDLK_MODIFIER_MIN 300 |
446 | #define SDLK_MODIFIER_MIN 300 |
436 | #define SDLK_MODIFIER_MAX 314 |
447 | #define SDLK_MODIFIER_MAX 314 |
437 | |
448 | |
438 | /******************************************************************************/ |
449 | /******************************************************************************/ |
|
|
450 | |
|
|
451 | static GV *draw_x_gv, *draw_y_gv, *draw_w_gv, *draw_h_gv; |
|
|
452 | static GV *hover_gv; |
439 | |
453 | |
440 | static int |
454 | static int |
441 | within_widget (SV *widget, NV x, NV y) |
455 | within_widget (SV *widget, NV x, NV y) |
442 | { |
456 | { |
443 | HV *self; |
457 | HV *self; |
… | |
… | |
701 | |
715 | |
702 | if (RETVAL) |
716 | if (RETVAL) |
703 | { |
717 | { |
704 | av_clear (texture_av); |
718 | av_clear (texture_av); |
705 | |
719 | |
706 | SDL_WM_SetCaption ("Crossfire+ Client " VERSION, "Crossfire+"); |
720 | SDL_WM_SetCaption ("Crossfire TRT Client " VERSION, "Crossfire TRT"); |
707 | #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); |
708 | #include "glfunc.h" |
722 | #include "glfunc.h" |
709 | #undef GL_FUNC |
723 | #undef GL_FUNC |
710 | } |
724 | } |
711 | } |
725 | } |
… | |
… | |
797 | XPUSHs (sv_2mortal (sv_bless (newRV_noinc ((SV *)hv), gv_stashpv ("CFPlus::UI::Event", 1)))); |
811 | XPUSHs (sv_2mortal (sv_bless (newRV_noinc ((SV *)hv), gv_stashpv ("CFPlus::UI::Event", 1)))); |
798 | } |
812 | } |
799 | } |
813 | } |
800 | |
814 | |
801 | int |
815 | int |
802 | Mix_OpenAudio (int frequency = 48000, int format = MIX_DEFAULT_FORMAT, int channels = 1, int chunksize = 2048) |
816 | Mix_OpenAudio (int frequency = 44100, int format = MIX_DEFAULT_FORMAT, int channels = 2, int chunksize = 1024) |
803 | POSTCALL: |
817 | POSTCALL: |
804 | Mix_HookMusicFinished (music_finished); |
818 | Mix_HookMusicFinished (music_finished); |
805 | Mix_ChannelFinished (channel_finished); |
819 | Mix_ChannelFinished (channel_finished); |
806 | |
820 | |
807 | void |
821 | void |
808 | Mix_CloseAudio () |
822 | Mix_CloseAudio () |
809 | |
823 | |
810 | int |
824 | int |
811 | Mix_AllocateChannels (int numchans = -1) |
825 | Mix_AllocateChannels (int numchans = -1) |
|
|
826 | |
|
|
827 | const char * |
|
|
828 | Mix_GetError () |
812 | |
829 | |
813 | void |
830 | void |
814 | lowdelay (int fd, int val = 1) |
831 | lowdelay (int fd, int val = 1) |
815 | CODE: |
832 | CODE: |
816 | setsockopt (fd, IPPROTO_TCP, TCP_NODELAY, (void *)&val, sizeof (val)); |
833 | setsockopt (fd, IPPROTO_TCP, TCP_NODELAY, (void *)&val, sizeof (val)); |
… | |
… | |
858 | STRLEN image_len; |
875 | STRLEN image_len; |
859 | char *image = (char *)SvPVbyte (image_, image_len); |
876 | char *image = (char *)SvPVbyte (image_, image_len); |
860 | SDL_Surface *surface, *surface2; |
877 | SDL_Surface *surface, *surface2; |
861 | SDL_PixelFormat fmt; |
878 | SDL_PixelFormat fmt; |
862 | SDL_RWops *rw = ix |
879 | SDL_RWops *rw = ix |
863 | ? SDL_RWFromFile (image, "r") |
880 | ? SDL_RWFromFile (image, "rb") |
864 | : SDL_RWFromConstMem (image, image_len); |
881 | : SDL_RWFromConstMem (image, image_len); |
865 | |
882 | |
866 | if (!rw) |
883 | if (!rw) |
867 | croak ("load_image: %s", SDL_GetError ()); |
884 | croak ("load_image: %s", SDL_GetError ()); |
868 | |
885 | |
… | |
… | |
1020 | RETVAL->g = 1.; |
1037 | RETVAL->g = 1.; |
1021 | RETVAL->b = 1.; |
1038 | RETVAL->b = 1.; |
1022 | RETVAL->a = 1.; |
1039 | RETVAL->a = 1.; |
1023 | RETVAL->base_height = MIN_FONT_HEIGHT; |
1040 | RETVAL->base_height = MIN_FONT_HEIGHT; |
1024 | RETVAL->font = 0; |
1041 | RETVAL->font = 0; |
|
|
1042 | RETVAL->rc = rc_alloc (); |
1025 | |
1043 | |
1026 | pango_layout_set_wrap (RETVAL->pl, PANGO_WRAP_WORD_CHAR); |
1044 | pango_layout_set_wrap (RETVAL->pl, PANGO_WRAP_WORD_CHAR); |
1027 | layout_update_font (RETVAL); |
1045 | layout_update_font (RETVAL); |
1028 | OUTPUT: |
1046 | OUTPUT: |
1029 | RETVAL |
1047 | RETVAL |
1030 | |
1048 | |
1031 | void |
1049 | void |
1032 | DESTROY (CFPlus::Layout self) |
1050 | DESTROY (CFPlus::Layout self) |
1033 | CODE: |
1051 | CODE: |
1034 | g_object_unref (self->pl); |
1052 | g_object_unref (self->pl); |
|
|
1053 | rc_free (self->rc); |
1035 | Safefree (self); |
1054 | Safefree (self); |
1036 | |
1055 | |
1037 | void |
1056 | void |
1038 | set_text (CFPlus::Layout self, SV *text_) |
1057 | set_text (CFPlus::Layout self, SV *text_) |
1039 | CODE: |
1058 | CODE: |
… | |
… | |
1291 | } |
1310 | } |
1292 | } |
1311 | } |
1293 | |
1312 | |
1294 | void |
1313 | void |
1295 | render (CFPlus::Layout self, float x, float y, int flags = 0) |
1314 | render (CFPlus::Layout self, float x, float y, int flags = 0) |
1296 | PPCODE: |
1315 | CODE: |
|
|
1316 | rc_clear (self->rc); |
1297 | pango_opengl_render_layout_subpixel ( |
1317 | pango_opengl_render_layout_subpixel ( |
1298 | self->pl, |
1318 | self->pl, |
|
|
1319 | self->rc, |
1299 | x * PANGO_SCALE, y * PANGO_SCALE, |
1320 | x * PANGO_SCALE, y * PANGO_SCALE, |
1300 | self->r, self->g, self->b, self->a, |
1321 | self->r, self->g, self->b, self->a, |
1301 | flags |
1322 | flags |
1302 | ); |
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 | } |
1303 | |
1346 | |
1304 | MODULE = CFPlus PACKAGE = CFPlus::Texture |
1347 | MODULE = CFPlus PACKAGE = CFPlus::Texture |
1305 | |
1348 | |
1306 | PROTOTYPES: ENABLE |
1349 | PROTOTYPES: ENABLE |
1307 | |
1350 | |
… | |
… | |
1339 | { |
1382 | { |
1340 | HV *hv = (HV *)SvRV (self); |
1383 | HV *hv = (HV *)SvRV (self); |
1341 | float s = SvNV (*hv_fetch (hv, "s", 1, 1)); |
1384 | float s = SvNV (*hv_fetch (hv, "s", 1, 1)); |
1342 | float t = SvNV (*hv_fetch (hv, "t", 1, 1)); |
1385 | float t = SvNV (*hv_fetch (hv, "t", 1, 1)); |
1343 | int name = SvIV (*hv_fetch (hv, "name", 4, 1)); |
1386 | int name = SvIV (*hv_fetch (hv, "name", 4, 1)); |
|
|
1387 | |
|
|
1388 | if (name <= 0) |
|
|
1389 | XSRETURN_EMPTY; |
1344 | |
1390 | |
1345 | if (items < 5) |
1391 | if (items < 5) |
1346 | { |
1392 | { |
1347 | w = SvNV (*hv_fetch (hv, "w", 1, 1)); |
1393 | w = SvNV (*hv_fetch (hv, "w", 1, 1)); |
1348 | h = SvNV (*hv_fetch (hv, "h", 1, 1)); |
1394 | h = SvNV (*hv_fetch (hv, "h", 1, 1)); |
… | |
… | |
1537 | self->rows += MAP_EXTEND_Y; |
1583 | self->rows += MAP_EXTEND_Y; |
1538 | self->y += MAP_EXTEND_Y; |
1584 | self->y += MAP_EXTEND_Y; |
1539 | } |
1585 | } |
1540 | } |
1586 | } |
1541 | |
1587 | |
1542 | void |
1588 | SV * |
1543 | map1a_update (CFPlus::Map self, SV *data_, int extmap) |
1589 | map1a_update (CFPlus::Map self, SV *data_, int extmap) |
1544 | CODE: |
1590 | CODE: |
1545 | { |
1591 | { |
1546 | uint8_t *data = (uint8_t *)SvPVbyte_nolen (data_); |
1592 | uint8_t *data = (uint8_t *)SvPVbyte_nolen (data_); |
1547 | uint8_t *data_end = (uint8_t *)SvEND (data_); |
1593 | uint8_t *data_end = (uint8_t *)SvEND (data_); |
1548 | mapcell *cell; |
1594 | mapcell *cell; |
1549 | int x, y, flags; |
1595 | int x, y, z, flags; |
|
|
1596 | AV *missing = newAV (); |
|
|
1597 | RETVAL = newRV_noinc ((SV *)missing); |
1550 | |
1598 | |
1551 | while (data < data_end - 1) |
1599 | while (data < data_end - 1) |
1552 | { |
1600 | { |
1553 | flags = (data [0] << 8) + data [1]; data += 2; |
1601 | flags = (data [0] << 8) + data [1]; data += 2; |
1554 | |
1602 | |
… | |
… | |
1605 | } |
1653 | } |
1606 | else |
1654 | else |
1607 | cell->darkness = *data++ + 1; |
1655 | cell->darkness = *data++ + 1; |
1608 | } |
1656 | } |
1609 | |
1657 | |
|
|
1658 | for (z = 0; z <= 2; ++z) |
1610 | if (flags & 4) |
1659 | if (flags & (4 >> z)) |
1611 | { |
1660 | { |
1612 | faceid face = (data [0] << 8) + data [1]; data += 2; |
1661 | faceid face = (data [0] << 8) + data [1]; data += 2; |
1613 | need_facenum (self, face); |
1662 | need_facenum (self, face); |
1614 | cell->tile [0] = self->face2tile [face]; |
1663 | cell->tile [z] = self->face2tile [face]; |
|
|
1664 | |
|
|
1665 | if (cell->tile [z]) |
|
|
1666 | { |
|
|
1667 | maptex *tex = self->tex + cell->tile [z]; |
|
|
1668 | if (!tex->name) |
|
|
1669 | av_push (missing, newSViv (cell->tile [z])); |
|
|
1670 | |
|
|
1671 | if (tex->smoothtile) |
|
|
1672 | { |
|
|
1673 | maptex *smooth = self->tex + tex->smoothtile; |
|
|
1674 | if (!smooth->name) |
|
|
1675 | av_push (missing, newSViv (tex->smoothtile)); |
|
|
1676 | } |
|
|
1677 | } |
1615 | } |
1678 | } |
1616 | |
|
|
1617 | if (flags & 2) |
|
|
1618 | { |
|
|
1619 | faceid face = (data [0] << 8) + data [1]; data += 2; |
|
|
1620 | need_facenum (self, face); |
|
|
1621 | cell->tile [1] = self->face2tile [face]; |
|
|
1622 | } |
|
|
1623 | |
|
|
1624 | if (flags & 1) |
|
|
1625 | { |
|
|
1626 | faceid face = (data [0] << 8) + data [1]; data += 2; |
|
|
1627 | need_facenum (self, face); |
|
|
1628 | cell->tile [2] = self->face2tile [face]; |
|
|
1629 | } |
|
|
1630 | } |
1679 | } |
1631 | else |
1680 | else |
1632 | cell->darkness = 0; |
1681 | cell->darkness = 0; |
1633 | } |
1682 | } |
1634 | } |
1683 | } |
|
|
1684 | OUTPUT: |
|
|
1685 | RETVAL |
1635 | |
1686 | |
1636 | SV * |
1687 | SV * |
1637 | mapmap (CFPlus::Map self, int x0, int y0, int w, int h) |
1688 | mapmap (CFPlus::Map self, int x0, int y0, int w, int h) |
1638 | CODE: |
1689 | CODE: |
1639 | { |
1690 | { |
… | |
… | |
1690 | |
1741 | |
1691 | void |
1742 | void |
1692 | draw (CFPlus::Map self, int mx, int my, int sw, int sh, int T) |
1743 | draw (CFPlus::Map self, int mx, int my, int sw, int sh, int T) |
1693 | CODE: |
1744 | CODE: |
1694 | { |
1745 | { |
|
|
1746 | int x, y, z; |
|
|
1747 | |
1695 | HV *smooth = (HV *)sv_2mortal ((SV *)newHV ()); |
1748 | HV *smooth = (HV *)sv_2mortal ((SV *)newHV ()); |
1696 | 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 |
1697 | 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) |
1698 | smooth_key skey; |
1751 | smooth_key skey; |
1699 | int x, y, z; |
1752 | |
1700 | int last_name; |
1753 | rc_t *rc = rc_alloc (); |
|
|
1754 | rc_key_t key; |
|
|
1755 | rc_array_t *arr; |
1701 | |
1756 | |
1702 | // thats current max. sorry. |
1757 | // thats current max. sorry. |
1703 | if (sw > 255) sw = 255; |
1758 | if (sw > 255) sw = 255; |
1704 | if (sh > 255) sh = 255; |
1759 | if (sh > 255) sh = 255; |
1705 | |
1760 | |
1706 | // clear key, in case of extra padding |
1761 | // clear key, in case of extra padding |
1707 | memset (&skey, 0, sizeof (skey)); |
1762 | memset (&skey, 0, sizeof (skey)); |
1708 | |
1763 | |
1709 | glColor4ub (255, 255, 255, 255); |
1764 | memset (&key, 0, sizeof (key)); |
1710 | |
1765 | key.r = 255; |
1711 | glEnable (GL_BLEND); |
1766 | key.g = 255; |
1712 | glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); |
1767 | key.b = 255; |
1713 | glEnable (GL_TEXTURE_2D); |
1768 | key.a = 255; |
1714 | glTexEnvi (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE); |
1769 | key.mode = GL_QUADS; |
1715 | |
1770 | key.format = GL_T2F_V3F; |
1716 | glBegin (GL_QUADS); |
1771 | key.texname = -1; |
1717 | |
|
|
1718 | last_name = 0; |
|
|
1719 | |
1772 | |
1720 | mx += self->x; |
1773 | mx += self->x; |
1721 | my += self->y; |
1774 | my += self->y; |
1722 | |
1775 | |
1723 | // first pass: determine smooth_max |
1776 | // first pass: determine smooth_max |
… | |
… | |
1739 | MAX (self->tex [cell->tile [0]].smoothlevel, |
1792 | MAX (self->tex [cell->tile [0]].smoothlevel, |
1740 | MAX (self->tex [cell->tile [1]].smoothlevel, |
1793 | MAX (self->tex [cell->tile [1]].smoothlevel, |
1741 | self->tex [cell->tile [2]].smoothlevel)); |
1794 | self->tex [cell->tile [2]].smoothlevel)); |
1742 | } |
1795 | } |
1743 | } |
1796 | } |
|
|
1797 | |
|
|
1798 | glEnable (GL_BLEND); |
|
|
1799 | glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); |
|
|
1800 | glTexEnvi (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE); |
1744 | |
1801 | |
1745 | for (z = 0; z <= 2; z++) |
1802 | for (z = 0; z <= 2; z++) |
1746 | { |
1803 | { |
1747 | memset (smooth_level, 0, sizeof (smooth_level)); |
1804 | memset (smooth_level, 0, sizeof (smooth_level)); |
1748 | |
1805 | |
… | |
… | |
1758 | tileid tile = cell->tile [z]; |
1815 | tileid tile = cell->tile [z]; |
1759 | |
1816 | |
1760 | if (tile) |
1817 | if (tile) |
1761 | { |
1818 | { |
1762 | maptex tex = self->tex [tile]; |
1819 | maptex tex = self->tex [tile]; |
1763 | int px = (x + 1) * T - tex.w; |
1820 | int px, py; |
1764 | int py = (y + 1) * T - tex.h; |
|
|
1765 | |
1821 | |
1766 | // suppressing texture state switches here |
|
|
1767 | // is only moderately effective, but worth the extra effort |
|
|
1768 | if (last_name != tex.name) |
1822 | if (key.texname != tex.name) |
1769 | { |
1823 | { |
1770 | if (!tex.name) |
1824 | if (!tex.name) |
1771 | tex = self->tex [2]; /* missing, replace by noface */ |
1825 | tex = self->tex [2]; /* missing, replace by noface */ |
1772 | |
1826 | |
1773 | glEnd (); |
1827 | key.texname = tex.name; |
1774 | glBindTexture (GL_TEXTURE_2D, last_name = tex.name); |
1828 | arr = rc_array (rc, &key); |
1775 | glBegin (GL_QUADS); |
|
|
1776 | } |
1829 | } |
1777 | |
1830 | |
1778 | glTexCoord2f (0 , 0 ); glVertex2f (px , py ); |
1831 | px = (x + 1) * T - tex.w; |
|
|
1832 | py = (y + 1) * T - tex.h; |
|
|
1833 | |
|
|
1834 | rc_t2f_v3f (arr, 0 , 0 , px , py , 0); |
1779 | glTexCoord2f (0 , tex.t); glVertex2f (px , py + tex.h); |
1835 | rc_t2f_v3f (arr, 0 , tex.t, px , py + tex.h, 0); |
1780 | glTexCoord2f (tex.s, tex.t); glVertex2f (px + tex.w, py + tex.h); |
1836 | rc_t2f_v3f (arr, tex.s, tex.t, px + tex.w, py + tex.h, 0); |
1781 | glTexCoord2f (tex.s, 0 ); glVertex2f (px + tex.w, py ); |
1837 | rc_t2f_v3f (arr, tex.s, 0 , px + tex.w, py , 0); |
1782 | |
1838 | |
1783 | if (cell->flags && z == 2) |
1839 | if (cell->flags && z == 2) |
1784 | { |
1840 | { |
|
|
1841 | // overlays such as the speech bubble, probably more to come |
1785 | if (cell->flags & 1) |
1842 | if (cell->flags & 1) |
1786 | { |
1843 | { |
1787 | maptex tex = self->tex [1]; |
1844 | maptex tex = self->tex [1]; |
1788 | int px = x * T + T * 2 / 32; |
1845 | int px = x * T + T * 2 / 32; |
1789 | int py = y * T - T * 6 / 32; |
1846 | int py = y * T - T * 6 / 32; |
1790 | |
1847 | |
|
|
1848 | if (tex.name) |
1791 | glEnd (); |
1849 | { |
1792 | glBindTexture (GL_TEXTURE_2D, last_name = tex.name); |
1850 | if (key.texname != tex.name) |
|
|
1851 | { |
|
|
1852 | key.texname = tex.name; |
|
|
1853 | arr = rc_array (rc, &key); |
|
|
1854 | } |
|
|
1855 | |
|
|
1856 | rc_t2f_v3f (arr, 0 , 0 , px , py , 0); |
|
|
1857 | rc_t2f_v3f (arr, 0 , tex.t, px , py + T, 0); |
|
|
1858 | rc_t2f_v3f (arr, tex.s, tex.t, px + T, py + T, 0); |
|
|
1859 | rc_t2f_v3f (arr, tex.s, 0 , px + T, py , 0); |
1793 | glBegin (GL_QUADS); |
1860 | } |
1794 | |
|
|
1795 | glTexCoord2f (0 , 0 ); glVertex2f (px , py ); |
|
|
1796 | glTexCoord2f (0 , tex.t); glVertex2f (px , py + T); |
|
|
1797 | glTexCoord2f (tex.s, tex.t); glVertex2f (px + T, py + T); |
|
|
1798 | glTexCoord2f (tex.s, 0 ); glVertex2f (px + T, py ); |
|
|
1799 | } |
1861 | } |
1800 | } |
1862 | } |
1801 | |
1863 | |
1802 | // update smooth hash |
1864 | // update smooth hash |
1803 | if (tex.smoothtile) |
1865 | if (tex.smoothtile) |
… | |
… | |
1839 | } |
1901 | } |
1840 | } |
1902 | } |
1841 | } |
1903 | } |
1842 | } |
1904 | } |
1843 | |
1905 | |
|
|
1906 | rc_draw (rc); |
|
|
1907 | rc_clear (rc); |
|
|
1908 | |
1844 | // go through all smoothlevels, lowest to highest, then draw. |
1909 | // go through all smoothlevels, lowest to highest, then draw. |
1845 | // this is basically counting sort |
1910 | // this is basically counting sort |
1846 | { |
1911 | { |
1847 | int w, b; |
1912 | int w, b; |
1848 | |
1913 | |
|
|
1914 | glEnable (GL_TEXTURE_2D); |
|
|
1915 | glBegin (GL_QUADS); |
1849 | for (w = 0; w < 256 / 32; ++w) |
1916 | for (w = 0; w < 256 / 32; ++w) |
1850 | { |
1917 | { |
1851 | uint32_t smask = smooth_level [w]; |
1918 | uint32_t smask = smooth_level [w]; |
1852 | if (smask) |
1919 | if (smask) |
1853 | for (b = 0; b < 32; ++b) |
1920 | for (b = 0; b < 32; ++b) |
… | |
… | |
1872 | int border = bits & 15; |
1939 | int border = bits & 15; |
1873 | int corner = (bits >> 8) & ~(bits >> 4) & 15; |
1940 | int corner = (bits >> 8) & ~(bits >> 4) & 15; |
1874 | float dx = tex.s * .0625f; // 16 images/row |
1941 | float dx = tex.s * .0625f; // 16 images/row |
1875 | float dy = tex.t * .5f ; // 2 images/column |
1942 | float dy = tex.t * .5f ; // 2 images/column |
1876 | |
1943 | |
1877 | // this time naively avoiding texture state changes |
|
|
1878 | // save gobs of state changes. |
|
|
1879 | if (last_name != tex.name) |
1944 | if (tex.name) |
1880 | { |
1945 | { |
|
|
1946 | // this time avoiding texture state changes |
|
|
1947 | // save gobs of state changes. |
1881 | if (!tex.name) |
1948 | if (key.texname != tex.name) |
1882 | continue; // smoothing not yet available |
1949 | { |
1883 | |
|
|
1884 | glEnd (); |
1950 | glEnd (); |
1885 | glBindTexture (GL_TEXTURE_2D, last_name = tex.name); |
1951 | glBindTexture (GL_TEXTURE_2D, key.texname = tex.name); |
1886 | glBegin (GL_QUADS); |
1952 | glBegin (GL_QUADS); |
1887 | } |
1953 | } |
1888 | |
1954 | |
1889 | if (border) |
1955 | if (border) |
1890 | { |
1956 | { |
1891 | float ox = border * dx; |
1957 | float ox = border * dx; |
1892 | |
1958 | |
1893 | glTexCoord2f (ox , 0.f ); glVertex2f (px , py ); |
1959 | glTexCoord2f (ox , 0.f ); glVertex2i (px , py ); |
1894 | glTexCoord2f (ox , dy ); glVertex2f (px , py + T); |
1960 | glTexCoord2f (ox , dy ); glVertex2i (px , py + T); |
1895 | glTexCoord2f (ox + dx, dy ); glVertex2f (px + T, py + T); |
1961 | glTexCoord2f (ox + dx, dy ); glVertex2i (px + T, py + T); |
1896 | glTexCoord2f (ox + dx, 0.f ); glVertex2f (px + T, py ); |
1962 | glTexCoord2f (ox + dx, 0.f ); glVertex2i (px + T, py ); |
1897 | } |
1963 | } |
1898 | |
1964 | |
1899 | if (corner) |
1965 | if (corner) |
1900 | { |
1966 | { |
1901 | float ox = corner * dx; |
1967 | float ox = corner * dx; |
1902 | |
1968 | |
1903 | glTexCoord2f (ox , dy ); glVertex2f (px , py ); |
1969 | glTexCoord2f (ox , dy ); glVertex2i (px , py ); |
1904 | glTexCoord2f (ox , dy * 2.f); glVertex2f (px , py + T); |
1970 | glTexCoord2f (ox , dy * 2.f); glVertex2i (px , py + T); |
1905 | glTexCoord2f (ox + dx, dy * 2.f); glVertex2f (px + T, py + T); |
1971 | glTexCoord2f (ox + dx, dy * 2.f); glVertex2i (px + T, py + T); |
1906 | glTexCoord2f (ox + dx, dy ); glVertex2f (px + T, py ); |
1972 | glTexCoord2f (ox + dx, dy ); glVertex2i (px + T, py ); |
|
|
1973 | } |
1907 | } |
1974 | } |
1908 | } |
1975 | } |
1909 | } |
1976 | } |
1910 | } |
1977 | } |
1911 | } |
1978 | } |
|
|
1979 | |
|
|
1980 | glEnd (); |
|
|
1981 | glDisable (GL_TEXTURE_2D); |
|
|
1982 | key.texname = -1; |
1912 | } |
1983 | } |
1913 | |
1984 | |
1914 | hv_clear (smooth); |
1985 | hv_clear (smooth); |
1915 | } |
1986 | } |
1916 | |
1987 | |
1917 | glEnd (); |
|
|
1918 | |
|
|
1919 | glDisable (GL_TEXTURE_2D); |
|
|
1920 | glDisable (GL_BLEND); |
1988 | glDisable (GL_BLEND); |
|
|
1989 | rc_free (rc); |
1921 | |
1990 | |
1922 | // top layer: overlays such as the health bar |
1991 | // top layer: overlays such as the health bar |
1923 | for (y = 0; y < sh; y++) |
1992 | for (y = 0; y < sh; y++) |
1924 | if (0 <= y + my && y + my < self->rows) |
1993 | if (0 <= y + my && y + my < self->rows) |
1925 | { |
1994 | { |
… | |
… | |
2174 | int x, y, z; |
2243 | int x, y, z; |
2175 | int w, h; |
2244 | int w, h; |
2176 | int x1, y1; |
2245 | int x1, y1; |
2177 | |
2246 | |
2178 | if (*data++ != 0) |
2247 | if (*data++ != 0) |
2179 | return; /* version mismatch */ |
2248 | XSRETURN_EMPTY; /* version mismatch */ |
2180 | |
2249 | |
2181 | w = *data++ << 8; w |= *data++; |
2250 | w = *data++ << 8; w |= *data++; |
2182 | h = *data++ << 8; h |= *data++; |
2251 | h = *data++ << 8; h |= *data++; |
2183 | |
2252 | |
2184 | // 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 |
… | |
… | |
2229 | } |
2298 | } |
2230 | } |
2299 | } |
2231 | } |
2300 | } |
2232 | } |
2301 | } |
2233 | |
2302 | |
|
|
2303 | MODULE = CFPlus PACKAGE = CFPlus::RW |
|
|
2304 | |
|
|
2305 | CFPlus::RW |
|
|
2306 | new (SV *class, SV *data_sv) |
|
|
2307 | CODE: |
|
|
2308 | { |
|
|
2309 | STRLEN datalen; |
|
|
2310 | char *data = SvPVbyte (data_sv, datalen); |
|
|
2311 | |
|
|
2312 | RETVAL = SDL_RWFromConstMem (data, datalen); |
|
|
2313 | } |
|
|
2314 | OUTPUT: |
|
|
2315 | RETVAL |
|
|
2316 | |
|
|
2317 | CFPlus::RW |
|
|
2318 | new_from_file (SV *class, const char *path, const char *mode = "rb") |
|
|
2319 | CODE: |
|
|
2320 | RETVAL = SDL_RWFromFile (path, mode); |
|
|
2321 | OUTPUT: |
|
|
2322 | RETVAL |
|
|
2323 | |
|
|
2324 | # fails on win32: |
|
|
2325 | # CFPlus.xs(2268) : error C2059: syntax error : '(' |
|
|
2326 | #void |
|
|
2327 | #close (CFPlus::RW self) |
|
|
2328 | # CODE: |
|
|
2329 | # (self->(close)) (self); |
|
|
2330 | |
|
|
2331 | MODULE = CFPlus PACKAGE = CFPlus::Channel |
|
|
2332 | |
|
|
2333 | PROTOTYPES: DISABLE |
|
|
2334 | |
|
|
2335 | CFPlus::Channel |
|
|
2336 | find () |
|
|
2337 | CODE: |
|
|
2338 | { |
|
|
2339 | RETVAL = Mix_GroupAvailable (-1); |
|
|
2340 | |
|
|
2341 | if (RETVAL < 0) |
|
|
2342 | { |
|
|
2343 | RETVAL = Mix_GroupOldest (-1); |
|
|
2344 | |
|
|
2345 | if (RETVAL < 0) |
|
|
2346 | XSRETURN_UNDEF; |
|
|
2347 | |
|
|
2348 | Mix_HaltChannel (RETVAL); |
|
|
2349 | } |
|
|
2350 | |
|
|
2351 | Mix_UnregisterAllEffects (RETVAL); |
|
|
2352 | Mix_Volume (RETVAL, 128); |
|
|
2353 | } |
|
|
2354 | OUTPUT: |
|
|
2355 | RETVAL |
|
|
2356 | |
|
|
2357 | void |
|
|
2358 | halt (CFPlus::Channel self) |
|
|
2359 | CODE: |
|
|
2360 | Mix_HaltChannel (self); |
|
|
2361 | |
|
|
2362 | void |
|
|
2363 | expire (CFPlus::Channel self, int ticks = -1) |
|
|
2364 | CODE: |
|
|
2365 | Mix_ExpireChannel (self, ticks); |
|
|
2366 | |
|
|
2367 | void |
|
|
2368 | fade_out (CFPlus::Channel self, int ticks = -1) |
|
|
2369 | CODE: |
|
|
2370 | Mix_FadeOutChannel (self, ticks); |
|
|
2371 | |
|
|
2372 | int |
|
|
2373 | volume (CFPlus::Channel self, int volume) |
|
|
2374 | CODE: |
|
|
2375 | RETVAL = Mix_Volume (self, CLAMP (volume, 0, 128)); |
|
|
2376 | OUTPUT: |
|
|
2377 | RETVAL |
|
|
2378 | |
|
|
2379 | void |
|
|
2380 | unregister_all_effects (CFPlus::Channel self) |
|
|
2381 | CODE: |
|
|
2382 | Mix_UnregisterAllEffects (self); |
|
|
2383 | |
|
|
2384 | void |
|
|
2385 | set_panning (CFPlus::Channel self, int left, int right) |
|
|
2386 | CODE: |
|
|
2387 | left = CLAMP (left , 0, 255); |
|
|
2388 | right = CLAMP (right, 0, 255); |
|
|
2389 | Mix_SetPanning (self, left, right); |
|
|
2390 | |
|
|
2391 | void |
|
|
2392 | set_distance (CFPlus::Channel self, int distance) |
|
|
2393 | CODE: |
|
|
2394 | Mix_SetDistance (self, CLAMP (distance, 0, 255)); |
|
|
2395 | |
|
|
2396 | void |
|
|
2397 | set_position (CFPlus::Channel self, int angle, int distance) |
|
|
2398 | CODE: |
|
|
2399 | |
|
|
2400 | void |
|
|
2401 | set_position_r (CFPlus::Channel self, int dx, int dy, int maxdistance) |
|
|
2402 | CODE: |
|
|
2403 | { |
|
|
2404 | int distance = sqrtf (dx * dx + dy * dy) * (255.f / sqrtf (maxdistance * maxdistance)); |
|
|
2405 | int angle = 360 + (int)roundf (atan2f (dx, -dy) * 180.f / (float)M_PI); |
|
|
2406 | Mix_SetPosition (self, angle, CLAMP (distance, 0, 255)); |
|
|
2407 | } |
|
|
2408 | |
|
|
2409 | void |
|
|
2410 | set_reverse_stereo (CFPlus::Channel self, int flip) |
|
|
2411 | CODE: |
|
|
2412 | Mix_SetReverseStereo (self, flip); |
|
|
2413 | |
2234 | MODULE = CFPlus PACKAGE = CFPlus::MixChunk |
2414 | MODULE = CFPlus PACKAGE = CFPlus::MixChunk |
2235 | |
2415 | |
2236 | PROTOTYPES: DISABLE |
2416 | PROTOTYPES: DISABLE |
2237 | |
2417 | |
2238 | CFPlus::MixChunk |
2418 | CFPlus::MixChunk |
2239 | new_from_file (SV *class, char *path) |
2419 | new (SV *class, CFPlus::RW rwops) |
2240 | CODE: |
2420 | CODE: |
2241 | RETVAL = Mix_LoadWAV (path); |
2421 | RETVAL = Mix_LoadWAV_RW (rwops, 1); |
2242 | OUTPUT: |
2422 | OUTPUT: |
2243 | RETVAL |
2423 | RETVAL |
2244 | |
2424 | |
2245 | void |
2425 | void |
2246 | DESTROY (CFPlus::MixChunk self) |
2426 | DESTROY (CFPlus::MixChunk self) |
… | |
… | |
2248 | Mix_FreeChunk (self); |
2428 | Mix_FreeChunk (self); |
2249 | |
2429 | |
2250 | int |
2430 | int |
2251 | volume (CFPlus::MixChunk self, int volume = -1) |
2431 | volume (CFPlus::MixChunk self, int volume = -1) |
2252 | CODE: |
2432 | CODE: |
|
|
2433 | if (items > 1) |
|
|
2434 | volume = CLAMP (volume, 0, 128); |
2253 | RETVAL = Mix_VolumeChunk (self, volume); |
2435 | RETVAL = Mix_VolumeChunk (self, volume); |
2254 | OUTPUT: |
2436 | OUTPUT: |
2255 | RETVAL |
2437 | RETVAL |
2256 | |
2438 | |
2257 | int |
2439 | CFPlus::Channel |
2258 | play (CFPlus::MixChunk self, int channel = -1, int loops = 0, int ticks = -1) |
2440 | play (CFPlus::MixChunk self, CFPlus::Channel channel = -1, int loops = 0, int ticks = -1) |
2259 | CODE: |
2441 | CODE: |
|
|
2442 | { |
2260 | RETVAL = Mix_PlayChannelTimed (channel, self, loops, ticks); |
2443 | RETVAL = Mix_PlayChannelTimed (channel, self, loops, ticks); |
|
|
2444 | |
|
|
2445 | if (RETVAL < 0) |
|
|
2446 | XSRETURN_UNDEF; |
|
|
2447 | |
|
|
2448 | if (channel < 0) |
|
|
2449 | { |
|
|
2450 | Mix_UnregisterAllEffects (RETVAL); |
|
|
2451 | Mix_Volume (RETVAL, 128); |
|
|
2452 | } |
|
|
2453 | } |
2261 | OUTPUT: |
2454 | OUTPUT: |
2262 | RETVAL |
2455 | RETVAL |
2263 | |
2456 | |
2264 | MODULE = CFPlus PACKAGE = CFPlus::MixMusic |
2457 | MODULE = CFPlus PACKAGE = CFPlus::MixMusic |
2265 | |
2458 | |
2266 | int |
2459 | int |
2267 | volume (int volume = -1) |
2460 | volume (int volume = -1) |
2268 | PROTOTYPE: ;$ |
2461 | PROTOTYPE: ;$ |
2269 | CODE: |
2462 | CODE: |
|
|
2463 | if (items > 0) |
|
|
2464 | volume = CLAMP (volume, 0, 128); |
2270 | RETVAL = Mix_VolumeMusic (volume); |
2465 | RETVAL = Mix_VolumeMusic (volume); |
2271 | OUTPUT: |
2466 | OUTPUT: |
2272 | RETVAL |
2467 | RETVAL |
2273 | |
2468 | |
2274 | int |
2469 | void |
2275 | fade_out (int ms) |
2470 | fade_out (int ms) |
2276 | CODE: |
2471 | CODE: |
2277 | RETVAL = Mix_FadeOutMusic (ms); |
2472 | Mix_FadeOutMusic (ms); |
2278 | OUTPUT: |
2473 | |
2279 | RETVAL |
2474 | void |
|
|
2475 | halt () |
|
|
2476 | CODE: |
|
|
2477 | Mix_HaltMusic (); |
2280 | |
2478 | |
2281 | CFPlus::MixMusic |
2479 | CFPlus::MixMusic |
2282 | new_from_file (SV *class, char *path) |
2480 | new (SV *class, CFPlus::RW rwops) |
2283 | CODE: |
2481 | CODE: |
2284 | RETVAL = Mix_LoadMUS (path); |
2482 | RETVAL = Mix_LoadMUS_RW (rwops); |
2285 | OUTPUT: |
2483 | OUTPUT: |
2286 | RETVAL |
2484 | RETVAL |
2287 | |
2485 | |
2288 | void |
2486 | void |
2289 | DESTROY (CFPlus::MixMusic self) |
2487 | DESTROY (CFPlus::MixMusic self) |
… | |
… | |
2295 | CODE: |
2493 | CODE: |
2296 | RETVAL = Mix_PlayMusic (self, loops); |
2494 | RETVAL = Mix_PlayMusic (self, loops); |
2297 | OUTPUT: |
2495 | OUTPUT: |
2298 | RETVAL |
2496 | RETVAL |
2299 | |
2497 | |
2300 | int |
2498 | void |
2301 | fade_in_pos (CFPlus::MixMusic self, int loops, int ms, double position) |
2499 | fade_in_pos (CFPlus::MixMusic self, int loops, int ms, double position) |
2302 | CODE: |
2500 | CODE: |
2303 | RETVAL = Mix_FadeInMusicPos (self, loops, ms, position); |
2501 | Mix_FadeInMusicPos (self, loops, ms, position); |
2304 | OUTPUT: |
|
|
2305 | RETVAL |
|
|
2306 | |
2502 | |
2307 | MODULE = CFPlus PACKAGE = CFPlus::OpenGL |
2503 | MODULE = CFPlus PACKAGE = CFPlus::OpenGL |
2308 | |
2504 | |
2309 | PROTOTYPES: ENABLE |
2505 | PROTOTYPES: ENABLE |
2310 | |
2506 | |
… | |
… | |
2353 | const_iv (GL_INTENSITY), |
2549 | const_iv (GL_INTENSITY), |
2354 | const_iv (GL_LUMINANCE), |
2550 | const_iv (GL_LUMINANCE), |
2355 | const_iv (GL_LUMINANCE_ALPHA), |
2551 | const_iv (GL_LUMINANCE_ALPHA), |
2356 | const_iv (GL_FLOAT), |
2552 | const_iv (GL_FLOAT), |
2357 | 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), |
2358 | const_iv (GL_COMPILE), |
2560 | const_iv (GL_COMPILE), |
2359 | const_iv (GL_PROXY_TEXTURE_1D), |
2561 | const_iv (GL_PROXY_TEXTURE_1D), |
2360 | const_iv (GL_PROXY_TEXTURE_2D), |
2562 | const_iv (GL_PROXY_TEXTURE_2D), |
2361 | const_iv (GL_TEXTURE_1D), |
2563 | const_iv (GL_TEXTURE_1D), |
2362 | const_iv (GL_TEXTURE_2D), |
2564 | const_iv (GL_TEXTURE_2D), |
… | |
… | |
2386 | const_iv (GL_COLOR_LOGIC_OP), |
2588 | const_iv (GL_COLOR_LOGIC_OP), |
2387 | const_iv (GL_SEPARABLE_2D), |
2589 | const_iv (GL_SEPARABLE_2D), |
2388 | const_iv (GL_CONVOLUTION_2D), |
2590 | const_iv (GL_CONVOLUTION_2D), |
2389 | const_iv (GL_CONVOLUTION_BORDER_MODE), |
2591 | const_iv (GL_CONVOLUTION_BORDER_MODE), |
2390 | const_iv (GL_CONSTANT_BORDER), |
2592 | const_iv (GL_CONSTANT_BORDER), |
|
|
2593 | const_iv (GL_POINTS), |
2391 | const_iv (GL_LINES), |
2594 | const_iv (GL_LINES), |
2392 | const_iv (GL_LINE_STRIP), |
2595 | const_iv (GL_LINE_STRIP), |
2393 | const_iv (GL_LINE_LOOP), |
2596 | const_iv (GL_LINE_LOOP), |
2394 | const_iv (GL_QUADS), |
2597 | const_iv (GL_QUADS), |
2395 | const_iv (GL_QUAD_STRIP), |
2598 | const_iv (GL_QUAD_STRIP), |
2396 | const_iv (GL_TRIANGLES), |
2599 | const_iv (GL_TRIANGLES), |
2397 | const_iv (GL_TRIANGLE_STRIP), |
2600 | const_iv (GL_TRIANGLE_STRIP), |
2398 | const_iv (GL_TRIANGLE_FAN), |
2601 | const_iv (GL_TRIANGLE_FAN), |
|
|
2602 | const_iv (GL_POLYGON), |
2399 | const_iv (GL_PERSPECTIVE_CORRECTION_HINT), |
2603 | const_iv (GL_PERSPECTIVE_CORRECTION_HINT), |
2400 | const_iv (GL_POINT_SMOOTH_HINT), |
2604 | const_iv (GL_POINT_SMOOTH_HINT), |
2401 | const_iv (GL_LINE_SMOOTH_HINT), |
2605 | const_iv (GL_LINE_SMOOTH_HINT), |
2402 | const_iv (GL_POLYGON_SMOOTH_HINT), |
2606 | const_iv (GL_POLYGON_SMOOTH_HINT), |
2403 | const_iv (GL_GENERATE_MIPMAP_HINT), |
2607 | const_iv (GL_GENERATE_MIPMAP_HINT), |
|
|
2608 | const_iv (GL_TEXTURE_COMPRESSION_HINT), |
2404 | const_iv (GL_FASTEST), |
2609 | const_iv (GL_FASTEST), |
2405 | const_iv (GL_DONT_CARE), |
2610 | const_iv (GL_DONT_CARE), |
2406 | const_iv (GL_NICEST), |
2611 | const_iv (GL_NICEST), |
2407 | const_iv (GL_V2F), |
2612 | const_iv (GL_V2F), |
2408 | const_iv (GL_V3F), |
2613 | const_iv (GL_V3F), |
… | |
… | |
2416 | |
2621 | |
2417 | texture_av = newAV (); |
2622 | texture_av = newAV (); |
2418 | AvREAL_off (texture_av); |
2623 | AvREAL_off (texture_av); |
2419 | } |
2624 | } |
2420 | |
2625 | |
|
|
2626 | void |
|
|
2627 | disable_GL_EXT_blend_func_separate () |
|
|
2628 | CODE: |
|
|
2629 | gl.BlendFuncSeparate = 0; |
|
|
2630 | gl.BlendFuncSeparateEXT = 0; |
|
|
2631 | |
2421 | char * |
2632 | char * |
2422 | gl_vendor () |
2633 | gl_vendor () |
2423 | CODE: |
2634 | CODE: |
2424 | RETVAL = (char *)glGetString (GL_VENDOR); |
2635 | RETVAL = (char *)glGetString (GL_VENDOR); |
2425 | OUTPUT: |
2636 | OUTPUT: |
… | |
… | |
2497 | # near_ and far_ are due to microsofts buggy "c" compiler |
2708 | # near_ and far_ are due to microsofts buggy "c" compiler |
2498 | void glFrustum (double left, double right, double bottom, double top, double near_, double far_) |
2709 | void glFrustum (double left, double right, double bottom, double top, double near_, double far_) |
2499 | |
2710 | |
2500 | # near_ and far_ are due to microsofts buggy "c" compiler |
2711 | # near_ and far_ are due to microsofts buggy "c" compiler |
2501 | void glOrtho (double left, double right, double bottom, double top, double near_, double far_) |
2712 | void glOrtho (double left, double right, double bottom, double top, double near_, double far_) |
|
|
2713 | |
|
|
2714 | PROTOTYPES: DISABLE |
2502 | |
2715 | |
2503 | void glViewport (int x, int y, int width, int height) |
2716 | void glViewport (int x, int y, int width, int height) |
2504 | |
2717 | |
2505 | void glScissor (int x, int y, int width, int height) |
2718 | void glScissor (int x, int y, int width, int height) |
2506 | |
2719 | |
… | |
… | |
2514 | |
2727 | |
2515 | void glRotate (float angle, float x, float y, float z) |
2728 | void glRotate (float angle, float x, float y, float z) |
2516 | CODE: |
2729 | CODE: |
2517 | glRotatef (angle, x, y, z); |
2730 | glRotatef (angle, x, y, z); |
2518 | |
2731 | |
2519 | void glBegin (int mode) |
|
|
2520 | |
|
|
2521 | void glEnd () |
|
|
2522 | |
|
|
2523 | void glColor (float r, float g, float b, float a = 1.0) |
2732 | void glColor (float r, float g, float b, float a = 1.0) |
2524 | PROTOTYPE: @ |
|
|
2525 | ALIAS: |
2733 | ALIAS: |
2526 | glColor_premultiply = 1 |
2734 | glColor_premultiply = 1 |
2527 | CODE: |
2735 | CODE: |
2528 | if (ix) |
2736 | if (ix) |
2529 | { |
2737 | { |
… | |
… | |
2532 | b *= a; |
2740 | b *= a; |
2533 | } |
2741 | } |
2534 | // microsoft visual "c" rounds instead of truncating... |
2742 | // microsoft visual "c" rounds instead of truncating... |
2535 | glColor4f (r, g, b, a); |
2743 | glColor4f (r, g, b, a); |
2536 | |
2744 | |
2537 | void glInterleavedArrays (int format, int stride, char *data) |
|
|
2538 | |
|
|
2539 | void glDrawElements (int mode, int count, int type, char *indices) |
|
|
2540 | |
|
|
2541 | # 1.2 void glDrawRangeElements (int mode, int start, int end |
|
|
2542 | |
|
|
2543 | void glRasterPos (float x, float y, float z = 0.) |
2745 | void glRasterPos (float x, float y, float z = 0.) |
2544 | CODE: |
2746 | CODE: |
2545 | glRasterPos3f (0, 0, z); |
2747 | glRasterPos3f (0, 0, z); |
2546 | glBitmap (0, 0, 0, 0, x, y, 0); |
2748 | glBitmap (0, 0, 0, 0, x, y, 0); |
2547 | |
2749 | |
… | |
… | |
2551 | |
2753 | |
2552 | void glTexCoord (float s, float t) |
2754 | void glTexCoord (float s, float t) |
2553 | CODE: |
2755 | CODE: |
2554 | glTexCoord2f (s, t); |
2756 | glTexCoord2f (s, t); |
2555 | |
2757 | |
|
|
2758 | void glRect (float x1, float y1, float x2, float y2) |
|
|
2759 | CODE: |
|
|
2760 | glRectf (x1, y1, x2, y2); |
|
|
2761 | |
|
|
2762 | PROTOTYPES: ENABLE |
|
|
2763 | |
|
|
2764 | void glBegin (int mode) |
|
|
2765 | |
|
|
2766 | void glEnd () |
|
|
2767 | |
|
|
2768 | void glPointSize (GLfloat size) |
|
|
2769 | |
|
|
2770 | void glLineWidth (GLfloat width) |
|
|
2771 | |
|
|
2772 | void glInterleavedArrays (int format, int stride, char *data) |
|
|
2773 | |
|
|
2774 | void glDrawElements (int mode, int count, int type, char *indices) |
|
|
2775 | |
|
|
2776 | # 1.2 void glDrawRangeElements (int mode, int start, int end |
|
|
2777 | |
2556 | void glTexEnv (int target, int pname, float param) |
2778 | void glTexEnv (int target, int pname, float param) |
2557 | CODE: |
2779 | CODE: |
2558 | glTexEnvf (target, pname, param); |
2780 | glTexEnvf (target, pname, param); |
2559 | |
2781 | |
2560 | void glTexParameter (int target, int pname, float param) |
2782 | void glTexParameter (int target, int pname, float param) |
… | |
… | |
2617 | MODULE = CFPlus PACKAGE = CFPlus::UI::Base |
2839 | MODULE = CFPlus PACKAGE = CFPlus::UI::Base |
2618 | |
2840 | |
2619 | PROTOTYPES: DISABLE |
2841 | PROTOTYPES: DISABLE |
2620 | |
2842 | |
2621 | void |
2843 | void |
2622 | find_widget (SV *widget, NV x, NV y) |
2844 | find_widget (SV *self, NV x, NV y) |
2623 | PPCODE: |
2845 | PPCODE: |
2624 | { |
2846 | { |
2625 | if (within_widget (widget, x, y)) |
2847 | if (within_widget (self, x, y)) |
2626 | XPUSHs (widget); |
2848 | XPUSHs (self); |
2627 | } |
2849 | } |
2628 | |
2850 | |
|
|
2851 | BOOT: |
|
|
2852 | { |
|
|
2853 | hover_gv = gv_fetchpv ("CFPlus::UI::HOVER", 1, SVt_NV); |
|
|
2854 | |
|
|
2855 | draw_x_gv = gv_fetchpv ("CFPlus::UI::Base::draw_x", 1, SVt_NV); |
|
|
2856 | draw_y_gv = gv_fetchpv ("CFPlus::UI::Base::draw_y", 1, SVt_NV); |
|
|
2857 | draw_w_gv = gv_fetchpv ("CFPlus::UI::Base::draw_w", 1, SVt_NV); |
|
|
2858 | draw_h_gv = gv_fetchpv ("CFPlus::UI::Base::draw_h", 1, SVt_NV); |
|
|
2859 | } |
|
|
2860 | |
|
|
2861 | void |
|
|
2862 | draw (SV *self) |
|
|
2863 | CODE: |
|
|
2864 | { |
|
|
2865 | HV *hv; |
|
|
2866 | SV **svp; |
|
|
2867 | NV x, y, w, h; |
|
|
2868 | SV *draw_x_sv = GvSV (draw_x_gv); |
|
|
2869 | SV *draw_y_sv = GvSV (draw_y_gv); |
|
|
2870 | SV *draw_w_sv = GvSV (draw_w_gv); |
|
|
2871 | SV *draw_h_sv = GvSV (draw_h_gv); |
|
|
2872 | double draw_x, draw_y; |
|
|
2873 | |
|
|
2874 | if (!SvROK (self)) |
|
|
2875 | croak ("CFPlus::Base::draw: %s not a reference", SvPV_nolen (self)); |
|
|
2876 | |
|
|
2877 | hv = (HV *)SvRV (self); |
|
|
2878 | |
|
|
2879 | if (SvTYPE (hv) != SVt_PVHV) |
|
|
2880 | croak ("CFPlus::Base::draw: %s not a hashref", SvPV_nolen (self)); |
|
|
2881 | |
|
|
2882 | svp = hv_fetch (hv, "w", 1, 0); w = svp ? SvNV (*svp) : 0.; |
|
|
2883 | svp = hv_fetch (hv, "h", 1, 0); h = svp ? SvNV (*svp) : 0.; |
|
|
2884 | |
|
|
2885 | if (!h || !w) |
|
|
2886 | XSRETURN_EMPTY; |
|
|
2887 | |
|
|
2888 | svp = hv_fetch (hv, "x", 1, 0); x = svp ? SvNV (*svp) : 0.; |
|
|
2889 | svp = hv_fetch (hv, "y", 1, 0); y = svp ? SvNV (*svp) : 0.; |
|
|
2890 | |
|
|
2891 | draw_x = SvNV (draw_x_sv) + x; |
|
|
2892 | draw_y = SvNV (draw_y_sv) + y; |
|
|
2893 | |
|
|
2894 | if (draw_x + w < 0 || draw_x >= SvNV (draw_w_sv) |
|
|
2895 | || draw_y + h < 0 || draw_y >= SvNV (draw_h_sv)) |
|
|
2896 | XSRETURN_EMPTY; |
|
|
2897 | |
|
|
2898 | sv_setnv (draw_x_sv, draw_x); |
|
|
2899 | sv_setnv (draw_y_sv, draw_y); |
|
|
2900 | |
|
|
2901 | glPushMatrix (); |
|
|
2902 | glTranslated (x, y, 0); |
|
|
2903 | |
|
|
2904 | if (SvROK (GvSV (hover_gv)) && SvRV (GvSV (hover_gv)) == (SV *)hv) |
|
|
2905 | { |
|
|
2906 | svp = hv_fetch (hv, "can_hover", sizeof ("can_hover") - 1, 0); |
|
|
2907 | |
|
|
2908 | if (svp && SvTRUE (*svp)) |
|
|
2909 | { |
|
|
2910 | glColor4f (1.0f * 0.2f, 0.8f * 0.2f, 0.5f * 0.2f, 0.2f); |
|
|
2911 | glEnable (GL_BLEND); |
|
|
2912 | glBlendFunc (GL_ONE, GL_ONE_MINUS_SRC_ALPHA); |
|
|
2913 | glBegin (GL_QUADS); |
|
|
2914 | glVertex2f (0, 0); |
|
|
2915 | glVertex2f (w, 0); |
|
|
2916 | glVertex2f (w, h); |
|
|
2917 | glVertex2f (0, h); |
|
|
2918 | glEnd (); |
|
|
2919 | glDisable (GL_BLEND); |
|
|
2920 | } |
|
|
2921 | } |
|
|
2922 | #if 0 |
|
|
2923 | if ($ENV{CFPLUS_DEBUG} & 1) { |
|
|
2924 | glPushMatrix; |
|
|
2925 | glColor 1, 1, 0, 1; |
|
|
2926 | glTranslate 0.375, 0.375; |
|
|
2927 | glBegin GL_LINE_LOOP; |
|
|
2928 | glVertex 0 , 0; |
|
|
2929 | glVertex $self->{w} - 1, 0; |
|
|
2930 | glVertex $self->{w} - 1, $self->{h} - 1; |
|
|
2931 | glVertex 0 , $self->{h} - 1; |
|
|
2932 | glEnd; |
|
|
2933 | glPopMatrix; |
|
|
2934 | #CFPlus::UI::Label->new (w => $self->{w}, h => $self->{h}, text => $self, fontsize => 0)->_draw; |
|
|
2935 | } |
|
|
2936 | #endif |
|
|
2937 | PUSHMARK (SP); |
|
|
2938 | XPUSHs (self); |
|
|
2939 | PUTBACK; |
|
|
2940 | call_method ("_draw", G_VOID | G_DISCARD); |
|
|
2941 | SPAGAIN; |
|
|
2942 | |
|
|
2943 | glPopMatrix (); |
|
|
2944 | |
|
|
2945 | draw_x = draw_x - x; sv_setnv (draw_x_sv, draw_x); |
|
|
2946 | draw_y = draw_y - y; sv_setnv (draw_y_sv, draw_y); |
|
|
2947 | } |
|
|
2948 | |