diff --git a/polymer/build/include/glbuild.h b/polymer/build/include/glbuild.h index 81bbf1f02..546207c4e 100644 --- a/polymer/build/include/glbuild.h +++ b/polymer/build/include/glbuild.h @@ -117,7 +117,12 @@ extern void (APIENTRY * bglVertexPointer)(GLint size, GLenum type, GLsizei strid extern void (APIENTRY * bglTexCoordPointer)(GLint size, GLenum type, GLsizei stride, const GLvoid *pointer); extern void (APIENTRY * bglDrawArrays)(GLenum mode, GLint first, GLsizei count); extern void (APIENTRY * bglDrawElements)(GLenum mode, GLsizei count, GLenum type, const GLvoid *indices); - + +// Stencil Buffer +extern void (APIENTRY * bglClearStencil)(GLint s); +extern void (APIENTRY * bglStencilOp)(GLenum fail, GLenum zfail, GLenum zpass); +extern void (APIENTRY * bglStencilFunc)(GLenum func, GLint ref, GLuint mask); + #ifdef RENDERTYPEWIN // Windows extern HGLRC (WINAPI * bwglCreateContext)(HDC); diff --git a/polymer/build/include/polymer.h b/polymer/build/include/polymer.h index d21723430..152545d1f 100644 --- a/polymer/build/include/polymer.h +++ b/polymer/build/include/polymer.h @@ -30,7 +30,8 @@ typedef struct s_prsector { GLfloat floorcolor[4], ceilcolor[4]; GLuint floorglpic, ceilglpic; // elements - GLushort* indices; + GLushort* floorindices; + GLushort* ceilindices; short curindice; int indicescount; @@ -57,7 +58,7 @@ extern _prwall* prwalls[MAXWALLS]; int polymer_init(void); void polymer_glinit(void); void polymer_loadboard(void); -void polymer_drawrooms(long daposx, long daposy, long daposz, short daang, long dahoriz, short dacursectnum); +void polymer_drawrooms(long daposx, long daposy, long daposz, short daang, long dahoriz, short dacursectnum, int root); // SECTOR MANAGEMENT int polymer_initsector(short sectnum); int polymer_updatesector(short sectnum); @@ -66,7 +67,7 @@ void PR_CALLBACK polymer_tesserror(GLenum error); void PR_CALLBACK polymer_tessedgeflag(GLenum error); void PR_CALLBACK polymer_tessvertex(void* vertex, void* sector); int polymer_buildfloor(short sectnum); -void polymer_drawsector(long daposx, long daposy, long daposz, short daang, long dahoriz, short sectnum); +void polymer_drawsector(long daposx, long daposy, long daposz, short daang, long dahoriz, short sectnum, int root); // WALL MANAGEMENT int polymer_initwall(short wallnum); void polymer_updatewall(short wallnum); diff --git a/polymer/build/include/polymost.h b/polymer/build/include/polymost.h index dab711dd8..62aa0374c 100644 --- a/polymer/build/include/polymost.h +++ b/polymer/build/include/polymost.h @@ -36,5 +36,6 @@ typedef struct pthtyp_t pthtyp * gltexcache (long dapicnum, long dapalnum, long dameth); extern palette_t hictinting[MAXPALOOKUPS]; +extern float gtang; #endif // !_polymost_h_ diff --git a/polymer/build/src/baselayer.c b/polymer/build/src/baselayer.c index 65bdddd7b..a5309675f 100644 --- a/polymer/build/src/baselayer.c +++ b/polymer/build/src/baselayer.c @@ -34,7 +34,7 @@ static int osdfunc_setrendermode(const osdfuncparm_t *parm) char *modestrs[] = { "classic software", "polygonal flat-shaded software", - "polygonal textured software", "polygonal OpenGL", "blah" + "polygonal textured software", "polygonal OpenGL", "great justice" }; if (parm->numparms != 1) return OSDCMD_SHOWHELP; diff --git a/polymer/build/src/engine.c b/polymer/build/src/engine.c index 5597346ac..decc9e428 100644 --- a/polymer/build/src/engine.c +++ b/polymer/build/src/engine.c @@ -5683,7 +5683,9 @@ void drawrooms(long daposx, long daposy, long daposz, if (rendmode == 4) { - polymer_drawrooms(daposx, daposy, daposz, daang, dahoriz, dacursectnum); + polymer_glinit(); + polymer_drawrooms(daposx, daposy, daposz, daang, dahoriz, dacursectnum, 1); + bglDisable(GL_CULL_FACE); return; } diff --git a/polymer/build/src/glbuild.c b/polymer/build/src/glbuild.c index 4005897c0..c4fd23677 100644 --- a/polymer/build/src/glbuild.c +++ b/polymer/build/src/glbuild.c @@ -102,6 +102,11 @@ void (APIENTRY * bglTexCoordPointer)(GLint size, GLenum type, GLsizei stride, co void (APIENTRY * bglDrawArrays)(GLenum mode, GLint first, GLsizei count); void (APIENTRY * bglDrawElements)(GLenum mode, GLsizei count, GLenum type, const GLvoid *indices); +// Stencil Buffer +void (APIENTRY * bglClearStencil)(GLint s); +void (APIENTRY * bglStencilOp)(GLenum fail, GLenum zfail, GLenum zpass); +void (APIENTRY * bglStencilFunc)(GLenum func, GLint ref, GLuint mask); + #ifdef RENDERTYPEWIN // Windows HGLRC (WINAPI * bwglCreateContext)(HDC); @@ -271,6 +276,11 @@ int loadgldriver(const char *driver) bglDrawArrays = GETPROC("glDrawArrays"); bglDrawElements = GETPROC("glDrawElements"); + // Stencil Buffer + bglClearStencil = GETPROC("glClearStencil"); + bglStencilOp = GETPROC("glStencilOp"); + bglStencilFunc = GETPROC("glStencilFunc"); + loadglextensions(); if (err) unloadgldriver(); @@ -386,6 +396,11 @@ int unloadgldriver(void) bglTexCoordPointer = NULL; bglDrawElements = NULL; + // Stencil Buffer + bglClearStencil = NULL; + bglStencilOp = NULL; + bglStencilFunc = NULL; + #ifdef RENDERTYPEWIN bwglCreateContext = NULL; bwglDeleteContext = NULL; diff --git a/polymer/build/src/polymer.c b/polymer/build/src/polymer.c index 85ecfc26d..4fa2e4470 100644 --- a/polymer/build/src/polymer.c +++ b/polymer/build/src/polymer.c @@ -58,7 +58,8 @@ void polymer_glinit(void) bglGetFloatv(GL_PROJECTION_MATRIX, polymostprojmatrix); bglGetFloatv(GL_MODELVIEW_MATRIX, polymostmodelmatrix); bglClearColor(0.0f, 0.0f, 0.0f, 1.0f); - bglClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); + bglClearStencil(0); + bglClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT); bglViewport(0, 0, 1024, 768); // texturing @@ -93,6 +94,8 @@ void polymer_glinit(void) bglEnableClientState(GL_VERTEX_ARRAY); bglEnableClientState(GL_TEXTURE_COORD_ARRAY); + bglEnable(GL_CULL_FACE); + bglCullFace(GL_BACK); } void polymer_loadboard(void) @@ -118,18 +121,16 @@ void polymer_loadboard(void) if (pr_verbosity >= 1) OSD_Printf("PR : Board loaded.\n"); } -void polymer_drawrooms(long daposx, long daposy, long daposz, short daang, long dahoriz, short dacursectnum) +void polymer_drawrooms(long daposx, long daposy, long daposz, short daang, long dahoriz, short dacursectnum, int root) { int i; if (pr_verbosity >= 3) OSD_Printf("PR : Drawing rooms...\n"); - polymer_glinit(); - i = 0; while (i < numsectors) { - polymer_drawsector(daposx, daposy, daposz, daang, dahoriz, i); + polymer_drawsector(daposx, daposy, daposz, daang, dahoriz, i, 0); i++; } @@ -169,7 +170,7 @@ int polymer_initsector(short sectnum) return (0); } - s->indices = NULL; + s->floorindices = s->ceilindices = NULL; prsectors[sectnum] = s; @@ -347,9 +348,10 @@ void PR_CALLBACK polymer_tessvertex(void* vertex, void* sector) { if (pr_verbosity >= 2) OSD_Printf("PR : Indice overflow, extending the indices list... !\n"); s->indicescount++; - s->indices = realloc(s->indices, s->indicescount * sizeof(GLushort)); + s->floorindices = realloc(s->floorindices, s->indicescount * sizeof(GLushort)); + s->ceilindices = realloc(s->ceilindices, s->indicescount * sizeof(GLushort)); } - s->indices[s->curindice] = (int)vertex; + s->ceilindices[s->curindice] = (int)vertex; s->curindice++; } int polymer_buildfloor(short sectnum) @@ -366,10 +368,11 @@ int polymer_buildfloor(short sectnum) if (s == NULL) return (-1); - if (s->indices == NULL) + if (s->floorindices == NULL) { s->indicescount = (sec->wallnum - 2) * 3; - s->indices = calloc(s->indicescount, sizeof(GLushort)); + s->floorindices = calloc(s->indicescount, sizeof(GLushort)); + s->ceilindices = calloc(s->indicescount, sizeof(GLushort)); } s->curindice = 0; @@ -398,17 +401,25 @@ int polymer_buildfloor(short sectnum) gluTessEndContour(prtess); gluTessEndPolygon(prtess); + i = 0; + while (i < s->indicescount) + { + s->floorindices[s->indicescount - i - 1] = s->ceilindices[i]; + + i++; + } + if (pr_verbosity >= 2) OSD_Printf("PR : Tesselated floor of sector %i.\n", sectnum); return (1); } -void polymer_drawsector(long daposx, long daposy, long daposz, short daang, long dahoriz, short sectnum) +void polymer_drawsector(long daposx, long daposy, long daposz, short daang, long dahoriz, short sectnum, int root) { sectortype *sec, *nextsec; walltype *wal; _prsector* s; - float ang, horizang; + float ang, horizang, tiltang; double pos[3]; int i; long zdiff; @@ -425,7 +436,7 @@ void polymer_drawsector(long daposx, long daposy, long daposz, sh polymer_updatesector(sectnum); polymer_buildfloor(sectnum); } - else if (prsectors[sectnum]->invalidate) + else if (prsectors[sectnum]->invalidate || 0) { if (pr_verbosity >= 2) OSD_Printf("PR : Sector %i invalidated. Tesselating...\n", sectnum); polymer_updatesector(sectnum); @@ -442,6 +453,7 @@ void polymer_drawsector(long daposx, long daposy, long daposz, sh ang = (float)(daang) / (2048.0f / 360.0f); horizang = (float)(100 - dahoriz) / (256.0f / 90.0f); + tiltang = (gtang * 90.0f); pos[0] = -daposy; pos[1] = daposz; @@ -452,26 +464,69 @@ void polymer_drawsector(long daposx, long daposy, long daposz, sh bglRotatef(horizang, 1.0f, 0.0f, 0.0f); bglRotatef(ang, 0.0f, 1.0f, 0.0f); + bglRotatef(tiltang, 0.0f, 0.0f, -1.0f); bglScalef(1.0f, 1.0f / 16.0f, 1.0f); bglTranslatef(pos[0], pos[1], pos[2]); - bglEnable(GL_TEXTURE_2D); // floor - bglBindTexture(GL_TEXTURE_2D, s->floorglpic); - bglColor4f(s->floorcolor[0], s->floorcolor[1], s->floorcolor[2], s->floorcolor[3]); - bglVertexPointer(3, GL_FLOAT, 5 * sizeof(GLfloat), s->floorbuffer); - bglTexCoordPointer(2, GL_FLOAT, 5 * sizeof(GLfloat), &s->floorbuffer[3]); - bglDrawElements(GL_TRIANGLES, s->indicescount, GL_UNSIGNED_SHORT, s->indices); + if (!(sec->floorstat & 1)) + { + if (root) + { + bglDisable(GL_TEXTURE_2D); + bglColorMask(0, 0, 0, 0); + bglEnable(GL_STENCIL_TEST); + + bglStencilOp(GL_KEEP, GL_KEEP, GL_REPLACE); + bglStencilFunc(GL_ALWAYS, 1, 1); + + bglVertexPointer(3, GL_FLOAT, 5 * sizeof(GLfloat), s->floorbuffer); + bglTexCoordPointer(2, GL_FLOAT, 5 * sizeof(GLfloat), &s->floorbuffer[3]); + bglDrawElements(GL_TRIANGLES, s->indicescount, GL_UNSIGNED_SHORT, s->floorindices); + + bglStencilOp(GL_KEEP, GL_KEEP, GL_KEEP); + bglStencilFunc(GL_EQUAL, 1, 1); + bglColorMask(1, 1, 1, 1); + bglEnable(GL_TEXTURE_2D); + + //bglDepthMask(0); + polymer_drawrooms(daposx, daposy, daposz - ((daposz - sec->floorz) * 2), daang, dahoriz, sectnum, 0); + //bglDepthMask(1); + + bglDisable(GL_STENCIL_TEST); + bglEnable(GL_BLEND); + bglBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA); + + bglBindTexture(GL_TEXTURE_2D, s->floorglpic); + bglColor4f(s->floorcolor[0], s->floorcolor[1], s->floorcolor[2], 0.5f); + bglVertexPointer(3, GL_FLOAT, 5 * sizeof(GLfloat), s->floorbuffer); + bglTexCoordPointer(2, GL_FLOAT, 5 * sizeof(GLfloat), &s->floorbuffer[3]); + bglDrawElements(GL_TRIANGLES, s->indicescount, GL_UNSIGNED_SHORT, s->floorindices); + + bglDisable(GL_BLEND); + } + else + { + bglBindTexture(GL_TEXTURE_2D, s->floorglpic); + bglColor4f(s->floorcolor[0], s->floorcolor[1], s->floorcolor[2], s->floorcolor[3]); + bglVertexPointer(3, GL_FLOAT, 5 * sizeof(GLfloat), s->floorbuffer); + bglTexCoordPointer(2, GL_FLOAT, 5 * sizeof(GLfloat), &s->floorbuffer[3]); + bglDrawElements(GL_TRIANGLES, s->indicescount, GL_UNSIGNED_SHORT, s->floorindices); + } + } // ceiling - bglBindTexture(GL_TEXTURE_2D, s->ceilglpic); - bglColor4f(s->ceilcolor[0], s->ceilcolor[1], s->ceilcolor[2], s->ceilcolor[3]); - bglVertexPointer(3, GL_FLOAT, 5 * sizeof(GLfloat), s->ceilbuffer); - bglTexCoordPointer(2, GL_FLOAT, 5 * sizeof(GLfloat), &s->ceilbuffer[3]); - bglDrawElements(GL_TRIANGLES, s->indicescount, GL_UNSIGNED_SHORT, s->indices); + if (!(sec->ceilingstat & 1)) + { + bglBindTexture(GL_TEXTURE_2D, s->ceilglpic); + bglColor4f(s->ceilcolor[0], s->ceilcolor[1], s->ceilcolor[2], s->ceilcolor[3]); + bglVertexPointer(3, GL_FLOAT, 5 * sizeof(GLfloat), s->ceilbuffer); + bglTexCoordPointer(2, GL_FLOAT, 5 * sizeof(GLfloat), &s->ceilbuffer[3]); + bglDrawElements(GL_TRIANGLES, s->indicescount, GL_UNSIGNED_SHORT, s->ceilindices); + } // walls i = 0; @@ -632,7 +687,8 @@ void polymer_updatewall(short wallnum) i++; } - w->underover |= 1; + if (!((sec->floorstat & 1) && (nsec->floorstat & 1))) + w->underover |= 1; } if (((s->ceilbuffer[((wallnum - sec->wallptr) * 5) + 1] != ns->ceilbuffer[((nnwallnum - nsec->wallptr) * 5) + 1]) || @@ -680,7 +736,8 @@ void polymer_updatewall(short wallnum) i++; } - w->underover |= 2; + if (!((sec->ceilingstat & 1) && (nsec->ceilingstat & 1))) + w->underover |= 2; } } diff --git a/polymer/build/src/polymost.c b/polymer/build/src/polymost.c index a0cbefbfd..01a142004 100644 --- a/polymer/build/src/polymost.c +++ b/polymer/build/src/polymost.c @@ -101,7 +101,7 @@ static double dxb1[MAXWALLSB], dxb2[MAXWALLSB]; static double gyxscale, gxyaspect, gviewxrange, ghalfx, grhalfxdown10, grhalfxdown10x, ghoriz; static double gcosang, gsinang, gcosang2, gsinang2; static double gchang, gshang, gctang, gstang, gvisibility; -static float gtang = 0.0; +float gtang = 0.0; double guo, gux, guy; //Screen-based texture mapping parameters double gvo, gvx, gvy; double gdo, gdx, gdy; diff --git a/polymer/build/src/winlayer.c b/polymer/build/src/winlayer.c index 455ed703d..b2a5bd2c0 100644 --- a/polymer/build/src/winlayer.c +++ b/polymer/build/src/winlayer.c @@ -2733,7 +2733,7 @@ static int SetupOpenGL(int width, int height, int bitspp) 0, //No Accumulation Buffer 0,0,0,0, //Accumulation Bits Ignored 32, //16/24/32 Z-Buffer depth - 0, //No Stencil Buffer + 1, //No Stencil Buffer 0, //No Auxiliary Buffer PFD_MAIN_PLANE, //Main Drawing Layer 0, //Reserved diff --git a/polymer/polymer/polymer.sln b/polymer/polymer/polymer.sln new file mode 100644 index 000000000..861a726e9 --- /dev/null +++ b/polymer/polymer/polymer.sln @@ -0,0 +1,20 @@ + +Microsoft Visual Studio Solution File, Format Version 9.00 +# Visual Studio 2005 +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "polymer", "polymer.vcproj", "{6D68F889-28E5-49C1-A23B-448285B092A5}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Win32 = Debug|Win32 + Release|Win32 = Release|Win32 + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {6D68F889-28E5-49C1-A23B-448285B092A5}.Debug|Win32.ActiveCfg = Debug|Win32 + {6D68F889-28E5-49C1-A23B-448285B092A5}.Debug|Win32.Build.0 = Debug|Win32 + {6D68F889-28E5-49C1-A23B-448285B092A5}.Release|Win32.ActiveCfg = Release|Win32 + {6D68F889-28E5-49C1-A23B-448285B092A5}.Release|Win32.Build.0 = Release|Win32 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection +EndGlobal diff --git a/polymer/polymer/polymer.suo b/polymer/polymer/polymer.suo new file mode 100644 index 000000000..e1e9d0f27 Binary files /dev/null and b/polymer/polymer/polymer.suo differ diff --git a/polymer/polymer/polymer.vcproj b/polymer/polymer/polymer.vcproj new file mode 100644 index 000000000..f0316893f --- /dev/null +++ b/polymer/polymer/polymer.vcproj @@ -0,0 +1,885 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +