diff --git a/polymer/build/include/build.h b/polymer/build/include/build.h index e87b07c7d..6b73fc94a 100644 --- a/polymer/build/include/build.h +++ b/polymer/build/include/build.h @@ -1,538 +1,540 @@ -// "Build Engine & Tools" Copyright (c) 1993-1997 Ken Silverman -// Ken Silverman's official web site: "http://www.advsys.net/ken" -// See the included license file "BUILDLIC.TXT" for license info. -// -// This file has been modified from Ken Silverman's original release -// by Jonathon Fowler (jonof@edgenetwk.com) - - -#ifndef __build_h__ -#define __build_h__ - -#ifdef __cplusplus -extern "C" { -#endif - -#define MAXSECTORSV8 4096 -#define MAXWALLSV8 16384 -#define MAXSPRITESV8 16384 - -#define MAXSECTORSV7 1024 -#define MAXWALLSV7 8192 -#define MAXSPRITESV7 4096 - -#define MAXSECTORS MAXSECTORSV8 -#define MAXWALLS MAXWALLSV8 -#define MAXSPRITES MAXSPRITESV8 - -#define MAXTILES 15360 -#define MAXVOXELS 4096 -#define MAXSTATUS 1024 -#define MAXPLAYERS 16 -#define MAXXDIM 2048 -#define MAXYDIM 1536 -#define MAXPALOOKUPS 256 -#define MAXPSKYTILES 256 -#define MAXSPRITESONSCREEN 4096 -#define MAXUNIQHUDID 256 //Extra slots so HUD models can store animation state without messing game sprites - -#define RESERVEDPALS 1 -#define DETAILPAL (MAXPALOOKUPS-1) - -#define CLIPMASK0 (((1L)<<16)+1L) -#define CLIPMASK1 (((256L)<<16)+64L) - - //Make all variables in BUILD.H defined in the ENGINE, - //and externed in GAME -#ifdef ENGINE -# define EXTERN -#else -# define EXTERN extern -#endif - -#ifdef __GNUC__ -#define BPACK __attribute__ ((packed)) -#else -#define BPACK -#endif - -#ifdef _MSC_VER -#pragma pack(1) -#endif - -#ifdef __WATCOMC__ -#pragma pack(push,1); -#endif - - -//ceilingstat/floorstat: -// bit 0: 1 = parallaxing, 0 = not "P" -// bit 1: 1 = groudraw, 0 = not -// bit 2: 1 = swap x&y, 0 = not "F" -// bit 3: 1 = double smooshiness "E" -// bit 4: 1 = x-flip "F" -// bit 5: 1 = y-flip "F" -// bit 6: 1 = Align texture to first wall of sector "R" -// bits 7-8: "T" -// 00 = normal floors -// 01 = masked floors -// 10 = transluscent masked floors -// 11 = reverse transluscent masked floors -// bits 9-15: reserved - - //40 bytes -typedef struct BPACK -{ - short wallptr, wallnum; - long ceilingz, floorz; - short ceilingstat, floorstat; - short ceilingpicnum, ceilingheinum; - signed char ceilingshade; - char ceilingpal, ceilingxpanning, ceilingypanning; - short floorpicnum, floorheinum; - signed char floorshade; - char floorpal, floorxpanning, floorypanning; - char visibility, filler; - short lotag, hitag, extra; -} sectortype; - -//cstat: -// bit 0: 1 = Blocking wall (use with clipmove, getzrange) "B" -// bit 1: 1 = bottoms of invisible walls swapped, 0 = not "2" -// bit 2: 1 = align picture on bottom (for doors), 0 = top "O" -// bit 3: 1 = x-flipped, 0 = normal "F" -// bit 4: 1 = masking wall, 0 = not "M" -// bit 5: 1 = 1-way wall, 0 = not "1" -// bit 6: 1 = Blocking wall (use with hitscan / cliptype 1) "H" -// bit 7: 1 = Transluscence, 0 = not "T" -// bit 8: 1 = y-flipped, 0 = normal "F" -// bit 9: 1 = Transluscence reversing, 0 = normal "T" -// bits 10-15: reserved - - //32 bytes -typedef struct BPACK -{ - long x, y; - short point2, nextwall, nextsector, cstat; - short picnum, overpicnum; - signed char shade; - char pal, xrepeat, yrepeat, xpanning, ypanning; - short lotag, hitag, extra; -} walltype; - -//cstat: -// bit 0: 1 = Blocking sprite (use with clipmove, getzrange) "B" -// bit 1: 1 = transluscence, 0 = normal "T" -// bit 2: 1 = x-flipped, 0 = normal "F" -// bit 3: 1 = y-flipped, 0 = normal "F" -// bits 5-4: 00 = FACE sprite (default) "R" -// 01 = WALL sprite (like masked walls) -// 10 = FLOOR sprite (parallel to ceilings&floors) -// bit 6: 1 = 1-sided sprite, 0 = normal "1" -// bit 7: 1 = Real centered centering, 0 = foot center "C" -// bit 8: 1 = Blocking sprite (use with hitscan / cliptype 1) "H" -// bit 9: 1 = Transluscence reversing, 0 = normal "T" -// bits 10-14: reserved -// bit 15: 1 = Invisible sprite, 0 = not invisible - - //44 bytes -typedef struct BPACK -{ - long x, y, z; - short cstat, picnum; - signed char shade; - char pal, clipdist, filler; - unsigned char xrepeat, yrepeat; - signed char xoffset, yoffset; - short sectnum, statnum; - short ang, owner, xvel, yvel, zvel; - short lotag, hitag, extra; -} spritetype; - -typedef struct BPACK { - unsigned long mdanimtims; - short mdanimcur; - short angoff; - short pitch, roll; - long xoff, yoff, zoff; - unsigned char flags; - char filler[3]; -} spriteexttype; -#define SPREXT_NOTMD 1 -#define SPREXT_NOMDANIM 2 -EXTERN spriteexttype spriteext[MAXSPRITES+MAXUNIQHUDID]; -EXTERN long guniqhudid; - -EXTERN sectortype sector[MAXSECTORS]; -EXTERN walltype wall[MAXWALLS]; -EXTERN spritetype sprite[MAXSPRITES]; - -EXTERN long spritesortcnt; -EXTERN spritetype tsprite[MAXSPRITESONSCREEN]; - -EXTERN long xdim, ydim, ylookup[MAXYDIM+1], numpages; -EXTERN long yxaspect, viewingrange; - -#define MAXVALIDMODES 256 -EXTERN long validmodecnt; -struct validmode_t { - long xdim,ydim; - char bpp; - char fs; // bit 0 = fullscreen flag - char filler[2]; - long extra; // internal use -}; -EXTERN struct validmode_t validmode[MAXVALIDMODES]; - -EXTERN short numsectors, numwalls; -EXTERN /*volatile*/ long totalclock; -EXTERN long numframes, randomseed; -EXTERN short sintable[2048]; -EXTERN char palette[768]; -EXTERN short numpalookups; -EXTERN char *palookup[MAXPALOOKUPS]; -EXTERN char parallaxtype, showinvisibility; -EXTERN long parallaxyoffs, parallaxyscale; -EXTERN long visibility, parallaxvisibility; - -EXTERN long windowx1, windowy1, windowx2, windowy2; -EXTERN short startumost[MAXXDIM], startdmost[MAXXDIM]; - -EXTERN short pskyoff[MAXPSKYTILES], pskybits; - -EXTERN short headspritesect[MAXSECTORS+1], headspritestat[MAXSTATUS+1]; -EXTERN short prevspritesect[MAXSPRITES], prevspritestat[MAXSPRITES]; -EXTERN short nextspritesect[MAXSPRITES], nextspritestat[MAXSPRITES]; - -EXTERN short tilesizx[MAXTILES], tilesizy[MAXTILES]; -EXTERN char picsiz[MAXTILES]; -EXTERN char walock[MAXTILES]; -EXTERN long pow2long[32]; -EXTERN long numtiles, picanm[MAXTILES], waloff[MAXTILES]; - - //These variables are for auto-mapping with the draw2dscreen function. - //When you load a new board, these bits are all set to 0 - since - //you haven't mapped out anything yet. Note that these arrays are - //bit-mapped. - //If you want draw2dscreen() to show sprite #54 then you say: - // spritenum = 54; - // show2dsprite[spritenum>>3] |= (1<<(spritenum&7)); - //And if you want draw2dscreen() to not show sprite #54 then you say: - // spritenum = 54; - // show2dsprite[spritenum>>3] &= ~(1<<(spritenum&7)); - //Automapping defaults to 0 (do nothing). If you set automapping to 1, - // then in 3D mode, the walls and sprites that you see will show up the - // next time you flip to 2D mode. - -EXTERN char show2dsector[(MAXSECTORS+7)>>3]; -EXTERN char show2dwall[(MAXWALLS+7)>>3]; -EXTERN char show2dsprite[(MAXSPRITES+7)>>3]; -EXTERN char automapping; - -EXTERN char gotpic[(MAXTILES+7)>>3]; -EXTERN char gotsector[(MAXSECTORS+7)>>3]; - -EXTERN char captureformat; -extern char vgapalette[5*256]; -extern unsigned long drawlinepat; - -extern void faketimerhandler(void); - -extern char apptitle[256]; -typedef struct { - unsigned char r,g,b,f; -} palette_t; -extern palette_t curpalette[256], curpalettefaded[256], palfadergb; -extern char palfadedelta; - -extern long dommxoverlay, novoxmips; - -#ifdef SUPERBUILD -extern long tiletovox[MAXTILES]; -extern long usevoxels, voxscale[MAXVOXELS]; -#endif -#ifdef POLYMOST -extern long usemodels, usehightile; -#endif - -extern char *engineerrstr; -extern char noclip; - -/************************************************************************* -POSITION VARIABLES: - - POSX is your x - position ranging from 0 to 65535 - POSY is your y - position ranging from 0 to 65535 - (the length of a side of the grid in EDITBORD would be 1024) - POSZ is your z - position (height) ranging from 0 to 65535, 0 highest. - ANG is your angle ranging from 0 to 2047. Instead of 360 degrees, or - 2 * PI radians, I use 2048 different angles, so 90 degrees would - be 512 in my system. - -SPRITE VARIABLES: - - EXTERN short headspritesect[MAXSECTORS+1], headspritestat[MAXSTATUS+1]; - EXTERN short prevspritesect[MAXSPRITES], prevspritestat[MAXSPRITES]; - EXTERN short nextspritesect[MAXSPRITES], nextspritestat[MAXSPRITES]; - - Example: if the linked lists look like the following: - �������������������������������Ŀ - Sector lists: Status lists: - �������������������������������Ĵ - Sector0: 4, 5, 8 Status0: 2, 0, 8 - Sector1: 16, 2, 0, 7 Status1: 4, 5, 16, 7, 3, 9 - Sector2: 3, 9 - �������������������������������� - Notice that each number listed above is shown exactly once on both the - left and right side. This is because any sprite that exists must - be in some sector, and must have some kind of status that you define. - - -Coding example #1: - To go through all the sprites in sector 1, the code can look like this: - - sectnum = 1; - i = headspritesect[sectnum]; - while (i != -1) - { - nexti = nextspritesect[i]; - - //your code goes here - //ex: printf("Sprite %d is in sector %d\n",i,sectnum); - - i = nexti; - } - -Coding example #2: - To go through all sprites with status = 1, the code can look like this: - - statnum = 1; //status 1 - i = headspritestat[statnum]; - while (i != -1) - { - nexti = nextspritestat[i]; - - //your code goes here - //ex: printf("Sprite %d has a status of 1 (active)\n",i,statnum); - - i = nexti; - } - - insertsprite(short sectnum, short statnum); - deletesprite(short spritenum); - changespritesect(short spritenum, short newsectnum); - changespritestat(short spritenum, short newstatnum); - -TILE VARIABLES: - NUMTILES - the number of tiles found TILES.DAT. - TILESIZX[MAXTILES] - simply the x-dimension of the tile number. - TILESIZY[MAXTILES] - simply the y-dimension of the tile number. - WALOFF[MAXTILES] - the actual 32-bit offset pointing to the top-left - corner of the tile. - PICANM[MAXTILES] - flags for animating the tile. - -TIMING VARIABLES: - TOTALCLOCK - When the engine is initialized, TOTALCLOCK is set to zero. - From then on, it is incremented 120 times a second by 1. That - means that the number of seconds elapsed is totalclock / 120. - NUMFRAMES - The number of times the draw3dscreen function was called - since the engine was initialized. This helps to determine frame - rate. (Frame rate = numframes * 120 / totalclock.) - -OTHER VARIABLES: - - STARTUMOST[320] is an array of the highest y-coordinates on each column - that my engine is allowed to write to. You need to set it only - once. - STARTDMOST[320] is an array of the lowest y-coordinates on each column - that my engine is allowed to write to. You need to set it only - once. - SINTABLE[2048] is a sin table with 2048 angles rather than the - normal 360 angles for higher precision. Also since SINTABLE is in - all integers, the range is multiplied by 16383, so instead of the - normal -1=0 for a particular palette -// how: pass -1 to invalidate all instances of the tile in texture memory, or a bitfield -// bit 0: opaque or masked (non-translucent) texture, using repeating -// bit 1: ignored -// bit 2: 33% translucence, using repeating -// bit 3: 67% translucence, using repeating -// bit 4: opaque or masked (non-translucent) texture, using clamping -// bit 5: ignored -// bit 6: 33% translucence, using clamping -// bit 7: 67% translucence, using clamping -// clamping is for sprites, repeating is for walls -void invalidatetile(short tilenume, long pal, long how); - -long animateoffs(short tilenum, short fakevar); - -void setpolymost2dview(void); // sets up GL for 2D drawing - -long polymost_drawtilescreen(long tilex, long tiley, long wallnum, long dimen); -void polymost_glreset(void); -void polymost_precache(long dapicnum, long dapalnum, long datype); - -#if defined(POLYMOST) && defined(USE_OPENGL) -extern long glanisotropy; -extern long glusetexcompr; -extern long gltexfiltermode; -extern long glredbluemode; -extern long glusetexcache, glusetexcachecompression; -extern long glmultisample, glnvmultisamplehint; -extern long glwidescreen, glprojectionhacks; -void gltexapplyprops (void); - -extern long r_depthpeeling, r_peelscount; -extern long r_detailmapping; -#endif - -void hicinit(void); -// effect bitset: 1 = greyscale, 2 = invert -void hicsetpalettetint(long palnum, unsigned char r, unsigned char g, unsigned char b, unsigned char effect); -// flags bitset: 1 = don't compress -int hicsetsubsttex(long picnum, long palnum, char *filen, float alphacut, char flags); -int hicsetskybox(long picnum, long palnum, char *faces[6]); -int hicclearsubst(long picnum, long palnum); - -int md_loadmodel(const char *fn); -int md_setmisc(int modelid, float scale, int shadeoff, float zadd); -int md_tilehasmodel(int tilenume); -int md_defineframe(int modelid, const char *framename, int tilenume, int skinnum); -int md_defineanimation(int modelid, const char *framestart, const char *frameend, int fps, int flags); -int md_defineskin(int modelid, const char *skinfn, int palnum, int skinnum, int surfnum); -int md_definehud (int modelid, int tilex, double xadd, double yadd, double zadd, double angadd, int flags); -int md_undefinetile(int tile); -int md_undefinemodel(int modelid); - -int loaddefinitionsfile(char *fn); - -extern long mapversion; // if loadboard() fails with -2 return, try loadoldboard(). if it fails with -2, board is dodgy -long loadoldboard(char *filename, char fromwhere, long *daposx, long *daposy, long *daposz, short *daang, short *dacursectnum); - -#ifdef _MSC_VER -#pragma pack() -#endif - -#ifdef __WATCOMC__ -#pragma pack(pop) -#endif - -#undef BPACK - -#ifdef __cplusplus -} -#endif - -#endif // __build_h__ +// "Build Engine & Tools" Copyright (c) 1993-1997 Ken Silverman +// Ken Silverman's official web site: "http://www.advsys.net/ken" +// See the included license file "BUILDLIC.TXT" for license info. +// +// This file has been modified from Ken Silverman's original release +// by Jonathon Fowler (jonof@edgenetwk.com) + + +#ifndef __build_h__ +#define __build_h__ + +#ifdef __cplusplus +extern "C" { +#endif + +#define MAXSECTORSV8 4096 +#define MAXWALLSV8 16384 +#define MAXSPRITESV8 16384 + +#define MAXSECTORSV7 1024 +#define MAXWALLSV7 8192 +#define MAXSPRITESV7 4096 + +#define MAXSECTORS MAXSECTORSV8 +#define MAXWALLS MAXWALLSV8 +#define MAXSPRITES MAXSPRITESV8 + +#define MAXTILES 15360 +#define MAXVOXELS 4096 +#define MAXSTATUS 1024 +#define MAXPLAYERS 16 +#define MAXXDIM 2048 +#define MAXYDIM 1536 +#define MAXPALOOKUPS 256 +#define MAXPSKYTILES 256 +#define MAXSPRITESONSCREEN 4096 +#define MAXUNIQHUDID 256 //Extra slots so HUD models can store animation state without messing game sprites + +#define RESERVEDPALS 2 // don't forget to increment this when adding reserved pals +#define DETAILPAL (MAXPALOOKUPS - 1) +#define GLOWPAL (MAXPALOOKUPS - 2) + +#define CLIPMASK0 (((1L)<<16)+1L) +#define CLIPMASK1 (((256L)<<16)+64L) + + //Make all variables in BUILD.H defined in the ENGINE, + //and externed in GAME +#ifdef ENGINE +# define EXTERN +#else +# define EXTERN extern +#endif + +#ifdef __GNUC__ +#define BPACK __attribute__ ((packed)) +#else +#define BPACK +#endif + +#ifdef _MSC_VER +#pragma pack(1) +#endif + +#ifdef __WATCOMC__ +#pragma pack(push,1); +#endif + + +//ceilingstat/floorstat: +// bit 0: 1 = parallaxing, 0 = not "P" +// bit 1: 1 = groudraw, 0 = not +// bit 2: 1 = swap x&y, 0 = not "F" +// bit 3: 1 = double smooshiness "E" +// bit 4: 1 = x-flip "F" +// bit 5: 1 = y-flip "F" +// bit 6: 1 = Align texture to first wall of sector "R" +// bits 7-8: "T" +// 00 = normal floors +// 01 = masked floors +// 10 = transluscent masked floors +// 11 = reverse transluscent masked floors +// bits 9-15: reserved + + //40 bytes +typedef struct BPACK +{ + short wallptr, wallnum; + long ceilingz, floorz; + short ceilingstat, floorstat; + short ceilingpicnum, ceilingheinum; + signed char ceilingshade; + char ceilingpal, ceilingxpanning, ceilingypanning; + short floorpicnum, floorheinum; + signed char floorshade; + char floorpal, floorxpanning, floorypanning; + char visibility, filler; + short lotag, hitag, extra; +} sectortype; + +//cstat: +// bit 0: 1 = Blocking wall (use with clipmove, getzrange) "B" +// bit 1: 1 = bottoms of invisible walls swapped, 0 = not "2" +// bit 2: 1 = align picture on bottom (for doors), 0 = top "O" +// bit 3: 1 = x-flipped, 0 = normal "F" +// bit 4: 1 = masking wall, 0 = not "M" +// bit 5: 1 = 1-way wall, 0 = not "1" +// bit 6: 1 = Blocking wall (use with hitscan / cliptype 1) "H" +// bit 7: 1 = Transluscence, 0 = not "T" +// bit 8: 1 = y-flipped, 0 = normal "F" +// bit 9: 1 = Transluscence reversing, 0 = normal "T" +// bits 10-15: reserved + + //32 bytes +typedef struct BPACK +{ + long x, y; + short point2, nextwall, nextsector, cstat; + short picnum, overpicnum; + signed char shade; + char pal, xrepeat, yrepeat, xpanning, ypanning; + short lotag, hitag, extra; +} walltype; + +//cstat: +// bit 0: 1 = Blocking sprite (use with clipmove, getzrange) "B" +// bit 1: 1 = transluscence, 0 = normal "T" +// bit 2: 1 = x-flipped, 0 = normal "F" +// bit 3: 1 = y-flipped, 0 = normal "F" +// bits 5-4: 00 = FACE sprite (default) "R" +// 01 = WALL sprite (like masked walls) +// 10 = FLOOR sprite (parallel to ceilings&floors) +// bit 6: 1 = 1-sided sprite, 0 = normal "1" +// bit 7: 1 = Real centered centering, 0 = foot center "C" +// bit 8: 1 = Blocking sprite (use with hitscan / cliptype 1) "H" +// bit 9: 1 = Transluscence reversing, 0 = normal "T" +// bits 10-14: reserved +// bit 15: 1 = Invisible sprite, 0 = not invisible + + //44 bytes +typedef struct BPACK +{ + long x, y, z; + short cstat, picnum; + signed char shade; + char pal, clipdist, filler; + unsigned char xrepeat, yrepeat; + signed char xoffset, yoffset; + short sectnum, statnum; + short ang, owner, xvel, yvel, zvel; + short lotag, hitag, extra; +} spritetype; + +typedef struct BPACK { + unsigned long mdanimtims; + short mdanimcur; + short angoff; + short pitch, roll; + long xoff, yoff, zoff; + unsigned char flags; + char filler[3]; +} spriteexttype; +#define SPREXT_NOTMD 1 +#define SPREXT_NOMDANIM 2 +EXTERN spriteexttype spriteext[MAXSPRITES+MAXUNIQHUDID]; +EXTERN long guniqhudid; + +EXTERN sectortype sector[MAXSECTORS]; +EXTERN walltype wall[MAXWALLS]; +EXTERN spritetype sprite[MAXSPRITES]; + +EXTERN long spritesortcnt; +EXTERN spritetype tsprite[MAXSPRITESONSCREEN]; + +EXTERN long xdim, ydim, ylookup[MAXYDIM+1], numpages; +EXTERN long yxaspect, viewingrange; + +#define MAXVALIDMODES 256 +EXTERN long validmodecnt; +struct validmode_t { + long xdim,ydim; + char bpp; + char fs; // bit 0 = fullscreen flag + char filler[2]; + long extra; // internal use +}; +EXTERN struct validmode_t validmode[MAXVALIDMODES]; + +EXTERN short numsectors, numwalls; +EXTERN /*volatile*/ long totalclock; +EXTERN long numframes, randomseed; +EXTERN short sintable[2048]; +EXTERN char palette[768]; +EXTERN short numpalookups; +EXTERN char *palookup[MAXPALOOKUPS]; +EXTERN char parallaxtype, showinvisibility; +EXTERN long parallaxyoffs, parallaxyscale; +EXTERN long visibility, parallaxvisibility; + +EXTERN long windowx1, windowy1, windowx2, windowy2; +EXTERN short startumost[MAXXDIM], startdmost[MAXXDIM]; + +EXTERN short pskyoff[MAXPSKYTILES], pskybits; + +EXTERN short headspritesect[MAXSECTORS+1], headspritestat[MAXSTATUS+1]; +EXTERN short prevspritesect[MAXSPRITES], prevspritestat[MAXSPRITES]; +EXTERN short nextspritesect[MAXSPRITES], nextspritestat[MAXSPRITES]; + +EXTERN short tilesizx[MAXTILES], tilesizy[MAXTILES]; +EXTERN char picsiz[MAXTILES]; +EXTERN char walock[MAXTILES]; +EXTERN long pow2long[32]; +EXTERN long numtiles, picanm[MAXTILES], waloff[MAXTILES]; + + //These variables are for auto-mapping with the draw2dscreen function. + //When you load a new board, these bits are all set to 0 - since + //you haven't mapped out anything yet. Note that these arrays are + //bit-mapped. + //If you want draw2dscreen() to show sprite #54 then you say: + // spritenum = 54; + // show2dsprite[spritenum>>3] |= (1<<(spritenum&7)); + //And if you want draw2dscreen() to not show sprite #54 then you say: + // spritenum = 54; + // show2dsprite[spritenum>>3] &= ~(1<<(spritenum&7)); + //Automapping defaults to 0 (do nothing). If you set automapping to 1, + // then in 3D mode, the walls and sprites that you see will show up the + // next time you flip to 2D mode. + +EXTERN char show2dsector[(MAXSECTORS+7)>>3]; +EXTERN char show2dwall[(MAXWALLS+7)>>3]; +EXTERN char show2dsprite[(MAXSPRITES+7)>>3]; +EXTERN char automapping; + +EXTERN char gotpic[(MAXTILES+7)>>3]; +EXTERN char gotsector[(MAXSECTORS+7)>>3]; + +EXTERN char captureformat; +extern char vgapalette[5*256]; +extern unsigned long drawlinepat; + +extern void faketimerhandler(void); + +extern char apptitle[256]; +typedef struct { + unsigned char r,g,b,f; +} palette_t; +extern palette_t curpalette[256], curpalettefaded[256], palfadergb; +extern char palfadedelta; + +extern long dommxoverlay, novoxmips; + +#ifdef SUPERBUILD +extern long tiletovox[MAXTILES]; +extern long usevoxels, voxscale[MAXVOXELS]; +#endif +#ifdef POLYMOST +extern long usemodels, usehightile; +#endif + +extern char *engineerrstr; +extern char noclip; + +/************************************************************************* +POSITION VARIABLES: + + POSX is your x - position ranging from 0 to 65535 + POSY is your y - position ranging from 0 to 65535 + (the length of a side of the grid in EDITBORD would be 1024) + POSZ is your z - position (height) ranging from 0 to 65535, 0 highest. + ANG is your angle ranging from 0 to 2047. Instead of 360 degrees, or + 2 * PI radians, I use 2048 different angles, so 90 degrees would + be 512 in my system. + +SPRITE VARIABLES: + + EXTERN short headspritesect[MAXSECTORS+1], headspritestat[MAXSTATUS+1]; + EXTERN short prevspritesect[MAXSPRITES], prevspritestat[MAXSPRITES]; + EXTERN short nextspritesect[MAXSPRITES], nextspritestat[MAXSPRITES]; + + Example: if the linked lists look like the following: + �������������������������������Ŀ + Sector lists: Status lists: + �������������������������������Ĵ + Sector0: 4, 5, 8 Status0: 2, 0, 8 + Sector1: 16, 2, 0, 7 Status1: 4, 5, 16, 7, 3, 9 + Sector2: 3, 9 + �������������������������������� + Notice that each number listed above is shown exactly once on both the + left and right side. This is because any sprite that exists must + be in some sector, and must have some kind of status that you define. + + +Coding example #1: + To go through all the sprites in sector 1, the code can look like this: + + sectnum = 1; + i = headspritesect[sectnum]; + while (i != -1) + { + nexti = nextspritesect[i]; + + //your code goes here + //ex: printf("Sprite %d is in sector %d\n",i,sectnum); + + i = nexti; + } + +Coding example #2: + To go through all sprites with status = 1, the code can look like this: + + statnum = 1; //status 1 + i = headspritestat[statnum]; + while (i != -1) + { + nexti = nextspritestat[i]; + + //your code goes here + //ex: printf("Sprite %d has a status of 1 (active)\n",i,statnum); + + i = nexti; + } + + insertsprite(short sectnum, short statnum); + deletesprite(short spritenum); + changespritesect(short spritenum, short newsectnum); + changespritestat(short spritenum, short newstatnum); + +TILE VARIABLES: + NUMTILES - the number of tiles found TILES.DAT. + TILESIZX[MAXTILES] - simply the x-dimension of the tile number. + TILESIZY[MAXTILES] - simply the y-dimension of the tile number. + WALOFF[MAXTILES] - the actual 32-bit offset pointing to the top-left + corner of the tile. + PICANM[MAXTILES] - flags for animating the tile. + +TIMING VARIABLES: + TOTALCLOCK - When the engine is initialized, TOTALCLOCK is set to zero. + From then on, it is incremented 120 times a second by 1. That + means that the number of seconds elapsed is totalclock / 120. + NUMFRAMES - The number of times the draw3dscreen function was called + since the engine was initialized. This helps to determine frame + rate. (Frame rate = numframes * 120 / totalclock.) + +OTHER VARIABLES: + + STARTUMOST[320] is an array of the highest y-coordinates on each column + that my engine is allowed to write to. You need to set it only + once. + STARTDMOST[320] is an array of the lowest y-coordinates on each column + that my engine is allowed to write to. You need to set it only + once. + SINTABLE[2048] is a sin table with 2048 angles rather than the + normal 360 angles for higher precision. Also since SINTABLE is in + all integers, the range is multiplied by 16383, so instead of the + normal -1=0 for a particular palette +// how: pass -1 to invalidate all instances of the tile in texture memory, or a bitfield +// bit 0: opaque or masked (non-translucent) texture, using repeating +// bit 1: ignored +// bit 2: 33% translucence, using repeating +// bit 3: 67% translucence, using repeating +// bit 4: opaque or masked (non-translucent) texture, using clamping +// bit 5: ignored +// bit 6: 33% translucence, using clamping +// bit 7: 67% translucence, using clamping +// clamping is for sprites, repeating is for walls +void invalidatetile(short tilenume, long pal, long how); + +long animateoffs(short tilenum, short fakevar); + +void setpolymost2dview(void); // sets up GL for 2D drawing + +long polymost_drawtilescreen(long tilex, long tiley, long wallnum, long dimen); +void polymost_glreset(void); +void polymost_precache(long dapicnum, long dapalnum, long datype); + +#if defined(POLYMOST) && defined(USE_OPENGL) +extern long glanisotropy; +extern long glusetexcompr; +extern long gltexfiltermode; +extern long glredbluemode; +extern long glusetexcache, glusetexcachecompression; +extern long glmultisample, glnvmultisamplehint; +extern long glwidescreen, glprojectionhacks; +void gltexapplyprops (void); + +extern long r_depthpeeling, r_peelscount; +extern long r_detailmapping; +extern long r_glowmapping; +#endif + +void hicinit(void); +// effect bitset: 1 = greyscale, 2 = invert +void hicsetpalettetint(long palnum, unsigned char r, unsigned char g, unsigned char b, unsigned char effect); +// flags bitset: 1 = don't compress +int hicsetsubsttex(long picnum, long palnum, char *filen, float alphacut, char flags); +int hicsetskybox(long picnum, long palnum, char *faces[6]); +int hicclearsubst(long picnum, long palnum); + +int md_loadmodel(const char *fn); +int md_setmisc(int modelid, float scale, int shadeoff, float zadd); +int md_tilehasmodel(int tilenume); +int md_defineframe(int modelid, const char *framename, int tilenume, int skinnum); +int md_defineanimation(int modelid, const char *framestart, const char *frameend, int fps, int flags); +int md_defineskin(int modelid, const char *skinfn, int palnum, int skinnum, int surfnum); +int md_definehud (int modelid, int tilex, double xadd, double yadd, double zadd, double angadd, int flags); +int md_undefinetile(int tile); +int md_undefinemodel(int modelid); + +int loaddefinitionsfile(char *fn); + +extern long mapversion; // if loadboard() fails with -2 return, try loadoldboard(). if it fails with -2, board is dodgy +long loadoldboard(char *filename, char fromwhere, long *daposx, long *daposy, long *daposz, short *daang, short *dacursectnum); + +#ifdef _MSC_VER +#pragma pack() +#endif + +#ifdef __WATCOMC__ +#pragma pack(pop) +#endif + +#undef BPACK + +#ifdef __cplusplus +} +#endif + +#endif // __build_h__ diff --git a/polymer/build/src/defs.c b/polymer/build/src/defs.c index b31862331..d348bf763 100644 --- a/polymer/build/src/defs.c +++ b/polymer/build/src/defs.c @@ -43,6 +43,7 @@ enum { T_FLAGS, T_PAL, T_DETAIL, + T_GLOW, T_HUD, T_XADD, T_YADD, @@ -119,6 +120,7 @@ static tokenlist modeltokens[] = { { "frame", T_FRAME }, { "anim", T_ANIM }, { "skin", T_SKIN }, + { "glow", T_GLOW }, { "hud", T_HUD }, }; @@ -187,10 +189,11 @@ static tokenlist tinttokens[] = { static tokenlist texturetokens[] = { { "pal", T_PAL }, { "detail", T_DETAIL }, + { "glow", T_GLOW }, }; static tokenlist texturetokens_pal[] = { { "file", T_FILE },{ "name", T_FILE }, - { "alphacut", T_ALPHACUT }, { "detailscale", T_ALPHACUT }, { "scale", T_ALPHACUT }, + { "alphacut", T_ALPHACUT }, { "detailscale", T_ALPHACUT }, { "scale", T_ALPHACUT }, { "intensity", T_ALPHACUT }, { "nocompress",T_NOCOMPRESS }, }; @@ -867,6 +870,51 @@ static int defsparser(scriptfile *script) script->filename, scriptfile_getlinum(script,skintokptr)); break; } +#endif + } break; + case T_GLOW: + { + char *glowtokptr = script->ltextptr; + char *glowend, *glowfn = 0; + int surfnum = 0; + + if (scriptfile_getbraces(script,&glowend)) break; + while (script->textptr < glowend) { + switch (getatoken(script,modelskintokens,sizeof(modelskintokens)/sizeof(tokenlist))) { + case T_FILE: + scriptfile_getstring(script,&glowfn); break; //skin filename + case T_SURF: + scriptfile_getnumber(script,&surfnum); break; + } + } + + if (!glowfn) { + initprintf("Error: missing 'skin filename' for skin definition near line %s:%d\n", script->filename, scriptfile_getlinum(script,glowtokptr)); + break; + } + + if (seenframe) { modelskin = ++lastmodelskin; } + seenframe = 0; + +#if defined(POLYMOST) && defined(USE_OPENGL) + switch (md_defineskin(lastmodelid, glowfn, GLOWPAL, max(0,modelskin), surfnum)) { + case 0: + break; + case -1: + break; // invalid model id!? + case -2: + initprintf("Invalid skin filename on line %s:%d\n", + script->filename, scriptfile_getlinum(script,glowtokptr)); + break; + case -3: + initprintf("Invalid palette number on line %s:%d\n", + script->filename, scriptfile_getlinum(script,glowtokptr)); + break; + case -4: + initprintf("Out of memory on line %s:%d\n", + script->filename, scriptfile_getlinum(script,glowtokptr)); + break; + } #endif } break; case T_HUD: @@ -1159,6 +1207,40 @@ static int defsparser(scriptfile *script) hicsetsubsttex(tile,DETAILPAL,fn,detailscale,flags); } break; + case T_GLOW: { + char *glowtokptr = script->ltextptr, *glowend; + int i; + char *fn = NULL; + double glowintensity = 1.0; + char flags = 0; + + if (scriptfile_getbraces(script,&glowend)) break; + while (script->textptr < glowend) { + switch (getatoken(script,texturetokens_pal,sizeof(texturetokens_pal)/sizeof(tokenlist))) { + case T_FILE: + scriptfile_getstring(script,&fn); break; + case T_ALPHACUT: + scriptfile_getdouble(script,&glowintensity); break; + case T_NOCOMPRESS: + flags |= 1; break; + default: + break; + } + } + + if ((unsigned)tile > (unsigned)MAXTILES) break; // message is printed later + if (!fn) { + initprintf("Error: missing 'file name' for texture definition near line %s:%d\n", + script->filename, scriptfile_getlinum(script,glowtokptr)); + break; + } + if ((i = kopen4load(fn,0)) < 0) { + initprintf("Error: file '%s' does not exist\n",fn); + break; + } else kclose(i); + + hicsetsubsttex(tile,GLOWPAL,fn,glowintensity,flags); + } break; default: break; } diff --git a/polymer/build/src/mdsprite.c b/polymer/build/src/mdsprite.c index 514e22407..6a780bf6e 100644 --- a/polymer/build/src/mdsprite.c +++ b/polymer/build/src/mdsprite.c @@ -661,7 +661,7 @@ failure: // --------------------------------------------------- JONOF'S COMPRESSED TEXTURE CACHE STUFF //Note: even though it says md2model, it works for both md2model&md3model -static long mdloadskin (md2model *m, int number, int pal, int surf) +static long mdloadskin (md2model *m, int number, int pal, int surf, int exact) { long i,j, fptr=0, bpl, xsiz=0, ysiz=0, osizx, osizy, texfmt = GL_RGBA, intexfmt = GL_RGBA; char *skinfile, hasalpha, fn[BMAX_PATH+65]; @@ -696,6 +696,8 @@ static long mdloadskin (md2model *m, int number, int pal, int surf) } if (!sk) { + if (exact) + return (0); if (skzero) { skinfile = skzero->fn; @@ -1272,13 +1274,14 @@ static int md3draw (md3model *m, spritetype *tspr) { point3d fp, fp1, fp2, m0, m1, a0, a1; md3xyzn_t *v0, *v1; - long i, j, k, surfi, *lptr; + long i, j, k, l, surfi, *lptr; float f, g, k0, k1, k2, k3, k4, k5, k6, k7, mat[16], pc[4], mult; md3surf_t *s; //PLAG : sorting stuff unsigned short *indexes; float *maxdepths; unsigned short tempus; + int texunits = GL_TEXTURE0_ARB; // if ((tspr->cstat&48) == 32) return 0; @@ -1485,10 +1488,81 @@ if (tspr->cstat&2) { if (!(tspr->cstat&512)) pc[3] = 0.66; else pc[3] = 0.33; } mat[3] = mat[7] = mat[11] = 0.f; mat[15] = 1.f; bglLoadMatrixf(mat); // PLAG: End - i = mdloadskin((md2model *)m,tile2model[tspr->picnum].skinnum,globalpal,surfi); if (!i) continue; + i = mdloadskin((md2model *)m,tile2model[tspr->picnum].skinnum,globalpal,surfi,0); if (!i) continue; //i = mdloadskin((md2model *)m,tile2model[tspr->picnum].skinnum,surfi); //hack for testing multiple surfaces per MD3 bglBindTexture(GL_TEXTURE_2D, i); + /*if (r_detailmapping && !r_depthpeeling && indrawroomsandmasks) + i = mdloadskin((md2model *)m,tile2model[tspr->picnum].skinnum,DETAILPAL,surfi,1); + else + i = 0; + + if (i) + { + bglActiveTextureARB(++texunits); + + bglEnable(GL_TEXTURE_2D); + bglBindTexture(GL_TEXTURE_2D, i); + + bglTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE_ARB); + bglTexEnvf(GL_TEXTURE_ENV, GL_COMBINE_RGB_ARB, GL_MODULATE); + + bglTexEnvf(GL_TEXTURE_ENV, GL_SOURCE0_RGB_ARB, GL_PREVIOUS_ARB); + bglTexEnvf(GL_TEXTURE_ENV, GL_OPERAND0_RGB_ARB, GL_SRC_COLOR); + + bglTexEnvf(GL_TEXTURE_ENV, GL_SOURCE1_RGB_ARB, GL_TEXTURE); + bglTexEnvf(GL_TEXTURE_ENV, GL_OPERAND1_RGB_ARB, GL_SRC_COLOR); + + bglTexEnvf(GL_TEXTURE_ENV, GL_COMBINE_ALPHA_ARB, GL_REPLACE); + bglTexEnvf(GL_TEXTURE_ENV, GL_SOURCE0_ALPHA_ARB, GL_PREVIOUS_ARB); + bglTexEnvf(GL_TEXTURE_ENV, GL_OPERAND0_ALPHA_ARB, GL_SRC_ALPHA); + + bglTexEnvf(GL_TEXTURE_ENV, GL_RGB_SCALE_ARB, 2.0f); + + bglTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_S,GL_REPEAT); + bglTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_T,GL_REPEAT); + + + f = 0.5f; + + bglMatrixMode(GL_TEXTURE); + bglLoadIdentity(); + bglScalef(f, f, 1.0f); + bglMatrixMode(GL_MODELVIEW); + }*/ + + if (r_glowmapping && !r_depthpeeling && indrawroomsandmasks) + i = mdloadskin((md2model *)m,tile2model[tspr->picnum].skinnum,GLOWPAL,surfi,1); + else + i = 0; + + if (i) + { + bglActiveTextureARB(++texunits); + + bglEnable(GL_TEXTURE_2D); + bglBindTexture(GL_TEXTURE_2D, i); + + bglTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE_ARB); + bglTexEnvf(GL_TEXTURE_ENV, GL_COMBINE_RGB_ARB, GL_INTERPOLATE_ARB); + + bglTexEnvf(GL_TEXTURE_ENV, GL_SOURCE0_RGB_ARB, GL_PREVIOUS_ARB); + bglTexEnvf(GL_TEXTURE_ENV, GL_OPERAND0_RGB_ARB, GL_SRC_COLOR); + + bglTexEnvf(GL_TEXTURE_ENV, GL_SOURCE1_RGB_ARB, GL_TEXTURE); + bglTexEnvf(GL_TEXTURE_ENV, GL_OPERAND1_RGB_ARB, GL_SRC_COLOR); + + bglTexEnvf(GL_TEXTURE_ENV, GL_SOURCE2_RGB_ARB, GL_TEXTURE); + bglTexEnvf(GL_TEXTURE_ENV, GL_OPERAND2_RGB_ARB, GL_ONE_MINUS_SRC_ALPHA); + + bglTexEnvf(GL_TEXTURE_ENV, GL_COMBINE_ALPHA_ARB, GL_REPLACE); + bglTexEnvf(GL_TEXTURE_ENV, GL_SOURCE0_ALPHA_ARB, GL_PREVIOUS_ARB); + bglTexEnvf(GL_TEXTURE_ENV, GL_OPERAND0_ALPHA_ARB, GL_SRC_ALPHA); + + bglTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_S,GL_REPEAT); + bglTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_T,GL_REPEAT); + } + //PLAG: delayed polygon-level sorted rendering if (m->usesalpha && !(tspr->cstat & 1024) && !r_depthpeeling) { @@ -1595,7 +1669,14 @@ if (tspr->cstat&2) { if (!(tspr->cstat&512)) pc[3] = 0.66; else pc[3] = 0.33; } for (j=0;j<3;j++) { k = s->tris[indexes[i]].i[j]; - bglTexCoord2f(s->uv[k].u,s->uv[k].v); + if (texunits > GL_TEXTURE0_ARB) + { + l = GL_TEXTURE0_ARB; + while (l <= texunits) + bglMultiTexCoord2fARB(l++, s->uv[k].u,s->uv[k].v); + } + else + bglTexCoord2f(s->uv[k].u,s->uv[k].v); bglVertex3fv((float *)&vertlist[k]); } bglEnd(); @@ -1610,11 +1691,30 @@ if (tspr->cstat&2) { if (!(tspr->cstat&512)) pc[3] = 0.66; else pc[3] = 0.33; } for (j=0;j<3;j++) { k = s->tris[i].i[j]; - bglTexCoord2f(s->uv[k].u,s->uv[k].v); + if (texunits > GL_TEXTURE0_ARB) + { + l = GL_TEXTURE0_ARB; + while (l <= texunits) + bglMultiTexCoord2fARB(l++, s->uv[k].u,s->uv[k].v); + } + else + bglTexCoord2f(s->uv[k].u,s->uv[k].v); bglVertex3fv((float *)&vertlist[k]); } bglEnd(); } + + if (texunits > GL_TEXTURE0_ARB) + { + while (texunits > GL_TEXTURE0_ARB) + { + bglMatrixMode(GL_TEXTURE); + bglLoadIdentity(); + bglMatrixMode(GL_MODELVIEW); + bglDisable(GL_TEXTURE_2D); + bglActiveTextureARB(--texunits); + } + } } //------------ diff --git a/polymer/build/src/polymost.c b/polymer/build/src/polymost.c index c0c89d470..147d3a9a7 100644 --- a/polymer/build/src/polymost.c +++ b/polymer/build/src/polymost.c @@ -152,6 +152,9 @@ GLuint peelprogram[2]; // ARBfp peeling fragment program // Detail mapping cvar long r_detailmapping = 1; +// Glow mapping cvar +long r_glowmapping = 1; + float fogresult, ofogresult, fogcol[4]; void fogcalc (signed char shade, char vis, char pal) @@ -634,33 +637,33 @@ void polymost_glinit() { GLfloat col[4]; int i; - char notpeeledprogramstring[] = - "!!ARBfp1.0\n" - "OPTION ARB_fog_exp2;\n" - "OPTION ARB_fragment_program_shadow;\n" - "TEMP texsample;\n" - "TEMP depthresult;\n" - "TEX depthresult, fragment.position, texture[1], SHADOWRECT;\n" - "ADD depthresult.a, depthresult.a, -0.5;\n" - "KIL depthresult.a;\n" - "TEX texsample, fragment.texcoord[0], texture[0], 2D;\n" - "MUL result.color, fragment.color, texsample;\n" - "END\n"; - char peeledprogramstring[] = - "!!ARBfp1.0\n" - "OPTION ARB_fog_exp2;\n" - "OPTION ARB_fragment_program_shadow;\n" - "TEMP texsample;\n" - "TEMP depthresult;\n" - "TEX depthresult, fragment.position, texture[2], SHADOWRECT;\n" - "ADD depthresult.a, depthresult.a, -0.5;\n" - "KIL depthresult.a;\n" - "TEX depthresult, fragment.position, texture[1], SHADOWRECT;\n" - "ADD depthresult.a, depthresult.a, -0.5;\n" - "KIL depthresult.a;\n" - "TEX texsample, fragment.texcoord[0], texture[0], 2D;\n" - "MUL result.color, fragment.color, texsample;\n" - "END\n"; + char notpeeledprogramstring[] = + "!!ARBfp1.0\n" + "OPTION ARB_fog_exp2;\n" + "OPTION ARB_fragment_program_shadow;\n" + "TEMP texsample;\n" + "TEMP depthresult;\n" + "TEX depthresult, fragment.position, texture[1], SHADOWRECT;\n" + "ADD depthresult.a, depthresult.a, -0.5;\n" + "KIL depthresult.a;\n" + "TEX texsample, fragment.texcoord[0], texture[0], 2D;\n" + "MUL result.color, fragment.color, texsample;\n" + "END\n"; + char peeledprogramstring[] = + "!!ARBfp1.0\n" + "OPTION ARB_fog_exp2;\n" + "OPTION ARB_fragment_program_shadow;\n" + "TEMP texsample;\n" + "TEMP depthresult;\n" + "TEX depthresult, fragment.position, texture[2], SHADOWRECT;\n" + "ADD depthresult.a, depthresult.a, -0.5;\n" + "KIL depthresult.a;\n" + "TEX depthresult, fragment.position, texture[1], SHADOWRECT;\n" + "ADD depthresult.a, depthresult.a, -0.5;\n" + "KIL depthresult.a;\n" + "TEX texsample, fragment.texcoord[0], texture[0], 2D;\n" + "MUL result.color, fragment.color, texsample;\n" + "END\n"; #if 1 if (!Bstrcmp(glinfo.vendor, "ATI Technologies Inc.")) @@ -700,12 +703,18 @@ void polymost_glinit() r_depthpeeling = 0; } - if (r_detailmapping && (!glinfo.multitex)) + if (r_detailmapping && (!glinfo.multitex || !glinfo.envcombine)) { OSD_Printf("Your OpenGL implementation doesn't support detail mapping. Disabling...\n"); r_detailmapping = 0; } + if (r_glowmapping && (!glinfo.multitex || !glinfo.envcombine)) + { + OSD_Printf("Your OpenGL implementation doesn't support glow mapping. Disabling...\n"); + r_glowmapping = 0; + } + //depth peeling initialization if (r_depthpeeling) { @@ -715,67 +724,67 @@ void polymost_glinit() newpeelscount = 0; } // create the secondary Z-buffers and the Z-backbuffer - bglGenTextures(3, ztexture); - - i = 0; - while (i < 3) - { - bglBindTexture(GL_TEXTURE_RECTANGLE, ztexture[i]); - bglCopyTexImage2D(GL_TEXTURE_RECTANGLE, 0, GL_DEPTH_COMPONENT, 0, 0, xdim, ydim, 0); - bglTexParameteri(GL_TEXTURE_RECTANGLE, GL_TEXTURE_MIN_FILTER, GL_NEAREST); - bglTexParameteri(GL_TEXTURE_RECTANGLE, GL_TEXTURE_MAG_FILTER, GL_NEAREST); - bglTexParameteri(GL_TEXTURE_RECTANGLE, GL_TEXTURE_WRAP_S, GL_CLAMP); - bglTexParameteri(GL_TEXTURE_RECTANGLE, GL_TEXTURE_WRAP_T, GL_CLAMP); - bglTexParameteri(GL_TEXTURE_RECTANGLE, GL_TEXTURE_COMPARE_MODE_ARB, GL_COMPARE_R_TO_TEXTURE_ARB); - if (i < 2) - bglTexParameteri(GL_TEXTURE_RECTANGLE, GL_TEXTURE_COMPARE_FUNC_ARB, GL_GREATER); - else - bglTexParameteri(GL_TEXTURE_RECTANGLE, GL_TEXTURE_COMPARE_FUNC_ARB, GL_LESS); - bglTexParameteri(GL_TEXTURE_RECTANGLE, GL_DEPTH_TEXTURE_MODE_ARB, GL_ALPHA); - - i++; - } - - // create the various peeling layers as well as the FBOs to render to them - peels = malloc((r_peelscount + 1) * sizeof(GLuint)); - bglGenTextures(r_peelscount + 1, peels); - - peelfbos = malloc((r_peelscount + 1) * sizeof(GLuint)); - bglGenFramebuffersEXT(r_peelscount + 1, peelfbos); - - i = 0; - while (i <= r_peelscount) - { - bglBindTexture(GL_TEXTURE_RECTANGLE, peels[i]); - bglCopyTexImage2D(GL_TEXTURE_RECTANGLE, 0, GL_RGBA, 0, 0, xdim, ydim, 0); - bglTexParameteri(GL_TEXTURE_RECTANGLE, GL_TEXTURE_MIN_FILTER, GL_NEAREST); - bglTexParameteri(GL_TEXTURE_RECTANGLE, GL_TEXTURE_MAG_FILTER, GL_NEAREST); - bglTexParameteri(GL_TEXTURE_RECTANGLE, GL_TEXTURE_WRAP_S, GL_CLAMP); - bglTexParameteri(GL_TEXTURE_RECTANGLE, GL_TEXTURE_WRAP_T, GL_CLAMP); - - bglBindFramebufferEXT(GL_FRAMEBUFFER_EXT, peelfbos[i]); - bglFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_TEXTURE_RECTANGLE, peels[i], 0); - if (i == r_peelscount) // bakcbuffer - bglFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT, GL_TEXTURE_RECTANGLE, ztexture[2], 0); + bglGenTextures(3, ztexture); + + i = 0; + while (i < 3) + { + bglBindTexture(GL_TEXTURE_RECTANGLE, ztexture[i]); + bglCopyTexImage2D(GL_TEXTURE_RECTANGLE, 0, GL_DEPTH_COMPONENT, 0, 0, xdim, ydim, 0); + bglTexParameteri(GL_TEXTURE_RECTANGLE, GL_TEXTURE_MIN_FILTER, GL_NEAREST); + bglTexParameteri(GL_TEXTURE_RECTANGLE, GL_TEXTURE_MAG_FILTER, GL_NEAREST); + bglTexParameteri(GL_TEXTURE_RECTANGLE, GL_TEXTURE_WRAP_S, GL_CLAMP); + bglTexParameteri(GL_TEXTURE_RECTANGLE, GL_TEXTURE_WRAP_T, GL_CLAMP); + bglTexParameteri(GL_TEXTURE_RECTANGLE, GL_TEXTURE_COMPARE_MODE_ARB, GL_COMPARE_R_TO_TEXTURE_ARB); + if (i < 2) + bglTexParameteri(GL_TEXTURE_RECTANGLE, GL_TEXTURE_COMPARE_FUNC_ARB, GL_GREATER); + else + bglTexParameteri(GL_TEXTURE_RECTANGLE, GL_TEXTURE_COMPARE_FUNC_ARB, GL_LESS); + bglTexParameteri(GL_TEXTURE_RECTANGLE, GL_DEPTH_TEXTURE_MODE_ARB, GL_ALPHA); + + i++; + } + + // create the various peeling layers as well as the FBOs to render to them + peels = malloc((r_peelscount + 1) * sizeof(GLuint)); + bglGenTextures(r_peelscount + 1, peels); + + peelfbos = malloc((r_peelscount + 1) * sizeof(GLuint)); + bglGenFramebuffersEXT(r_peelscount + 1, peelfbos); + + i = 0; + while (i <= r_peelscount) + { + bglBindTexture(GL_TEXTURE_RECTANGLE, peels[i]); + bglCopyTexImage2D(GL_TEXTURE_RECTANGLE, 0, GL_RGBA, 0, 0, xdim, ydim, 0); + bglTexParameteri(GL_TEXTURE_RECTANGLE, GL_TEXTURE_MIN_FILTER, GL_NEAREST); + bglTexParameteri(GL_TEXTURE_RECTANGLE, GL_TEXTURE_MAG_FILTER, GL_NEAREST); + bglTexParameteri(GL_TEXTURE_RECTANGLE, GL_TEXTURE_WRAP_S, GL_CLAMP); + bglTexParameteri(GL_TEXTURE_RECTANGLE, GL_TEXTURE_WRAP_T, GL_CLAMP); + + bglBindFramebufferEXT(GL_FRAMEBUFFER_EXT, peelfbos[i]); + bglFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_TEXTURE_RECTANGLE, peels[i], 0); + if (i == r_peelscount) // bakcbuffer + bglFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT, GL_TEXTURE_RECTANGLE, ztexture[2], 0); else if (i < (r_peelscount - 1)) - bglFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT, GL_TEXTURE_RECTANGLE, ztexture[i % 2], 0); - - if (bglCheckFramebufferStatusEXT(GL_FRAMEBUFFER_EXT) != GL_FRAMEBUFFER_COMPLETE_EXT) - { - OSD_Printf("FBO #%d initialization failed.\n", i); - } - + bglFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT, GL_TEXTURE_RECTANGLE, ztexture[i % 2], 0); + + if (bglCheckFramebufferStatusEXT(GL_FRAMEBUFFER_EXT) != GL_FRAMEBUFFER_COMPLETE_EXT) + { + OSD_Printf("FBO #%d initialization failed.\n", i); + } + bglBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0); - - i++; - } - - // create the peeling fragment programs - bglGenProgramsARB(2, peelprogram); - bglBindProgramARB(GL_FRAGMENT_PROGRAM_ARB, peelprogram[0]); - bglProgramStringARB(GL_FRAGMENT_PROGRAM_ARB, GL_PROGRAM_FORMAT_ASCII_ARB, strlen(notpeeledprogramstring), notpeeledprogramstring); - bglBindProgramARB(GL_FRAGMENT_PROGRAM_ARB, peelprogram[1]); - bglProgramStringARB(GL_FRAGMENT_PROGRAM_ARB, GL_PROGRAM_FORMAT_ASCII_ARB, strlen(peeledprogramstring), peeledprogramstring); + + i++; + } + + // create the peeling fragment programs + bglGenProgramsARB(2, peelprogram); + bglBindProgramARB(GL_FRAGMENT_PROGRAM_ARB, peelprogram[0]); + bglProgramStringARB(GL_FRAGMENT_PROGRAM_ARB, GL_PROGRAM_FORMAT_ASCII_ARB, strlen(notpeeledprogramstring), notpeeledprogramstring); + bglBindProgramARB(GL_FRAGMENT_PROGRAM_ARB, peelprogram[1]); + bglProgramStringARB(GL_FRAGMENT_PROGRAM_ARB, GL_PROGRAM_FORMAT_ASCII_ARB, strlen(peeledprogramstring), peeledprogramstring); } } @@ -1527,7 +1536,8 @@ void drawpoly (double *dpx, double *dpy, long n, long method) long xx, yy, xi, d0, u0, v0, d1, u1, v1, xmodnice = 0, ymulnice = 0, dorot; char dacol = 0, *walptr, *palptr = NULL, *vidp, *vide; #ifdef USE_OPENGL - pthtyp *pth, *detailpth; + pthtyp *pth, *detailpth, *glowpth; + int texunits = GL_TEXTURE0_ARB; #endif // backup of the n for possible redrawing of fullbright long n_ = n, method_ = method; @@ -1630,29 +1640,29 @@ void drawpoly (double *dpx, double *dpy, long n, long method) detailpth = NULL; if (r_detailmapping && usehightile && !r_depthpeeling && indrawroomsandmasks && !drawingskybox && hicfindsubst(globalpicnum, DETAILPAL, 0)) - detailpth = gltexcache(globalpicnum, DETAILPAL,method&(~3)); + detailpth = gltexcache(globalpicnum, DETAILPAL, method&(~3)); if (detailpth && (detailpth->hicr->palnum == DETAILPAL)) { - bglActiveTextureARB(GL_TEXTURE1_ARB); + bglActiveTextureARB(++texunits); bglEnable(GL_TEXTURE_2D); bglBindTexture(GL_TEXTURE_2D, detailpth ? detailpth->glpic : 0); - bglTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE_ARB); + bglTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE_ARB); bglTexEnvf(GL_TEXTURE_ENV, GL_COMBINE_RGB_ARB, GL_MODULATE); - bglTexEnvf(GL_TEXTURE_ENV, GL_SOURCE0_RGB_ARB, GL_PREVIOUS_ARB); - bglTexEnvf(GL_TEXTURE_ENV, GL_OPERAND0_RGB_ARB, GL_SRC_COLOR); + bglTexEnvf(GL_TEXTURE_ENV, GL_SOURCE0_RGB_ARB, GL_PREVIOUS_ARB); + bglTexEnvf(GL_TEXTURE_ENV, GL_OPERAND0_RGB_ARB, GL_SRC_COLOR); - bglTexEnvf(GL_TEXTURE_ENV, GL_SOURCE1_RGB_ARB, GL_TEXTURE); - bglTexEnvf(GL_TEXTURE_ENV, GL_OPERAND1_RGB_ARB, GL_SRC_COLOR); - + bglTexEnvf(GL_TEXTURE_ENV, GL_SOURCE1_RGB_ARB, GL_TEXTURE); + bglTexEnvf(GL_TEXTURE_ENV, GL_OPERAND1_RGB_ARB, GL_SRC_COLOR); + bglTexEnvf(GL_TEXTURE_ENV, GL_COMBINE_ALPHA_ARB, GL_REPLACE); - bglTexEnvf(GL_TEXTURE_ENV, GL_SOURCE0_ALPHA_ARB, GL_PREVIOUS_ARB); - bglTexEnvf(GL_TEXTURE_ENV, GL_OPERAND0_ALPHA_ARB, GL_SRC_ALPHA); - - bglTexEnvf(GL_TEXTURE_ENV, GL_RGB_SCALE_ARB, 2.0f); + bglTexEnvf(GL_TEXTURE_ENV, GL_SOURCE0_ALPHA_ARB, GL_PREVIOUS_ARB); + bglTexEnvf(GL_TEXTURE_ENV, GL_OPERAND0_ALPHA_ARB, GL_SRC_ALPHA); + + bglTexEnvf(GL_TEXTURE_ENV, GL_RGB_SCALE_ARB, 2.0f); bglTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_S,GL_REPEAT); bglTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_T,GL_REPEAT); @@ -1660,14 +1670,48 @@ void drawpoly (double *dpx, double *dpy, long n, long method) f = detailpth ? (1.0f / detailpth->hicr->alphacut) : 1.0; - bglMatrixMode(GL_TEXTURE); - bglLoadIdentity(); - bglScalef(f, f, 1.0f); - bglMatrixMode(GL_MODELVIEW); + bglMatrixMode(GL_TEXTURE); + bglLoadIdentity(); + bglScalef(f, f, 1.0f); + bglMatrixMode(GL_MODELVIEW); } else detailpth = NULL; + glowpth = NULL; + if (r_glowmapping && usehightile && !r_depthpeeling && indrawroomsandmasks && !drawingskybox && + hicfindsubst(globalpicnum, GLOWPAL, 0)) + glowpth = gltexcache(globalpicnum, GLOWPAL, method&(~3)); + + if (glowpth && (glowpth->hicr->palnum == GLOWPAL)) + { + bglActiveTextureARB(++texunits); + + bglEnable(GL_TEXTURE_2D); + bglBindTexture(GL_TEXTURE_2D, glowpth ? glowpth->glpic : 0); + + bglTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE_ARB); + bglTexEnvf(GL_TEXTURE_ENV, GL_COMBINE_RGB_ARB, GL_INTERPOLATE_ARB); + + bglTexEnvf(GL_TEXTURE_ENV, GL_SOURCE0_RGB_ARB, GL_PREVIOUS_ARB); + bglTexEnvf(GL_TEXTURE_ENV, GL_OPERAND0_RGB_ARB, GL_SRC_COLOR); + + bglTexEnvf(GL_TEXTURE_ENV, GL_SOURCE1_RGB_ARB, GL_TEXTURE); + bglTexEnvf(GL_TEXTURE_ENV, GL_OPERAND1_RGB_ARB, GL_SRC_COLOR); + + bglTexEnvf(GL_TEXTURE_ENV, GL_SOURCE2_RGB_ARB, GL_TEXTURE); + bglTexEnvf(GL_TEXTURE_ENV, GL_OPERAND2_RGB_ARB, GL_ONE_MINUS_SRC_ALPHA); + + bglTexEnvf(GL_TEXTURE_ENV, GL_COMBINE_ALPHA_ARB, GL_REPLACE); + bglTexEnvf(GL_TEXTURE_ENV, GL_SOURCE0_ALPHA_ARB, GL_PREVIOUS_ARB); + bglTexEnvf(GL_TEXTURE_ENV, GL_OPERAND0_ALPHA_ARB, GL_SRC_ALPHA); + + bglTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_S,GL_REPEAT); + bglTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_T,GL_REPEAT); + } + else + glowpth = NULL; + if (pth && (pth->flags & 2)) { hackscx = pth->scalex; @@ -1863,10 +1907,11 @@ void drawpoly (double *dpx, double *dpy, long n, long method) up = ox*ngux + oy*nguy + nguo; vp = ox*ngvx + oy*ngvy + ngvo; r = 1.0/dp; - if (detailpth) + if (texunits > GL_TEXTURE0_ARB) { - bglMultiTexCoord2dARB(GL_TEXTURE0_ARB, (up*r-du0+uoffs)*ox2,vp*r*oy2); - bglMultiTexCoord2dARB(GL_TEXTURE1_ARB, (up*r-du0+uoffs)*ox2,vp*r*oy2); + j = GL_TEXTURE0_ARB; + while (j <= texunits) + bglMultiTexCoord2dARB(j++, (up*r-du0+uoffs)*ox2,vp*r*oy2); } else bglTexCoord2d((up*r-du0+uoffs)*ox2,vp*r*oy2); @@ -1882,21 +1927,31 @@ void drawpoly (double *dpx, double *dpy, long n, long method) for (i=0;i GL_TEXTURE0_ARB) { - bglMultiTexCoord2dARB(GL_TEXTURE0_ARB, uu[i]*r*ox2,vv[i]*r*oy2); - bglMultiTexCoord2dARB(GL_TEXTURE1_ARB, uu[i]*r*ox2,vv[i]*r*oy2); + j = GL_TEXTURE0_ARB; + while (j <= texunits) + bglMultiTexCoord2dARB(j++, uu[i]*r*ox2,vv[i]*r*oy2); } - bglTexCoord2d(uu[i]*r*ox2,vv[i]*r*oy2); + else + bglTexCoord2d(uu[i]*r*ox2,vv[i]*r*oy2); bglVertex3d((px[i]-ghalfx)*r*grhalfxdown10x,(ghoriz-py[i])*r*grhalfxdown10,r*(1.0/1024.0)); } bglEnd(); } - if (detailpth) + + if (texunits > GL_TEXTURE0_ARB) { - bglDisable(GL_TEXTURE_2D); - bglActiveTextureARB(GL_TEXTURE0_ARB); + while (texunits > GL_TEXTURE0_ARB) + { + bglMatrixMode(GL_TEXTURE); + bglLoadIdentity(); + bglMatrixMode(GL_MODELVIEW); + bglDisable(GL_TEXTURE_2D); + bglActiveTextureARB(--texunits); + } } + if (fullbrightdrawingpass == 1) // tile has fullbright colors ? { fullbrightdrawingpass = 2; @@ -3702,7 +3757,7 @@ void polymost_drawrooms () } if (r_depthpeeling) { - bglBindFramebufferEXT(GL_FRAMEBUFFER_EXT, peelfbos[r_peelscount]); + bglBindFramebufferEXT(GL_FRAMEBUFFER_EXT, peelfbos[r_peelscount]); bglPushAttrib(GL_VIEWPORT_BIT); bglViewport(0, 0, xdim, ydim); //bglClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT); @@ -5228,7 +5283,7 @@ static int osdcmd_polymostvars(const osdfuncparm_t *parm) else if (!Bstrcasecmp(parm->name, "r_detailmapping")) { if (showval) { OSD_Printf("r_detailmapping is %d\n", r_detailmapping); } else { - if (!glinfo.multitex) + if (!glinfo.multitex || !glinfo.envcombine) { OSD_Printf("Your OpenGL implementation doesn't support detail mapping.\n"); r_detailmapping = 0; @@ -5238,6 +5293,19 @@ static int osdcmd_polymostvars(const osdfuncparm_t *parm) } return OSDCMD_OK; } + else if (!Bstrcasecmp(parm->name, "r_glowmapping")) { + if (showval) { OSD_Printf("r_glowmapping is %d\n", r_glowmapping); } + else { + if (!glinfo.multitex || !glinfo.envcombine) + { + OSD_Printf("Your OpenGL implementation doesn't support glow mapping.\n"); + r_glowmapping = 0; + return OSDCMD_OK; + } + r_glowmapping = (val != 0); + } + return OSDCMD_OK; + } else if (!Bstrcasecmp(parm->name, "glpolygonmode")) { if (showval) { OSD_Printf("glpolygonmode is %d\n", glpolygonmode); } else glpolygonmode = val; @@ -5322,7 +5390,8 @@ void polymost_initosdfuncs(void) OSD_RegisterFunction("r_depthpeeling","r_depthpeeling: enable/disable order-independant transparency",osdcmd_polymostvars); OSD_RegisterFunction("r_peelscount","r_peelscount: sets the number of depth layers for depth peeling",osdcmd_polymostvars); OSD_RegisterFunction("r_curpeel","r_curpeel: allows to display one depth layer at a time (for development purposes)",osdcmd_polymostvars); - OSD_RegisterFunction("r_detailmapping","r_detailmapping: enable/disable detail-mapping",osdcmd_polymostvars); + OSD_RegisterFunction("r_detailmapping","r_detailmapping: enable/disable detail mapping",osdcmd_polymostvars); + OSD_RegisterFunction("r_glowmapping","r_glowmapping: enable/disable glow mapping",osdcmd_polymostvars); #endif OSD_RegisterFunction("usemodels","usemodels: enable/disable model rendering in >8-bit mode",osdcmd_polymostvars); OSD_RegisterFunction("usehightile","usehightile: enable/disable hightile texture rendering in >8-bit mode",osdcmd_polymostvars); @@ -5359,7 +5428,7 @@ void polymost_precache(long dapicnum, long dapalnum, long datype) j = ((md3model *)models[mid])->head.numsurfs; for (i=0;i<=j;i++) - mdloadskin((md2model*)models[mid], 0, dapalnum, i); + mdloadskin((md2model*)models[mid], 0, dapalnum, i, 0); } #endif } diff --git a/polymer/eduke32/eduke32.sln b/polymer/eduke32/eduke32.sln index 549b538df..226519e84 100644 --- a/polymer/eduke32/eduke32.sln +++ b/polymer/eduke32/eduke32.sln @@ -57,7 +57,6 @@ Global {CD149A75-4507-404D-856C-E9DBC2E0B286}.HRP SD Release|Win32.ActiveCfg = Release|Win32 {CD149A75-4507-404D-856C-E9DBC2E0B286}.HRP SD Release|Win32.Build.0 = Release|Win32 {CD149A75-4507-404D-856C-E9DBC2E0B286}.HRP SD|Win32.ActiveCfg = Release|Win32 - {CD149A75-4507-404D-856C-E9DBC2E0B286}.HRP SD|Win32.Build.0 = Release|Win32 {862365FE-811C-46B8-BB1E-B7189DA8D858}.Classic JFAud|Win32.ActiveCfg = Release|Win32 {862365FE-811C-46B8-BB1E-B7189DA8D858}.Classic JFAud|Win32.Build.0 = Release|Win32 {862365FE-811C-46B8-BB1E-B7189DA8D858}.Classic Release JFAud|Win32.ActiveCfg = Release|Win32 @@ -73,7 +72,6 @@ Global {862365FE-811C-46B8-BB1E-B7189DA8D858}.HRP SD Release|Win32.ActiveCfg = Release|Win32 {862365FE-811C-46B8-BB1E-B7189DA8D858}.HRP SD Release|Win32.Build.0 = Release|Win32 {862365FE-811C-46B8-BB1E-B7189DA8D858}.HRP SD|Win32.ActiveCfg = Release|Win32 - {862365FE-811C-46B8-BB1E-B7189DA8D858}.HRP SD|Win32.Build.0 = Release|Win32 EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/polymer/eduke32/source/config.c b/polymer/eduke32/source/config.c index 521662f88..92208e1b3 100644 --- a/polymer/eduke32/source/config.c +++ b/polymer/eduke32/source/config.c @@ -680,6 +680,7 @@ int32 CONFIG_ReadSetup(void) SCRIPT_GetNumber(scripthandle, "Screen Setup", "GLPeelsCount", &r_peelscount); SCRIPT_GetNumber(scripthandle, "Screen Setup", "GLDetailMapping", &r_detailmapping); + SCRIPT_GetNumber(scripthandle, "Screen Setup", "GLGlowMapping", &r_glowmapping); dummy = usemodels; SCRIPT_GetNumber(scripthandle, "Screen Setup", "UseModels",&dummy); @@ -832,6 +833,7 @@ void CONFIG_WriteSetup(void) SCRIPT_PutNumber(scripthandle, "Screen Setup", "GLPeelsCount",r_peelscount,false,false); SCRIPT_PutNumber(scripthandle, "Screen Setup", "GLDetailMapping", r_detailmapping,false,false); + SCRIPT_PutNumber(scripthandle, "Screen Setup", "GLGlowMapping", r_glowmapping,false,false); #endif #ifdef RENDERTYPEWIN SCRIPT_PutNumber(scripthandle, "Screen Setup", "MaxRefreshFreq",maxrefreshfreq,false,false);