diff --git a/polymer/build/Makefile b/polymer/build/Makefile index 9c4c02de7..c218a6890 100644 --- a/polymer/build/Makefile +++ b/polymer/build/Makefile @@ -92,7 +92,8 @@ ENGINEOBJS+= \ $(OBJ)mmulti.$o \ $(OBJ)osd.$o \ $(OBJ)pragmas.$o \ - $(OBJ)scriptfile.$o + $(OBJ)scriptfile.$o \ + $(OBJ)polymer.$o EDITOROBJS=$(OBJ)build.$o \ $(OBJ)config.$o diff --git a/polymer/build/Makefile.deps b/polymer/build/Makefile.deps index aa333df09..b965ab1bb 100644 --- a/polymer/build/Makefile.deps +++ b/polymer/build/Makefile.deps @@ -9,7 +9,7 @@ $(OBJ)compat.$o: $(SRC)compat.c $(INC)compat.h $(OBJ)config.$o: $(SRC)config.c $(INC)compat.h $(INC)osd.h $(INC)editor.h $(OBJ)crc32.$o: $(SRC)crc32.c $(INC)crc32.h $(OBJ)defs.$o: $(SRC)defs.c $(INC)build.h $(INC)baselayer.h $(INC)scriptfile.h $(INC)compat.h -$(OBJ)engine.$o: $(SRC)engine.c $(SRC)polymost.c $(INC)kplib.h $(SRC)hightile.c $(SRC)mdsprite.c $(INC)md4.h $(INC)lzf.h $(INC)lzwnew.h $(INC)compat.h $(INC)build.h $(INC)pragmas.h $(INC)cache1d.h $(INC)a.h $(INC)osd.h $(INC)baselayer.h +$(OBJ)engine.$o: $(SRC)engine.c $(SRC)polymost.c $(INC)kplib.h $(SRC)hightile.c $(SRC)mdsprite.c $(INC)md4.h $(INC)lzf.h $(INC)lzwnew.h $(INC)compat.h $(INC)build.h $(INC)pragmas.h $(INC)cache1d.h $(INC)a.h $(INC)osd.h $(INC)baselayer.h $(INC)polymer.h $(OBJ)glbuild.$o: $(SRC)glbuild.c $(INC)glbuild.h $(INC)baselayer.h $(OBJ)kplib.$o: $(SRC)kplib.c $(INC)compat.h $(OBJ)lzf_c.$o: $(SRC)lzf_c.c $(SRC)lzfP.h @@ -26,6 +26,7 @@ $(OBJ)sound.$o: $(SRC)sound.c $(INC)osd.h $(INC)compat.h $(INC)cache1d.h $(OBJ)winlayer.$o: $(SRC)winlayer.c $(INC)compat.h $(INC)winlayer.h $(INC)baselayer.h $(INC)pragmas.h $(INC)build.h $(INC)a.h $(INC)osd.h $(INC)dxdidf.h $(INC)glbuild.h $(OBJ)gtkbits.$o: $(SRC)gtkbits.c $(INC)baselayer.h $(INC)build.h $(INC)dynamicgtk.h $(OBJ)dynamicgtk.$o: $(SRC)dynamicgtk.c $(INC)dynamicgtk.h +$(OBJ)polymer.$o: $(SRC)polymer.c $(INC)polymer.h # KenBuild test game $(OBJ)game.$o: $(GAME)game.c $(INC)compat.h $(INC)build.h $(GAME)names.h $(INC)pragmas.h $(INC)cache1d.h $(GAME)game.h $(INC)osd.h $(INC)baselayer.h diff --git a/polymer/build/include/glbuild.h b/polymer/build/include/glbuild.h index 1274e045d..ed642c48b 100644 --- a/polymer/build/include/glbuild.h +++ b/polymer/build/include/glbuild.h @@ -61,6 +61,7 @@ extern void (APIENTRY * bglPushMatrix)( void ); extern void (APIENTRY * bglPopMatrix)( void ); extern void (APIENTRY * bglLoadIdentity)( void ); extern void (APIENTRY * bglLoadMatrixf)( const GLfloat *m ); +extern void (APIENTRY * bglRotatef)(GLfloat angle, GLfloat x, GLfloat y, GLfloat z); // Drawing extern void (APIENTRY * bglBegin)( GLenum mode ); diff --git a/polymer/build/src/baselayer.c b/polymer/build/src/baselayer.c index 9999f7479..65bdddd7b 100644 --- a/polymer/build/src/baselayer.c +++ b/polymer/build/src/baselayer.c @@ -34,13 +34,13 @@ static int osdfunc_setrendermode(const osdfuncparm_t *parm) char *modestrs[] = { "classic software", "polygonal flat-shaded software", - "polygonal textured software", "polygonal OpenGL" + "polygonal textured software", "polygonal OpenGL", "blah" }; if (parm->numparms != 1) return OSDCMD_SHOWHELP; m = Bstrtol(parm->parms[0], &p, 10); - if (m < 0 || m > 3) return OSDCMD_SHOWHELP; + if (m < 0 || m > 4) return OSDCMD_SHOWHELP; setrendermode(m); OSD_Printf("Rendering method changed to %s\n", modestrs[ getrendermode() ] ); @@ -165,6 +165,7 @@ int baselayer_init(void) " 2 - Polygonal textured software\n" #ifdef USE_OPENGL " 3 - Polygonal OpenGL\n" + " 4 - great justice renderer\n" #endif , osdfunc_setrendermode); diff --git a/polymer/build/src/engine.c b/polymer/build/src/engine.c index db886dbae..44316ca33 100644 --- a/polymer/build/src/engine.c +++ b/polymer/build/src/engine.c @@ -27,6 +27,7 @@ # endif # ifdef USE_OPENGL # include "glbuild.h" +# include "polymer.h" # endif #endif @@ -694,9 +695,7 @@ int hicclearsubst(long picnum, long palnum) { return 0; } long polymost_drawtilescreen (long tilex, long tiley, long wallnum, long dimen) { return -1; } #endif //============================================================================= //POLYMOST ENDS -#if defined(POLYMOST) && defined(USE_OPENGL) -#include "polymer.c" -#endif + // // getpalookup (internal) // @@ -3123,7 +3122,13 @@ static void drawsprite(long snum) //============================================================================= //POLYMOST BEGINS #ifdef POLYMOST - if (rendmode) { polymost_drawsprite(snum); return; } + if (rendmode) { + polymost_drawsprite(snum); + #ifdef USE_OPENGL + bglDepthMask(1); + #endif + return; + } #endif //============================================================================= //POLYMOST ENDS @@ -4141,7 +4146,7 @@ static void fillpolygon(long npoints) short *ptr, *ptr2; #if defined POLYMOST && defined USE_OPENGL - if (rendmode == 3) { polymost_fillpolygon(npoints); return; } + if (rendmode >= 3) { polymost_fillpolygon(npoints); return; } #endif miny = 0x7fffffff; maxy = 0x80000000; @@ -5675,13 +5680,12 @@ void drawrooms(long daposx, long daposy, long daposz, umost[0] = shortptr1[0]-windowy1; dmost[0] = shortptr2[0]-windowy1; -#if defined(POLYMOST) && defined(USE_OPENGL) - if (0) + if (rendmode == 4) { - polymer_drawrooms(); + polymer_drawrooms(daposx, daposy, daposz, daang, dahoriz, dacursectnum); return; } -#endif + //============================================================================= //POLYMOST BEGINS #ifdef POLYMOST polymost_drawrooms(); if (rendmode) { return; } @@ -5780,16 +5784,138 @@ void drawrooms(long daposx, long daposy, long daposz, enddrawing(); //}}} } +// UTILITY TYPES AND FUNCTIONS FOR DRAWMASKS OCCLUSION TREE +typedef struct s_point2d { + long x, y; +} _point2d; + +typedef struct s_equation { + float a, b, c; +} _equation; + +typedef struct s_maskleaf { + long index; + _point2d p1, p2; + _equation maskeq, p1eq, p2eq; + struct s_maskleaf* branch[MAXWALLSB]; + int drawing; +} _maskleaf; + +_maskleaf maskleaves[MAXWALLSB]; + +// returns equation of a line given two points +_equation equation(long x1, long y1, long x2, long y2) +{ + _equation ret; + + if ((x2 - x1) != 0) + { + ret.a = (float)(y2 - y1)/(x2 - x1); + ret.b = -1; + ret.c = (y1 - (ret.a * x1)); + } + else // vertical + { + ret.a = 1; + ret.b = 0; + ret.c = -x1; + } + + return (ret); +} + +// returns the intersection point between two lines +_point2d intersection(_equation eq1, _equation eq2) +{ + _point2d ret; + float det; + + det = (float)(1) / (eq1.a*eq2.b - eq2.a*eq1.b); + ret.x = ((eq1.b*eq2.c - eq2.b*eq1.c) * det); + ret.y = ((eq2.a*eq1.c - eq1.a*eq2.c) * det); + + return (ret); +} + +// check if a point that's on the line is within the segment boundaries +int pointonmask(_point2d point, _maskleaf* wall) +{ + if ((min(wall->p1.x, wall->p2.x) <= point.x) && (point.x <= max(wall->p1.x, wall->p2.x)) && (min(wall->p1.y, wall->p2.y) <= point.y) && (point.y <= max(wall->p1.y, wall->p2.y))) + return (1); + return (0); +} + +// returns 1 if wall2 is hidden by wall1 +int wallobstructswall(_maskleaf* wall1, _maskleaf* wall2) +{ + _point2d cross; + + cross = intersection(wall2->p1eq, wall1->maskeq); + if (pointonmask(cross, wall1)) + return (1); + + cross = intersection(wall2->p2eq, wall1->maskeq); + if (pointonmask(cross, wall1)) + return (1); + + cross = intersection(wall1->p1eq, wall2->maskeq); + if (pointonmask(cross, wall2)) + return (1); + + cross = intersection(wall1->p2eq, wall2->maskeq); + if (pointonmask(cross, wall2)) + return (1); + + return (0); +} + +// recursive mask drawing function +void drawmaskleaf(_maskleaf* wall) +{ + int i; + + wall->drawing = 1; + i = 0; + while (wall->branch[i] != NULL) + { + if (wall->branch[i]->drawing == 0) + { + //OSD_Printf("Drawing parent of %i : mask %i\n", wall->index, wall->branch[i]->index); + drawmaskleaf(wall->branch[i]); + } + i++; + } + + //OSD_Printf("Drawing mask %i\n", wall->index); + drawmaskwall(wall->index); +} + +int sameside(_equation* eq, _point2d* p1, _point2d* p2) +{ + float sign1, sign2; + + sign1 = eq->a * p1->x + eq->b * p1->y + eq->c; + sign2 = eq->a * p2->x + eq->b * p2->y + eq->c; + + sign1 = sign1 * sign2; + if (sign1 > 0) + { + //OSD_Printf("SAME SIDE !\n"); + return (1); + } + //OSD_Printf("OPPOSITE SIDE !\n"); + return (0); +} // // drawmasks // void drawmasks(void) { - long i, j, k, l, gap, xs, ys, xp, yp, yoff, yspan; + long i, j, k, l, m, gap, xs, ys, xp, yp, yoff, yspan; // PLAG: sorting stuff - long *indexes, *wallindexes, *depths, *walldepths; - long x, y; + _equation maskeq, p1eq, p2eq; + _point2d dot, dot2, middle, pos, spr; for(i=spritesortcnt-1;i>=0;i--) tspriteptr[i] = &tsprite[i]; for(i=spritesortcnt-1;i>=0;i--) @@ -5983,7 +6109,7 @@ killsprite: // bubblesort is used, shouldn't cause any problems cpu-wise since the lists are small // SPRITES PREPROCESSING - l = spritesortcnt; + /*l = spritesortcnt; indexes = malloc(l * sizeof(long)); depths = malloc(l * sizeof(long)); @@ -6011,63 +6137,61 @@ killsprite: j = 0; } } - } + }*/ // MASKS PREPROCESSING - k = maskwallcnt; - wallindexes = malloc(k * sizeof(long)); - walldepths = malloc(k * sizeof(long)); + //k = maskwallcnt; - // first pass to set base indexes and depths + // first pass to set wall equations and init the tree + /*i = k; + while (i > 0) + { + i--; + + // leaf index + maskleaves[i].index = --maskwallcnt; + + // leaf boundaries + maskleaves[i].p1.x = wall[thewall[maskwall[maskleaves[i].index]]].x - globalposx; + maskleaves[i].p1.y = wall[thewall[maskwall[maskleaves[i].index]]].y - globalposy; + maskleaves[i].p2.x = wall[wall[thewall[maskwall[maskleaves[i].index]]].point2].x - globalposx; + maskleaves[i].p2.y = wall[wall[thewall[maskwall[maskleaves[i].index]]].point2].y - globalposy; + + // leaf equations + maskleaves[i].maskeq = equation(maskleaves[i].p1.x, maskleaves[i].p1.y, maskleaves[i].p2.x, maskleaves[i].p2.y); + maskleaves[i].p1eq = equation(0, 0, maskleaves[i].p1.x, maskleaves[i].p1.y); + maskleaves[i].p2eq = equation(0, 0, maskleaves[i].p2.x, maskleaves[i].p2.y); + + // drawing flag + maskleaves[i].drawing = 0; + + //OSD_Printf("Processed mask - %i\n", i); + } + + // second pass to connect the leaves together i = k; while (i > 0) { i--; - wallindexes[i] = --maskwallcnt; - xs = wall[thewall[maskwall[wallindexes[i]]]].x; - ys = wall[thewall[maskwall[wallindexes[i]]]].y; - xp = wall[wall[thewall[maskwall[wallindexes[i]]]].point2].x; - yp = wall[wall[thewall[maskwall[wallindexes[i]]]].point2].y; - - x = ((xs + xp) / 2) - globalposx; - y = ((ys + yp) / 2) - globalposy; - walldepths[i] = (x * x) + (y * y); - } - - // second pass (and possibly more) to sort - j = 0; - while (j == 0) - { - j = 1; - for(i=k-1;i>0;i--) - { - if (walldepths[i] < walldepths[i-1]) - { - swaplong(&wallindexes[i-1], &wallindexes[i]); - swaplong(&walldepths[i-1], &walldepths[i]); - j = 0; - } - } - } - - // DRAWING - // in this code all sprites are drawn, and masks are inserted when needed - i = l - 1; - while (i >= 0) - { + m = 0; j = k; while (j > 0) { j--; - // if a mask is farther than the sprite which is about to be drawn, we draw it before then discard it from the stack - if ((wallindexes[j] >= 0) && (spriteobstructswall(tspriteptr[indexes[i]],(long)thewall[maskwall[wallindexes[j]]]))) - { - //OSD_Printf("masked - %i\n", walldepths[j]); - drawmaskwall(wallindexes[j]); - wallindexes[j] = -1; - } + + if ((i != j) && (wallobstructswall(&maskleaves[i], &maskleaves[j]))) + maskleaves[i].branch[m++] = &maskleaves[j]; } + maskleaves[i].branch[m] = NULL; + //OSD_Printf("Processed parents for mask %i\n", i); + }*/ + + // DRAWING + // in this code all sprites are drawn, and masks are inserted when needed + /*i = l - 1; + while (i >= 0) + { //OSD_Printf("sprite - %i\n", depths[i]); drawsprite(indexes[i]); i--; @@ -6077,16 +6201,69 @@ killsprite: while (k > 0) { k--; - if (wallindexes[k] >= 0) - { - //OSD_Printf("masked - %i\n", walldepths[k]); - drawmaskwall(wallindexes[k]); - } + //OSD_Printf("Beginning drawing process for mask %i\n", k); + //drawmaskleaf(&maskleaves[k]); + drawmaskwall(k); } free(indexes); - free(wallindexes); - free(depths); - free(walldepths); + free(depths);*/ + + pos.x = globalposx; + pos.y = globalposy; + + //OSD_Printf("EIN OBSERVER POSITION : x=%i y=%i\n", pos.x, pos.y); + + while (maskwallcnt) + { + maskwallcnt--; + + dot.x = wall[thewall[maskwall[maskwallcnt]]].x; + dot.y = wall[thewall[maskwall[maskwallcnt]]].y; + dot2.x = wall[wall[thewall[maskwall[maskwallcnt]]].point2].x; + dot2.y = wall[wall[thewall[maskwall[maskwallcnt]]].point2].y; + + //OSD_Printf("EIN WALL : x1=%i y1=%i x2=%i y2=%i\n", dot.x, dot.y, dot2.x, dot2.y); + + maskeq = equation(dot.x, dot.y, dot2.x, dot2.y); + p1eq = equation(pos.x, pos.y, dot.x, dot.y); + p2eq = equation(pos.x, pos.y, dot2.x, dot2.y); + + //OSD_Printf("EIN WALL EQUATION : a=%f b=%f c=%f\n", maskeq.a, maskeq.b, maskeq.c); + //OSD_Printf("EIN WALL POINT1 TO POSITION EQUATION : a=%f b=%f c=%f\n", p1eq.a, p1eq.b, p1eq.c); + //OSD_Printf("EIN WALL POINT2 TO POSITION EQUATION : a=%f b=%f c=%f\n", p2eq.a, p2eq.b, p2eq.c); + + middle.x = (dot.x + dot2.x) / 2; + middle.y = (dot.y + dot2.y) / 2; + + //OSD_Printf("EIN WALL MIDDLE POINT POSITION : x=%i y=%i\n", middle.x, middle.y); + + i = spritesortcnt; + while (i) + { + i--; + if (tspriteptr[i] != NULL) + { + spr.x = tspriteptr[i]->x; + spr.y = tspriteptr[i]->y; + + //OSD_Printf("EIN SPRITE POSITION : x=%i y=%i\n", spr.x, spr.y); + + if ((sameside(&maskeq, &spr, &pos) == 0) && sameside(&p1eq, &middle, &spr) && sameside(&p2eq, &middle, &spr)) + { + drawsprite(i); + tspriteptr[i] = NULL; + } + } + } + drawmaskwall(maskwallcnt); + } + + while (spritesortcnt) + { + spritesortcnt--; + if (tspriteptr[spritesortcnt] != NULL) + drawsprite(spritesortcnt); + } #endif /* goodalpha */ indrawroomsandmasks = 0; @@ -7219,10 +7396,11 @@ long setgamemode(char davidoption, long daxdim, long daydim, long dabpp) if (searchx < 0) { searchx = halfxdimen; searchy = (ydimen>>1); } #if defined(POLYMOST) && defined(USE_OPENGL) - if (rendmode == 3) { + if (rendmode == 3) polymost_glinit(); - polymost_glreset(); - } + else if (rendmode == 4) + polymer_glinit(); + polymost_glreset(); #endif qsetmode = 200; return(0); @@ -9360,7 +9538,7 @@ void setbrightness(char dabrightness, char *dapal, char noapply) if ((noapply&1) == 0) setpalette(0,256,(char*)tempbuf); #if defined(POLYMOST) && defined(USE_OPENGL) - if (rendmode == 3) { + if (rendmode >= 3) { newpalettesum = crc32once((unsigned char *)curpalettefaded, sizeof(curpalettefaded)); // only reset the textures if the preserve flag (bit 1 of noapply) is clear and @@ -9426,7 +9604,7 @@ void clearview(long dacol) if (qsetmode != 200) return; #if defined(POLYMOST) && defined(USE_OPENGL) - if (rendmode == 3) { + if (rendmode >= 3) { palette_t p; if (gammabrightness) p = curpalette[dacol]; else { @@ -9467,7 +9645,7 @@ void clearallviews(long dacol) //dacol += (dacol<<8); dacol += (dacol<<16); #if defined(POLYMOST) && defined(USE_OPENGL) - if (rendmode == 3) { + if (rendmode >= 3) { palette_t p; if (gammabrightness) p = curpalette[dacol]; else { @@ -9501,7 +9679,7 @@ void clearallviews(long dacol) void plotpixel(long x, long y, char col) { #if defined(POLYMOST) && defined(USE_OPENGL) - if (rendmode == 3 && qsetmode == 200) { + if (rendmode >= 3 && qsetmode == 200) { palette_t p; if (gammabrightness) p = curpalette[col]; else { @@ -9535,7 +9713,7 @@ char getpixel(long x, long y) char r; #if defined(POLYMOST) && defined(USE_OPENGL) - if (rendmode == 3 && qsetmode == 200) return 0; + if (rendmode >= 3 && qsetmode == 200) return 0; #endif begindrawing(); //{{{ @@ -9901,7 +10079,7 @@ void drawline256(long x1, long y1, long x2, long y2, char col) col = palookup[0][col]; #if defined(POLYMOST) && defined(USE_OPENGL) - if (rendmode == 3) + if (rendmode >= 3) { palette_t p; if (gammabrightness) p = curpalette[col]; @@ -10787,7 +10965,7 @@ void printext256(long xpos, long ypos, short col, short backcol, char *name, cha #if defined(POLYMOST) && defined(USE_OPENGL) if (!polymost_printext256(xpos,ypos,col,backcol,name,fontsize)) return; - if (rendmode == 3) { + if (rendmode >= 3) { long xx, yy; int lc=-1; palette_t p,b; @@ -10921,7 +11099,7 @@ long screencapture_tga(char *filename, char inverseit) // palette first #if defined(POLYMOST) && defined(USE_OPENGL) - if (rendmode < 3 || (rendmode == 3 && qsetmode != 200)) { + if (rendmode < 3 || (rendmode >= 3 && qsetmode != 200)) { #endif //getpalette(0,256,palette); for (i=0; i<256; i++) { @@ -11122,7 +11300,7 @@ long screencapture_pcx(char *filename, char inverseit) // palette last #if defined(POLYMOST) && defined(USE_OPENGL) - if (rendmode < 3 || (rendmode == 3 && qsetmode != 200)) { + if (rendmode < 3 || (rendmode >= 3 && qsetmode != 200)) { #endif //getpalette(0,256,palette); Bfputc(12,fil); @@ -11162,9 +11340,13 @@ int setrendermode(int renderer) if (renderer < 0) renderer = 0; else if (renderer > 2) renderer = 2; } else { - renderer = 3; + if (renderer < 3) renderer = 3; + else if (renderer > 4) renderer = 4; } + if (renderer == 4) + polymer_init(); + rendmode = renderer; #endif diff --git a/polymer/build/src/glbuild.c b/polymer/build/src/glbuild.c index fa61aa4bf..9a5950aae 100644 --- a/polymer/build/src/glbuild.c +++ b/polymer/build/src/glbuild.c @@ -47,6 +47,7 @@ void (APIENTRY * bglPushMatrix)( void ); void (APIENTRY * bglPopMatrix)( void ); void (APIENTRY * bglLoadIdentity)( void ); void (APIENTRY * bglLoadMatrixf)( const GLfloat *m ); +void (APIENTRY * bglRotatef)(GLfloat angle, GLfloat x, GLfloat y, GLfloat z); // Drawing void (APIENTRY * bglBegin)( GLenum mode ); @@ -200,6 +201,7 @@ int loadgldriver(const char *driver) bglPopMatrix = GETPROC("glPopMatrix"); bglLoadIdentity = GETPROC("glLoadIdentity"); bglLoadMatrixf = GETPROC("glLoadMatrixf"); + bglRotatef = GETPROC("glRotatef"); // Drawing bglBegin = GETPROC("glBegin"); diff --git a/polymer/build/src/polymer.c b/polymer/build/src/polymer.c index d44333aa1..0348af26a 100644 --- a/polymer/build/src/polymer.c +++ b/polymer/build/src/polymer.c @@ -1,32 +1,150 @@ -//placeholder placeholder lol +// blah + +#include "compat.h" +#include "build.h" +#include "glbuild.h" +#include "osd.h" + +typedef struct s_prvertex { + float x; + float y; + float z; + short wallnum; +} _prvertex; + +typedef struct s_prtriangle { + int index[3]; +} _prtriangle; + +typedef struct s_prsector { + _prvertex* v; + _prtriangle* tris; +} _prsector; + +_prsector* prsectors[MAXSECTORS]; + +void polymer_init(void) +{ + int i; + + OSD_Printf("Initalizing Polymer subsystem.\n"); + + i = 0; + while (i < MAXSECTORS) + { + prsectors[i] = NULL; + i++; + } +} void polymer_glinit(void) { bglClearColor(0.0f, 0.0f, 0.0f, 1.0f); - bglClear(GL_COLOR_BUFFER_BIT); + bglClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); bglViewport(0, 0, 1024, 768); bglDisable(GL_TEXTURE_2D); + bglDisable(GL_FOG); bglEnable(GL_DEPTH_TEST); bglMatrixMode(GL_PROJECTION); bglLoadIdentity(); - bglFrustum(-1.0f, 1.0f, -0.75f, 0.75, 1.0f, 100.0f); + bglFrustum(-1.0f, 1.0f, -0.75f, 0.75, 1.0f, 10000.0f); bglMatrixMode(GL_MODELVIEW); bglLoadIdentity(); } - -void polymer_drawsector(short sectnum) + +void polymer_buildsector(short sectnum) +{ + _prsector* s; + sectortype *sec, *nextsec; + walltype *wal, *wal2; + int i; + + OSD_Printf("Polymer: building sector %i\n", sectnum); + + s = malloc(sizeof(_prsector)); + memset(s, 0, sizeof(_prsector)); + + sec = §or[sectnum]; + wal = &wall[sec->wallptr]; + + s->v = malloc(sizeof(_prvertex) * sec->wallnum); + + i = 0; + while (i < sec->wallnum) + { + s->v[i].wallnum = sec->wallptr + i; + s->v[i].z = -wal->x; + s->v[i].x = wal->y; + s->v[i].y = -sec->floorz; + + i++; + wal = &wall[sec->wallptr + i]; + } + + prsectors[sectnum] = s; +} + +void polymer_drawsector(long daposx, long daposy, long daposz, short daang, long dahoriz, short sectnum) { sectortype *sec; - walltype *wal; + int i; + float ang; + _prvertex v, pos; - sec = §or[sectnum]; - wal = &wall[sec->wallptr]; - OSD_Printf("%i\n", sec->wallnum); + OSD_Printf("Polymer: drawing sector %i with angle %i\n", sectnum, daang); + + //if (prsectors[sectnum] == NULL) + polymer_buildsector(sectnum); + + ang = (float)(daang) / (2048.0f / 360.0f); + + sec = §or[sectnum]; + + bglMatrixMode(GL_MODELVIEW); + bglLoadIdentity(); + bglRotatef(ang, 0.0f, 1.0f, 0.0f); + + bglBegin(GL_LINE_LOOP); + bglColor4f(1.0f, 1.0f, 1.0f, 1.0f); + + pos.x = daposy; + pos.y = -daposz; + pos.z = -daposx; + i = 0; + while (i < sec->wallnum) + { + v.x = (float)(prsectors[sectnum]->v[i].x - pos.x) / 1; + v.y = (float)(prsectors[sectnum]->v[i].y - pos.y) / (15.66 * 1); + v.z = (float)(prsectors[sectnum]->v[i].z - pos.z) / 1; + //OSD_Printf("Polymer: drawing poly %f, %f, %f\n", v.x, v.y, v.z); + bglVertex3d(v.x, v.y, v.z); + i++; + } + bglEnd(); + bglBegin(GL_LINE_LOOP); + i = 0; + while (i < sec->wallnum) + { + v.x = (float)(prsectors[sectnum]->v[i].x - pos.x) / 1; + v.y = (float)(prsectors[sectnum]->v[i].y - pos.y - (sec->ceilingz - sec->floorz)) / (15.66 * 1); + v.z = (float)(prsectors[sectnum]->v[i].z - pos.z) / 1; + //OSD_Printf("Polymer: drawing poly %f, %f, %f\n", v.x, v.y, v.z); + bglVertex3d(v.x, v.y, v.z); + i++; + } + bglEnd(); } -void polymer_drawrooms(void) +void polymer_drawrooms(long daposx, long daposy, long daposz, short daang, long dahoriz, short dacursectnum) { - OSD_Printf("drawrooms\n"); + int i; + OSD_Printf("Polymer: drawing rooms\n"); + polymer_glinit(); - polymer_drawsector(globalcursectnum); + i = 0; + while (i < numsectors) + { + polymer_drawsector(daposx, daposy, daposz, daang, dahoriz, i); + i++; + } } diff --git a/polymer/build/src/polymost.c b/polymer/build/src/polymost.c index cbe4d57fe..2da4a7647 100644 --- a/polymer/build/src/polymost.c +++ b/polymer/build/src/polymost.c @@ -1361,7 +1361,7 @@ void drawpoly (double *dpx, double *dpy, long n, long method) loadtile(globalpicnum); if (!waloff[globalpicnum]) { - if (rendmode != 3) return; + if (rendmode < 3) return; tsizx = tsizy = 1; method = 1; //Hack to update Z-buffer for invalid mirror textures } } @@ -1386,7 +1386,7 @@ void drawpoly (double *dpx, double *dpy, long n, long method) oy = ox2*gstang + oy2*gctang; oz = oz2; - if ((oz < SCISDIST) && (rendmode != 3)) return; //annoying hack to avoid bugs in software rendering + if ((oz < SCISDIST) && (rendmode < 3)) return; //annoying hack to avoid bugs in software rendering r = ghalfx / oz; @@ -1413,7 +1413,7 @@ void drawpoly (double *dpx, double *dpy, long n, long method) n = j; #ifdef USE_OPENGL - if (rendmode == 3) + if (rendmode >= 3) { float hackscx, hackscy; @@ -2288,7 +2288,7 @@ static void polymost_drawalls (long bunch) #ifdef USE_OPENGL if (!nofog) { - if (rendmode == 3) { + if (rendmode >= 3) { float col[4]; col[0] = (float)palookupfog[sec->floorpal].r / 63.f; col[1] = (float)palookupfog[sec->floorpal].g / 63.f; @@ -2470,7 +2470,7 @@ static void polymost_drawalls (long bunch) { //Parallaxing sky... hacked for Ken's mountain texture; paper-sky only :/ #ifdef USE_OPENGL - if (rendmode == 3) + if (rendmode >= 3) { /* if (!nofog) { bglDisable(GL_FOG); @@ -2711,7 +2711,7 @@ static void polymost_drawalls (long bunch) #endif } #ifdef USE_OPENGL - if (rendmode == 3) + if (rendmode >= 3) { skyclamphack = 0; if (!nofog) { @@ -2837,7 +2837,7 @@ static void polymost_drawalls (long bunch) else if ((nextsectnum < 0) || (!(sector[nextsectnum].ceilingstat&1))) { #ifdef USE_OPENGL - if (rendmode == 3) + if (rendmode >= 3) { /* if (!nofog) { bglDisable(GL_FOG); @@ -3077,7 +3077,7 @@ static void polymost_drawalls (long bunch) #endif } #ifdef USE_OPENGL - if (rendmode == 3) + if (rendmode >= 3) { skyclamphack = 0; if (!nofog) { @@ -3381,7 +3381,7 @@ void polymost_drawrooms () frameoffset = frameplace + windowy1*bytesperline + windowx1; #ifdef USE_OPENGL - if (rendmode == 3) + if (rendmode >= 3) { resizeglcheck(); @@ -3594,7 +3594,7 @@ void polymost_drawrooms () bunchlast[closest] = bunchlast[numbunches]; } #ifdef USE_OPENGL - if (rendmode == 3) + if (rendmode >= 3) { bglDepthFunc(GL_LEQUAL); //NEVER,LESS,(,L)EQUAL,GREATER,(NOT,G)EQUAL,ALWAYS @@ -3694,7 +3694,7 @@ if (yp1 < SCISDIST) { t1 = (SCISDIST-oyp0)/(yp1-oyp0); xp1 = (xp1-oxp0)*t1+oxp0; #ifdef USE_OPENGL if (!nofog) { - if (rendmode == 3) { + if (rendmode >= 3) { float col[4]; col[0] = (float)palookupfog[sec->floorpal].r / 63.f; col[1] = (float)palookupfog[sec->floorpal].g / 63.f; @@ -3807,7 +3807,7 @@ void polymost_drawsprite (long snum) if (tspr->cstat&2) { if (!(tspr->cstat&512)) method = 2+4; else method = 3+4; } #ifdef USE_OPENGL - if (!nofog && rendmode == 3) { + if (!nofog && rendmode >= 3) { float col[4]; col[0] = (float)palookupfog[sector[tspr->sectnum].floorpal].r / 63.f; col[1] = (float)palookupfog[sector[tspr->sectnum].floorpal].g / 63.f; @@ -3823,7 +3823,7 @@ if (tspr->cstat&2) { if (!(tspr->cstat&512)) method = 2+4; else method = 3+4; } } } - while (rendmode == 3 && !(spriteext[tspr->owner].flags&SPREXT_NOTMD)) { + while (rendmode >= 3 && !(spriteext[tspr->owner].flags&SPREXT_NOTMD)) { if (usemodels && tile2model[tspr->picnum].modelid >= 0 && tile2model[tspr->picnum].framenum >= 0) { if (mddraw(tspr)) return; break; // else, render as flat sprite @@ -3838,6 +3838,8 @@ if (tspr->cstat&2) { if (!(tspr->cstat&512)) method = 2+4; else method = 3+4; } } break; } + //if ((!(tspr->cstat&2)) && (!gltexmayhavealpha(tspr->picnum,tspr->pal))) + bglDepthMask(0); #endif switch((globalorientation>>4)&3) @@ -4123,7 +4125,7 @@ void polymost_dorotatesprite (long sx, long sy, long z, short a, short picnum, int fovcorrect; #ifdef USE_OPENGL - if (rendmode == 3 && usemodels && hudmem[(dastat&4)>>2][picnum].angadd) + if (rendmode >= 3 && usemodels && hudmem[(dastat&4)>>2][picnum].angadd) { if ((tile2model[picnum].modelid >= 0) && (tile2model[picnum].framenum >= 0)) { @@ -4264,7 +4266,7 @@ void polymost_dorotatesprite (long sx, long sy, long z, short a, short picnum, ogstang = gstang; gstang = 0.0; #ifdef USE_OPENGL - if (rendmode == 3) + if (rendmode >= 3) { bglViewport(0,0,xdim,ydim); glox1 = -1; //Force fullscreen (glox1=-1 forces it to restore) bglMatrixMode(GL_PROJECTION); @@ -4387,7 +4389,7 @@ if (dastat&16) { xoff = 0; yoff = 0; } } #ifdef USE_OPENGL - if (rendmode == 3) { + if (rendmode >= 3) { bglMatrixMode(GL_PROJECTION); bglPopMatrix(); } #endif @@ -4616,7 +4618,7 @@ long polymost_drawtilescreen (long tilex, long tiley, long wallnum, long dimen) long i; pthtyp *pth; - if ((rendmode != 3) || (qsetmode != 200)) return(-1); + if ((rendmode < 3) || (qsetmode != 200)) return(-1); if (!glinfo.texnpot) { i = (1<<(picsiz[wallnum]&15)); if (i < tilesizx[wallnum]) i += i; xdimepad = (float)i; @@ -4702,7 +4704,7 @@ long polymost_printext256(long xpos, long ypos, short col, short backcol, char * b.b = britable[curbrightness][ curpalette[backcol].b ]; } - if ((rendmode != 3) || (qsetmode != 200)) return(-1); + if ((rendmode < 3) || (qsetmode != 200)) return(-1); if (!polymosttext) { // construct a 256x128 8-bit alpha-only texture for the font glyph matrix