From 0a0f399ba04eb2f329ea7f8c5be45005f1faf402 Mon Sep 17 00:00:00 2001 From: Plagman Date: Wed, 30 Aug 2006 23:32:39 +0000 Subject: [PATCH] More Polymer (for win32 platform, still test code), added polymost.h for external access to some structs and funcs. git-svn-id: https://svn.eduke32.com/eduke32@283 1a8010ca-5511-0410-912e-c29ae57300e0 --- polymer/build/Makefile.deps | 4 +- polymer/build/Makefile.shared | 5 +- polymer/build/include/glbuild.h | 11 + polymer/build/include/polymer.h | 33 ++- polymer/build/include/polymost.h | 38 ++++ polymer/build/src/engine.c | 11 + polymer/build/src/glbuild.c | 18 ++ polymer/build/src/hightile.c | 6 +- polymer/build/src/mdsprite.c | 273 ++++++++++++++++++++++- polymer/build/src/polymer.c | 368 +++++++++++++++++++++++++------ polymer/build/src/polymost.c | 9 +- polymer/eduke32/source/osdcmds.c | 7 +- 12 files changed, 681 insertions(+), 102 deletions(-) create mode 100644 polymer/build/include/polymost.h diff --git a/polymer/build/Makefile.deps b/polymer/build/Makefile.deps index b965ab1bb..129d95505 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 $(INC)polymer.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 $(INC)polymost.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,7 +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 +$(OBJ)polymer.$o: $(SRC)polymer.c $(INC)polymer.h $(INC)compat.h $(INC)build.h $(INC)glbuild.h $(INC)osd.h $(INC)polymost.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/Makefile.shared b/polymer/build/Makefile.shared index 21391db12..37c71c371 100644 --- a/polymer/build/Makefile.shared +++ b/polymer/build/Makefile.shared @@ -125,7 +125,10 @@ ifeq ($(RENDERTYPE),SDL) endif else ifeq ($(RENDERTYPE),WIN) - LIBS+= -mwindows -ldxguid + LIBS+= -mwindows -ldxguid + ifneq (0,$(USE_OPENGL)) + LIBS+= -lglu32 + endif endif endif diff --git a/polymer/build/include/glbuild.h b/polymer/build/include/glbuild.h index ed642c48b..3da85a44b 100644 --- a/polymer/build/include/glbuild.h +++ b/polymer/build/include/glbuild.h @@ -7,8 +7,10 @@ #if defined(__APPLE__) # include +# include #else # include +# include #endif // get this header from http://oss.sgi.com/projects/ogl-sample/registry/ @@ -62,6 +64,8 @@ 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); +extern void (APIENTRY * bglScalef)(GLfloat x, GLfloat y, GLfloat z); +extern void (APIENTRY * bglTranslatef)(GLfloat x, GLfloat y, GLfloat z); // Drawing extern void (APIENTRY * bglBegin)( GLenum mode ); @@ -70,6 +74,7 @@ extern void (APIENTRY * bglVertex2f)( GLfloat x, GLfloat y ); extern void (APIENTRY * bglVertex2i)( GLint x, GLint y ); extern void (APIENTRY * bglVertex3d)( GLdouble x, GLdouble y, GLdouble z ); extern void (APIENTRY * bglVertex3fv)( const GLfloat *v ); +extern void (APIENTRY * bglVertex3dv)( const GLdouble *v ); extern void (APIENTRY * bglColor4f)( GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha ); extern void (APIENTRY * bglColor4ub)( GLubyte red, GLubyte green, GLubyte blue, GLubyte alpha ); extern void (APIENTRY * bglTexCoord2d)( GLdouble s, GLdouble t ); @@ -93,11 +98,17 @@ extern void (APIENTRY * bglTexParameteri)( GLenum target, GLenum pname, GLint pa extern void (APIENTRY * bglGetTexLevelParameteriv)( GLenum target, GLint level, GLenum pname, GLint *params ); extern void (APIENTRY * bglCompressedTexImage2DARB)(GLenum, GLint, GLenum, GLsizei, GLsizei, GLint, GLsizei, const GLvoid *); extern void (APIENTRY * bglGetCompressedTexImageARB)(GLenum, GLint, GLvoid *); +extern void (APIENTRY * bglTexGenfv)(GLenum coord, GLenum pname, const GLfloat *params); // Fog extern void (APIENTRY * bglFogf)( GLenum pname, GLfloat param ); extern void (APIENTRY * bglFogi)( GLenum pname, GLint param ); extern void (APIENTRY * bglFogfv)( GLenum pname, const GLfloat *params ); + +// Display Lists +extern void (APIENTRY * bglNewList)(GLuint list, GLenum mode); +extern void (APIENTRY * bglEndList)(void); +extern void (APIENTRY * bglCallList)(GLuint list); #ifdef RENDERTYPEWIN // Windows diff --git a/polymer/build/include/polymer.h b/polymer/build/include/polymer.h index 8011636df..68c32a214 100644 --- a/polymer/build/include/polymer.h +++ b/polymer/build/include/polymer.h @@ -1,18 +1,33 @@ // blah #ifndef _polymer_h_ -#define _polymer_h_ +# define _polymer_h_ -// geometry container -typedef struct DNF -{ - double v1[3], v2[3], v3[3]; - double u1[2], u2[2], u3[2]; - short picnum; -} _poly; +# include "compat.h" +# include "build.h" +# include "glbuild.h" +# include "osd.h" +# include "polymost.h" void polymer_glinit(void); -void polymer_init(void); +int polymer_init(void); void polymer_drawrooms(long daposx, long daposy, long daposz, short daang, long dahoriz, short dacursectnum); +typedef struct s_prvertex { + double v[3]; + short wallnum; +} _prvertex; + +typedef struct s_prsector { + _prvertex* verts; + short wallcount; + char invalidate; +} _prsector; + +extern _prsector* prsectors[MAXSECTORS]; + +// Polymer cvars +extern char pr_verbosity; +extern char pr_wireframe; + #endif // !_polymer_h_ diff --git a/polymer/build/include/polymost.h b/polymer/build/include/polymost.h new file mode 100644 index 000000000..455ef30ee --- /dev/null +++ b/polymer/build/include/polymost.h @@ -0,0 +1,38 @@ +#ifndef _polymost_h_ +# define _polymost_h_ + +# include "glbuild.h" + +struct hicskybox_t { + long ignore; + char *face[6]; +}; + +typedef struct hicreplc_t { + struct hicreplc_t *next; + char palnum, ignore, flags, filler; + char *filename; + float alphacut; + struct hicskybox_t *skybox; +} hicreplctyp; + +typedef struct pthtyp_t +{ + struct pthtyp_t *next; + GLuint glpic; + short picnum; + char palnum; + char effects; + char flags; // 1 = clamped (dameth&4), 2 = hightile, 4 = skybox face, 8 = hasalpha, 16 = hasfullbright, 128 = invalidated + char skyface; + hicreplctyp *hicr; + + unsigned short sizx, sizy; + float scalex, scaley; + struct pthtyp_t *wofb; // without fullbright + struct pthtyp_t *ofb; // only fullbright +} pthtyp; + +pthtyp * gltexcache (long dapicnum, long dapalnum, long dameth); + +#endif // !_polymost_h_ diff --git a/polymer/build/src/engine.c b/polymer/build/src/engine.c index 44316ca33..c2513f213 100644 --- a/polymer/build/src/engine.c +++ b/polymer/build/src/engine.c @@ -685,6 +685,7 @@ char palfadedelta = 0; //============================================================================= //POLYMOST BEGINS #ifdef POLYMOST static void scansector(short sectnum); +#include "polymost.h" #include "hightile.c" #include "polymost.c" #else @@ -8458,6 +8459,16 @@ void dragpoint(short pointhighlight, long dax, long day) wall[pointhighlight].x = dax; wall[pointhighlight].y = day; + if (rendmode == 4) + { + tempshort = wall[pointhighlight].nextwall; + if (tempshort >= 0) + { + prsectors[wall[pointhighlight].nextsector]->invalidate = 1; + prsectors[wall[tempshort].nextsector]->invalidate = 1; + } + } + cnt = MAXWALLS; tempshort = pointhighlight; //search points CCW do diff --git a/polymer/build/src/glbuild.c b/polymer/build/src/glbuild.c index 9a5950aae..ba9dd66e4 100644 --- a/polymer/build/src/glbuild.c +++ b/polymer/build/src/glbuild.c @@ -48,6 +48,8 @@ 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); +void (APIENTRY * bglScalef)(GLfloat x, GLfloat y, GLfloat z); +void (APIENTRY * bglTranslatef)(GLfloat x, GLfloat y, GLfloat z); // Drawing void (APIENTRY * bglBegin)( GLenum mode ); @@ -56,6 +58,7 @@ void (APIENTRY * bglVertex2f)( GLfloat x, GLfloat y ); void (APIENTRY * bglVertex2i)( GLint x, GLint y ); void (APIENTRY * bglVertex3d)( GLdouble x, GLdouble y, GLdouble z ); void (APIENTRY * bglVertex3fv)( const GLfloat *v ); +void (APIENTRY * bglVertex3dv)( const GLdouble *v ); void (APIENTRY * bglColor4f)( GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha ); void (APIENTRY * bglColor4ub)( GLubyte red, GLubyte green, GLubyte blue, GLubyte alpha ); void (APIENTRY * bglTexCoord2d)( GLdouble s, GLdouble t ); @@ -79,12 +82,18 @@ void (APIENTRY * bglTexParameteri)( GLenum target, GLenum pname, GLint param ); void (APIENTRY * bglGetTexLevelParameteriv)( GLenum target, GLint level, GLenum pname, GLint *params ); void (APIENTRY * bglCompressedTexImage2DARB)(GLenum, GLint, GLenum, GLsizei, GLsizei, GLint, GLsizei, const GLvoid *); void (APIENTRY * bglGetCompressedTexImageARB)(GLenum, GLint, GLvoid *); +void (APIENTRY * bglTexGenfv)(GLenum coord, GLenum pname, const GLfloat *params); // Fog void (APIENTRY * bglFogf)( GLenum pname, GLfloat param ); void (APIENTRY * bglFogi)( GLenum pname, GLint param ); void (APIENTRY * bglFogfv)( GLenum pname, const GLfloat *params ); +// Display Lists +void (APIENTRY * bglNewList)(GLuint list, GLenum mode); +void (APIENTRY * bglEndList)(void); +void (APIENTRY * bglCallList)(GLuint list); + #ifdef RENDERTYPEWIN // Windows HGLRC (WINAPI * bwglCreateContext)(HDC); @@ -202,6 +211,8 @@ int loadgldriver(const char *driver) bglLoadIdentity = GETPROC("glLoadIdentity"); bglLoadMatrixf = GETPROC("glLoadMatrixf"); bglRotatef = GETPROC("glRotatef"); + bglScalef = GETPROC("glScalef"); + bglTranslatef = GETPROC("glTranslatef"); // Drawing bglBegin = GETPROC("glBegin"); @@ -210,6 +221,7 @@ int loadgldriver(const char *driver) bglVertex2i = GETPROC("glVertex2i"); bglVertex3d = GETPROC("glVertex3d"); bglVertex3fv = GETPROC("glVertex3fv"); + bglVertex3dv = GETPROC("glVertex3dv"); bglColor4f = GETPROC("glColor4f"); bglColor4ub = GETPROC("glColor4ub"); bglTexCoord2d = GETPROC("glTexCoord2d"); @@ -231,12 +243,18 @@ int loadgldriver(const char *driver) bglTexParameterf = GETPROC("glTexParameterf"); bglTexParameteri = GETPROC("glTexParameteri"); bglGetTexLevelParameteriv = GETPROC("glGetTexLevelParameteriv"); + bglTexGenfv = GETPROC("glTexGenfv"); // Fog bglFogf = GETPROC("glFogf"); bglFogi = GETPROC("glFogi"); bglFogfv = GETPROC("glFogfv"); + // Display Lists + bglNewList = GETPROC("glNewList"); + bglEndList = GETPROC("glEndList"); + bglCallList = GETPROC("glCallList"); + loadglextensions(); if (err) unloadgldriver(); diff --git a/polymer/build/src/hightile.c b/polymer/build/src/hightile.c index b16287d9d..2ed69477a 100644 --- a/polymer/build/src/hightile.c +++ b/polymer/build/src/hightile.c @@ -9,17 +9,19 @@ #define HICEFFECTMASK (1|2) static palette_t hictinting[MAXPALOOKUPS]; -struct hicskybox_t { +//moved into polymost.h +/*struct hicskybox_t { long ignore; char *face[6]; }; + typedef struct hicreplc_t { struct hicreplc_t *next; char palnum, ignore, flags, filler; char *filename; float alphacut; struct hicskybox_t *skybox; -} hicreplctyp; +} hicreplctyp;*/ static hicreplctyp *hicreplc[MAXTILES]; static char hicfirstinit = 0; diff --git a/polymer/build/src/mdsprite.c b/polymer/build/src/mdsprite.c index 7369a5331..1f59a3def 100644 --- a/polymer/build/src/mdsprite.c +++ b/polymer/build/src/mdsprite.c @@ -857,6 +857,34 @@ else { if (i >= j) { i -= j; if (i >= j) i %= j; } } } //--------------------------------------- MD2 LIBRARY BEGINS --------------------------------------- +static void md2free (md2model *m) +{ + mdanim_t *anim, *nanim = NULL; + mdskinmap_t *sk, *nsk = NULL; + + if (!m) return; + + for(anim=m->animations; anim; anim=nanim) + { + nanim = anim->next; + free(anim); + } + for(sk=m->skinmap; sk; sk=nsk) + { + nsk = sk->next; + free(sk->fn); + free(sk); + } + + if (m->frames) free(m->frames); + if (m->glcmds) free(m->glcmds); + if (m->basepath) free(m->basepath); + if (m->skinfn) free(m->skinfn); + + if (m->texid) free(m->texid); +} +static long long memoryusage = 0; + static md2model *md2load (int fil, const char *filnam) { md2model *m; @@ -945,12 +973,16 @@ m->basepath = (char *)malloc(i+1); if (!m->basepath) { free(m->uv); free(m->tris m->texid = (GLuint *)calloc(m->numskins, sizeof(GLuint) * (HICEFFECTMASK+1)); if (!m->texid) { free(m->skinfn); free(m->basepath); free(m->uv); free(m->tris); free(m->glcmds); free(m->frames); free(m); return(0); } + maxmodelverts = max(maxmodelverts, m->numverts); + + //return(m); + // the MD2 is now loaded internally - let's begin the MD3 conversion process //OSD_Printf("Beginning md3 conversion.\n"); m3 = (md3model *)calloc(1, sizeof(md3model)); if (!m3) { free(m->skinfn); free(m->basepath); free(m->uv); free(m->tris); free(m->glcmds); free(m->frames); free(m); return(0); } m3->mdnum = 3; m3->texid = 0; m3->scale = m->scale; m3->head.id = 0x33504449; m3->head.vers = 15; - m3->head.flags = 0; m3->head.numframes = m->numframes; + m3->head.flags = 1337; m3->head.numframes = m->numframes; m3->head.numtags = 0; m3->head.numsurfs = 1; m3->head.numskins = 0; @@ -993,6 +1025,8 @@ m->basepath = (char *)malloc(i+1); if (!m->basepath) { free(m->uv); free(m->tris s->tris = (md3tri_t *)calloc(head.numtris, sizeof(md3tri_t)); if (!s->tris) { free(s); free(m3->head.frames); free(m3); free(m->skinfn); free(m->basepath); free(m->uv); free(m->tris); free(m->glcmds); free(m->frames); free(m); return(0); } s->uv = (md3uv_t *)calloc(s->numverts, sizeof(md3uv_t)); if (!s->uv) { free(s->tris); free(s); free(m3->head.frames); free(m3); free(m->skinfn); free(m->basepath); free(m->uv); free(m->tris); free(m->glcmds); free(m->frames); free(m); return(0); } s->xyzn = (md3xyzn_t *)calloc(s->numverts * m->numframes, sizeof(md3xyzn_t)); if (!s->xyzn) { free(s->uv); free(s->tris); free(s); free(m3->head.frames); free(m3); free(m->skinfn); free(m->basepath); free(m->uv); free(m->tris); free(m->glcmds); free(m->frames); free(m); return(0); } + //memoryusage += (s->numverts * m->numframes * sizeof(md3xyzn_t)); + //OSD_Printf("Current model geometry memory usage : %i.\n", memoryusage); //OSD_Printf("Number of frames : %i\n", m->numframes); //OSD_Printf("Number of triangles : %i\n", head.numtris); @@ -1018,9 +1052,9 @@ m->basepath = (char *)malloc(i+1); if (!m->basepath) { free(m->uv); free(m->tris while (k < m->numframes) { f = (md2frame_t *)&m->frames[k*m->framebytes]; - s->xyzn[(k*s->numverts) + (i*3) + j].x = ((f->verts[m->tris[i].v[j]].v[0] * f->mul.x) + f->add.x) * 64; - s->xyzn[(k*s->numverts) + (i*3) + j].y = ((f->verts[m->tris[i].v[j]].v[1] * f->mul.y) + f->add.y) * 64; - s->xyzn[(k*s->numverts) + (i*3) + j].z = ((f->verts[m->tris[i].v[j]].v[2] * f->mul.z) + f->add.z) * 64; + s->xyzn[(k*s->numverts) + (i*3) + j].x = ((f->verts[m->tris[i].v[j]].v[0] * f->mul.x) + f->add.x); + s->xyzn[(k*s->numverts) + (i*3) + j].y = ((f->verts[m->tris[i].v[j]].v[1] * f->mul.y) + f->add.y); + s->xyzn[(k*s->numverts) + (i*3) + j].z = ((f->verts[m->tris[i].v[j]].v[2] * f->mul.z) + f->add.z); k++; } j++; @@ -1050,6 +1084,216 @@ m->basepath = (char *)malloc(i+1); if (!m->basepath) { free(m->uv); free(m->tris return((md2model *)m3); } + +static int md2draw (md2model *m, spritetype *tspr) +{ + point3d fp, fp1, fp2, m0, m1, a0, a1; + md2frame_t *f0, *f1; + unsigned char *c0, *c1; + long i, *lptr; + float f, g, k0, k1, k2, k3, k4, k5, k6, k7, mat[16], pc[4]; + + // if ((tspr->cstat&48) == 32) return 0; + + updateanimation(m,tspr); + + // -------- Unnecessarily clean (lol) code to generate translation/rotation matrix for MD2 --------- + + //create current&next frame's vertex list from whole list + f0 = (md2frame_t *)&m->frames[m->cframe*m->framebytes]; + f1 = (md2frame_t *)&m->frames[m->nframe*m->framebytes]; + f = m->interpol; g = 1-f; + m0.x = f0->mul.x*m->scale*g; m1.x = f1->mul.x*m->scale*f; + m0.y = f0->mul.y*m->scale*g; m1.y = f1->mul.y*m->scale*f; + m0.z = f0->mul.z*m->scale*g; m1.z = f1->mul.z*m->scale*f; + a0.x = f0->add.x*m->scale; a0.x = (f1->add.x*m->scale-a0.x)*f+a0.x; + a0.y = f0->add.y*m->scale; a0.y = (f1->add.y*m->scale-a0.y)*f+a0.y; + a0.z = f0->add.z*m->scale; a0.z = (f1->add.z*m->scale-a0.z)*f+a0.z + m->zadd*m->scale; + c0 = &f0->verts[0].v[0]; c1 = &f1->verts[0].v[0]; + + // Parkar: Moved up to be able to use k0 for the y-flipping code + k0 = tspr->z; + if ((globalorientation&128) && !((globalorientation&48)==32)) k0 += (float)((tilesizy[tspr->picnum]*tspr->yrepeat)<<1); + + // Parkar: Changed to use the same method as centeroriented sprites + if (globalorientation&8) //y-flipping + { + m0.z = -m0.z; m1.z = -m1.z; a0.z = -a0.z; + k0 -= (float)((tilesizy[tspr->picnum]*tspr->yrepeat)<<2); + } + if (globalorientation&4) { m0.y = -m0.y; m1.y = -m1.y; a0.y = -a0.y; } //x-flipping + + f = ((float)tspr->xrepeat)/64*m->bscale; + m0.x *= f; m1.x *= f; a0.x *= f; f = -f; // 20040610: backwards models aren't cool + m0.y *= f; m1.y *= f; a0.y *= f; + f = ((float)tspr->yrepeat)/64*m->bscale; + m0.z *= f; m1.z *= f; a0.z *= f; + + // floor aligned + k1 = tspr->y; + if((globalorientation&48)==32) + { + m0.z = -m0.z; m1.z = -m1.z; a0.z = -a0.z; + m0.y = -m0.y; m1.y = -m1.y; a0.y = -a0.y; + f = a0.x; a0.x = a0.z; a0.z = f; + k1 += (float)((tilesizy[tspr->picnum]*tspr->yrepeat)>>3); + } + + f = (65536.0*512.0)/((float)xdimen*viewingrange); + g = 32.0/((float)xdimen*gxyaspect); + m0.y *= f; m1.y *= f; a0.y = (((float)(tspr->x-globalposx))/ 1024.0 + a0.y)*f; + m0.x *=-f; m1.x *=-f; a0.x = (((float)(k1 -globalposy))/ -1024.0 + a0.x)*-f; + m0.z *= g; m1.z *= g; a0.z = (((float)(k0 -globalposz))/-16384.0 + a0.z)*g; + + k0 = ((float)(tspr->x-globalposx))*f/1024.0; + k1 = ((float)(tspr->y-globalposy))*f/1024.0; + f = gcosang2*gshang; + g = gsinang2*gshang; + k4 = (float)sintable[(tspr->ang+spriteext[tspr->owner].angoff+1024)&2047] / 16384.0; + k5 = (float)sintable[(tspr->ang+spriteext[tspr->owner].angoff+ 512)&2047] / 16384.0; + k2 = k0*(1-k4)+k1*k5; + k3 = k1*(1-k4)-k0*k5; + k6 = f*gstang - gsinang*gctang; k7 = g*gstang + gcosang*gctang; + mat[0] = k4*k6 + k5*k7; mat[4] = gchang*gstang; mat[ 8] = k4*k7 - k5*k6; mat[12] = k2*k6 + k3*k7; + k6 = f*gctang + gsinang*gstang; k7 = g*gctang - gcosang*gstang; + mat[1] = k4*k6 + k5*k7; mat[5] = gchang*gctang; mat[ 9] = k4*k7 - k5*k6; mat[13] = k2*k6 + k3*k7; + k6 = gcosang2*gchang; k7 = gsinang2*gchang; + mat[2] = k4*k6 + k5*k7; mat[6] =-gshang; mat[10] = k4*k7 - k5*k6; mat[14] = k2*k6 + k3*k7; + + mat[12] += a0.y*mat[0] + a0.z*mat[4] + a0.x*mat[ 8]; + mat[13] += a0.y*mat[1] + a0.z*mat[5] + a0.x*mat[ 9]; + mat[14] += a0.y*mat[2] + a0.z*mat[6] + a0.x*mat[10]; + + // floor aligned + if((globalorientation&48)==32) + { + f = mat[4]; mat[4] = mat[8]*16.0; mat[8] = -f*(1.0/16.0); + f = mat[5]; mat[5] = mat[9]*16.0; mat[9] = -f*(1.0/16.0); + f = mat[6]; mat[6] = mat[10]*16.0; mat[10] = -f*(1.0/16.0); + } + + //Mirrors + if (grhalfxdown10x < 0) { mat[0] = -mat[0]; mat[4] = -mat[4]; mat[8] = -mat[8]; mat[12] = -mat[12]; } + + // ------ Unnecessarily clean (lol) code to generate translation/rotation matrix for MD2 ends ------ + + // PLAG: Cleaner model rotation code + if (spriteext[tspr->owner].pitch || spriteext[tspr->owner].roll) + { + if (spriteext[tspr->owner].xoff) + a0.x = (int)(spriteext[tspr->owner].xoff / (2048 * (m0.x+m1.x))); + else + a0.x = 0; + if (spriteext[tspr->owner].yoff) + a0.y = (int)(spriteext[tspr->owner].yoff / (2048 * (m0.y+m1.y))); + else + a0.y = 0; + if ((spriteext[tspr->owner].zoff) && !(tspr->cstat&1024)) + a0.z = (int)(spriteext[tspr->owner].zoff / (524288 * (m0.z+m1.z))); + else + a0.z = 0; + k0 = (float)sintable[(spriteext[tspr->owner].pitch+512)&2047] / 16384.0; + k1 = (float)sintable[spriteext[tspr->owner].pitch&2047] / 16384.0; + k2 = (float)sintable[(spriteext[tspr->owner].roll+512)&2047] / 16384.0; + k3 = (float)sintable[spriteext[tspr->owner].roll&2047] / 16384.0; + } + for(i=m->numverts-1;i>=0;i--) + { + if (spriteext[tspr->owner].pitch || spriteext[tspr->owner].roll) + { + fp.z = c0[(i<<2)+0] + a0.x; + fp.x = c0[(i<<2)+1] + a0.y; + fp.y = c0[(i<<2)+2] + a0.z; + fp1.x = fp.x*k2 + fp.y*k3; + fp1.y = fp.x*k0*(-k3) + fp.y*k0*k2 + fp.z*(-k1); + fp1.z = fp.x*k1*(-k3) + fp.y*k1*k2 + fp.z*k0; + fp.z = c1[(i<<2)+0] + a0.x; + fp.x = c1[(i<<2)+1] + a0.y; + fp2.y = c1[(i<<2)+2] + a0.z; + fp2.x = fp.x*k2 + fp.y*k3; + fp2.y = fp.x*k0*(-k3) + fp.y*k0*k2 + fp.z*(-k1); + fp2.z = fp.x*k1*(-k3) + fp.y*k1*k2 + fp.z*k0; + fp.z = (fp1.z - a0.x)*m0.x + (fp2.z - a0.x)*m1.x; + fp.x = (fp1.x - a0.y)*m0.y + (fp2.x - a0.y)*m1.y; + fp.y = (fp1.y - a0.z)*m0.z + (fp2.y - a0.z)*m1.z; + } + else + { + fp.z = c0[(i<<2)+0]*m0.x + c1[(i<<2)+0]*m1.x; + fp.y = c0[(i<<2)+2]*m0.z + c1[(i<<2)+2]*m1.z; + fp.x = c0[(i<<2)+1]*m0.y + c1[(i<<2)+1]*m1.y; + } + vertlist[i].x = fp.x; + vertlist[i].y = fp.y; + vertlist[i].z = fp.z; + } + bglMatrixMode(GL_MODELVIEW); //Let OpenGL (and perhaps hardware :) handle the matrix rotation + mat[3] = mat[7] = mat[11] = 0.f; mat[15] = 1.f; bglLoadMatrixf(mat); + // PLAG: End + + i = mdloadskin(m,tile2model[tspr->picnum].skinnum,globalpal,0); if (!i) return 0; + + //bit 10 is an ugly hack in game.c\animatesprites telling MD2SPRITE + //to use Z-buffer hacks to hide overdraw problems with the shadows + if (tspr->cstat&1024) + { + bglDepthFunc(GL_LESS); //NEVER,LESS,(,L)EQUAL,GREATER,(NOT,G)EQUAL,ALWAYS + bglDepthRange(0.0,0.9999); + } + bglPushAttrib(GL_POLYGON_BIT); + if ((grhalfxdown10x >= 0) ^ ((globalorientation&8) != 0) ^ ((globalorientation&4) != 0)) bglFrontFace(GL_CW); else bglFrontFace(GL_CCW); + bglEnable(GL_CULL_FACE); + bglCullFace(GL_BACK); + + bglEnable(GL_TEXTURE_2D); + bglBindTexture(GL_TEXTURE_2D, i); + + pc[0] = pc[1] = pc[2] = ((float)(numpalookups-min(max(globalshade+m->shadeoff,0),numpalookups)))/((float)numpalookups); + pc[0] *= (float)hictinting[globalpal].r / 255.0; + pc[1] *= (float)hictinting[globalpal].g / 255.0; + pc[2] *= (float)hictinting[globalpal].b / 255.0; +if (tspr->cstat&2) { if (!(tspr->cstat&512)) pc[3] = 0.66; else pc[3] = 0.33; } else pc[3] = 1.0; + if (m->usesalpha) //Sprites with alpha in texture + { + // bglEnable(GL_BLEND);// bglBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA); + // bglEnable(GL_ALPHA_TEST); bglAlphaFunc(GL_GREATER,0.32); + float al = 0.32; + if (alphahackarray[globalpicnum] != 0) + al=alphahackarray[globalpicnum]; + bglEnable(GL_BLEND); + bglEnable(GL_ALPHA_TEST); + bglAlphaFunc(GL_GREATER,al); + } + else + { + if (tspr->cstat&2) bglEnable(GL_BLEND); else bglDisable(GL_BLEND); + } + bglColor4f(pc[0],pc[1],pc[2],pc[3]); + + for(lptr=m->glcmds;(i=*lptr++);) + { + if (i < 0) { bglBegin(GL_TRIANGLE_FAN); i = -i; } + else { bglBegin(GL_TRIANGLE_STRIP); } + for(;i>0;i--,lptr+=3) + { + bglTexCoord2f(((float *)lptr)[0],((float *)lptr)[1]); + bglVertex3fv((float *)&vertlist[lptr[2]]); + } + bglEnd(); + } + + if (m->usesalpha) bglDisable(GL_ALPHA_TEST); + bglDisable(GL_CULL_FACE); + bglPopAttrib(); + if (tspr->cstat&1024) + { + bglDepthFunc(GL_LEQUAL); //NEVER,LESS,(,L)EQUAL,GREATER,(NOT,G)EQUAL,ALWAYS + bglDepthRange(0.0,0.99999); + } + bglLoadIdentity(); + + return 1; +} //---------------------------------------- MD2 LIBRARY ENDS ---------------------------------------- // DICHOTOMIC RECURSIVE SORTING - USED BY MD3DRAW - MAY PUT IT IN ITS OWN SOURCE FILE LATER @@ -1168,6 +1412,9 @@ if ((m->head.id != 0x33504449) && (m->head.vers != 15)) { free(m); return(0); } offs[1] = ofsurf+((long)(s->shaders)); leng[1] = s->numshaders*sizeof(md3shader_t); offs[2] = ofsurf+((long)(s->uv )); leng[2] = s->numverts*sizeof(md3uv_t); offs[3] = ofsurf+((long)(s->xyzn )); leng[3] = s->numframes*s->numverts*sizeof(md3xyzn_t); + //memoryusage += (s->numverts * s->numframes * sizeof(md3xyzn_t)); + //OSD_Printf("Current model geometry memory usage : %i.\n", memoryusage); + s->tris = (md3tri_t *)malloc(leng[0]+leng[1]+leng[2]+leng[3]); if (!s->tris) @@ -1239,7 +1486,7 @@ 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; - float f, g, k0, k1, k2, k3, k4, k5, k6, k7, mat[16], pc[4]; + 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; @@ -1253,10 +1500,14 @@ static int md3draw (md3model *m, spritetype *tspr) //create current&next frame's vertex list from whole list + if (m->head.flags == 1337) + mult = 1 * m->scale; // md2 + else + mult = (1.0/64.0) * m->scale; f = m->interpol; g = 1-f; - m0.x = (1.0/64.0)*m->scale*g; m1.x = (1.0/64.0)*m->scale*f; - m0.y = (1.0/64.0)*m->scale*g; m1.y = (1.0/64.0)*m->scale*f; - m0.z = (1.0/64.0)*m->scale*g; m1.z = (1.0/64.0)*m->scale*f; + m0.x = mult*g; m1.x = mult*f; + m0.y = mult*g; m1.y = mult*f; + m0.z = mult*g; m1.z = mult*f; a0.x = a0.y = 0; a0.z = m->zadd*m->scale; // Parkar: Moved up to be able to use k0 for the y-flipping code @@ -1361,6 +1612,8 @@ if (tspr->cstat&2) { if (!(tspr->cstat&512)) pc[3] = 0.66; else pc[3] = 0.33; } if (tspr->cstat&2) bglEnable(GL_BLEND); else bglDisable(GL_BLEND); } bglColor4f(pc[0],pc[1],pc[2],pc[3]); + if (m->head.flags == 1337) + bglColor4f(0.0f, 0.0f, 1.0f, 1.0f); //------------ // PLAG: Cleaner model rotation code @@ -2433,7 +2686,7 @@ int mddraw (spritetype *tspr) vm = models[tile2model[tspr->picnum].modelid]; if (vm->mdnum == 1) { return voxdraw((voxmodel *)vm,tspr); } - //if (vm->mdnum == 2) { return md2draw((md2model *)vm,tspr); } nope ! + if (vm->mdnum == 2) { return md2draw((md2model *)vm,tspr); } if (vm->mdnum == 3) { return md3draw((md3model *)vm,tspr); } return 0; } @@ -2441,7 +2694,7 @@ int mddraw (spritetype *tspr) void mdfree (mdmodel *vm) { if (vm->mdnum == 1) { voxfree((voxmodel *)vm); return; } - //if (vm->mdnum == 2) { md2free((md2model *)vm); return; } yeah right ! + if (vm->mdnum == 2) { md2free((md2model *)vm); return; } if (vm->mdnum == 3) { md3free((md3model *)vm); return; } } diff --git a/polymer/build/src/polymer.c b/polymer/build/src/polymer.c index 0348af26a..31a3fdd92 100644 --- a/polymer/build/src/polymer.c +++ b/polymer/build/src/polymer.c @@ -1,33 +1,26 @@ // 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; +#include "polymer.h" _prsector* prsectors[MAXSECTORS]; -void polymer_init(void) +float polymostprojmatrix[16]; +float polymostmodelmatrix[16]; + +// tesselation variables +GLUtesselator* prtess; +int tempverticescount; +GLdouble* tempvertices; + +// Polymer cvars +char pr_verbosity = 1; // 0: silent, 1: errors and one-times, 2: multiple-times, 3: flood +char pr_wireframe = 0; + +int polymer_init(void) { int i; - OSD_Printf("Initalizing Polymer subsystem.\n"); + if (pr_verbosity >= 1) OSD_Printf("Initalizing Polymer subsystem...\n"); i = 0; while (i < MAXSECTORS) @@ -35,116 +28,345 @@ void polymer_init(void) prsectors[i] = NULL; i++; } + + prtess = gluNewTess(); + if (prtess == 0) + { + if (pr_verbosity >= 1) OSD_Printf("PR : Tesselator initialization failed.\n"); + return (0); + } + + if (pr_verbosity >= 1) OSD_Printf("PR : Initialization complete.\n"); + return (1); } -void polymer_glinit(void) +void polymer_glinit(void) { + GLfloat params[4]; + + 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); bglViewport(0, 0, 1024, 768); - bglDisable(GL_TEXTURE_2D); + + // texturing + bglEnable(GL_TEXTURE_2D); + //bglEnable(GL_TEXTURE_GEN_S); + //bglEnable(GL_TEXTURE_GEN_T); + params[0] = GL_OBJECT_LINEAR; + bglTexGenfv(GL_S, GL_TEXTURE_GEN_MODE, params); + bglTexGenfv(GL_T, GL_TEXTURE_GEN_MODE, params); + params[0] = 1.0 / 10000.0; + params[1] = 1.0 / 10000.0; + params[2] = 1.0 / 10000.0; + params[3] = 1.0 / 10000.0; + bglTexGenfv(GL_S, GL_OBJECT_PLANE, params); + bglTexGenfv(GL_T, GL_OBJECT_PLANE, params); + bglDisable(GL_FOG); bglEnable(GL_DEPTH_TEST); + if (pr_wireframe) + bglPolygonMode(GL_FRONT_AND_BACK, GL_LINE); + else + bglPolygonMode(GL_FRONT_AND_BACK, GL_FILL); + bglMatrixMode(GL_PROJECTION); bglLoadIdentity(); - bglFrustum(-1.0f, 1.0f, -0.75f, 0.75, 1.0f, 10000.0f); + bglFrustum(-1.0f, 1.0f, -0.75f, 0.75, 1.0f, 1000000.0f); bglMatrixMode(GL_MODELVIEW); bglLoadIdentity(); } -void polymer_buildsector(short sectnum) +int polymer_updategeometry(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)); + sectortype *sec; + walltype *wal; + int i, ret; + s = prsectors[sectnum]; sec = §or[sectnum]; wal = &wall[sec->wallptr]; - s->v = malloc(sizeof(_prvertex) * sec->wallnum); + if (s == NULL) + { + if (pr_verbosity >= 1) OSD_Printf("PR : Can't update uninitialized sector %i.\n", sectnum); + return (-1); + } + + if (sec->wallnum != s->wallcount) + { + s->wallcount = sec->wallnum; + s->verts = realloc(s->verts, sizeof(_prvertex) * s->wallcount); + memset(s->verts, 0, sizeof(_prvertex) * s->wallcount); + ret = 1; + } + else + ret = 0; i = 0; - while (i < sec->wallnum) + while (i < s->wallcount) { - 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; + s->verts[i].wallnum = sec->wallptr + i; + s->verts[i].v[2] = -wal->x; + s->verts[i].v[0] = wal->y; + s->verts[i].v[1] = -sec->floorz; i++; wal = &wall[sec->wallptr + i]; } + if (pr_verbosity >= 3) OSD_Printf("PR : Updated sector %i.\n", sectnum); + + return (ret); +} + +// This callback is called by the tesselator when it detects an intersection between contours (HELLO ROTATING SPOTLIGHT IN E1L1). +// In this case, we create a new temporary vertex at the intersection point which will be freed after the polygon is drawn. +void __stdcall polymer_tesscombine(GLdouble v[3], GLdouble *data[4], GLfloat weight[4], GLdouble **out) +{ + GLdouble *ptr; + + tempverticescount++; + tempvertices = realloc(tempvertices, tempverticescount * sizeof(GLdouble) * 3); + tempvertices[(tempverticescount * 3) - 3] = v[0]; + tempvertices[(tempverticescount * 3) - 2] = v[1]; + tempvertices[(tempverticescount * 3) - 1] = v[2]; + + ptr = &tempvertices[(tempverticescount - 1) * 3]; + *out = ptr; + + if (pr_verbosity >= 2) OSD_Printf("PR : Created additional geometry for sector tesselation.\n"); +} + +// This callback is called by the tesselator whenever it raises an error. +void __stdcall polymer_tesserror(GLenum error) +{ + if (pr_verbosity >= 1) OSD_Printf("PR : Tesselation error number %i reported : %s.\n", error, gluErrorString(errno)); +} + +// This function tesselates the floor/ceiling of a sector and stores the triangles in a display list. +int polymer_buildfloor(short sectnum) +{ + _prsector* s; + sectortype *sec; + int i; + + if (pr_verbosity >= 2) OSD_Printf("PR : Tesselating floor of sector %i...\n", sectnum); + + s = prsectors[sectnum]; + sec = §or[sectnum]; + + if (s == NULL) + return (-1); + + bglNewList(sectnum + 1, GL_COMPILE); + + gluTessCallback(prtess, GLU_TESS_BEGIN, bglBegin); + gluTessCallback(prtess, GLU_TESS_VERTEX, bglVertex3dv); + gluTessCallback(prtess, GLU_TESS_END, bglEnd); + gluTessCallback(prtess, GLU_TESS_COMBINE, polymer_tesscombine); + gluTessCallback(prtess, GLU_TESS_ERROR, polymer_tesserror); + + gluTessProperty(prtess, GLU_TESS_WINDING_RULE, GLU_TESS_WINDING_POSITIVE); + + tempverticescount = 0; + + gluTessBeginPolygon(prtess, NULL); + gluTessBeginContour(prtess); + + i = 0; + while (i < sec->wallnum) + { + gluTessVertex(prtess, s->verts[i].v, s->verts[i].v); + if ((i != (sec->wallnum - 1)) && (s->verts[i].wallnum > wall[s->verts[i].wallnum].point2)) + { + gluTessEndContour(prtess); + gluTessBeginContour(prtess); + } + i++; + } + gluTessEndContour(prtess); + gluTessEndPolygon(prtess); + + bglEndList(); + + if (tempverticescount) + { + free(tempvertices); + tempverticescount = 0; + } + + if (pr_verbosity >= 2) OSD_Printf("PR : Tesselated floor of sector %i.\n", sectnum); + + return (1); +} + +int polymer_initsector(short sectnum) +{ + sectortype *sec; + _prsector* s; + + if (pr_verbosity >= 2) OSD_Printf("PR : Initalizing sector %i...\n", sectnum); + + sec = §or[sectnum]; + s = malloc(sizeof(_prsector)); + if (s == NULL) + { + if (pr_verbosity >= 1) OSD_Printf("PR : Cannot initialize sector %i : malloc failed.\n", sectnum); + return (0); + } + + s->invalidate = 0; + s->wallcount = sec->wallnum; + s->verts = malloc(s->wallcount * sizeof(_prvertex)); + if (s->verts == NULL) + { + if (pr_verbosity >= 1) OSD_Printf("PR : Cannot initialize geometry of sector %i : malloc failed.\n", sectnum); + return (0); + } + prsectors[sectnum] = s; + + if (pr_verbosity >= 2) OSD_Printf("PR : Initalized sector %i.\n", sectnum); + + return (1); } void polymer_drawsector(long daposx, long daposy, long daposz, short daang, long dahoriz, short sectnum) { - sectortype *sec; - int i; + sectortype *sec, *nextsec; + walltype *wal; + _prsector* s; float ang; - _prvertex v, pos; + double pos[3]; + int i; + long zdiff; + pthtyp* pth; - OSD_Printf("Polymer: drawing sector %i with angle %i\n", sectnum, daang); + if (pr_verbosity >= 3) OSD_Printf("PR : Drawing sector %i...\n", sectnum); - //if (prsectors[sectnum] == NULL) - polymer_buildsector(sectnum); + if (prsectors[sectnum] == NULL) + { + polymer_initsector(sectnum); + polymer_updategeometry(sectnum); + polymer_buildfloor(sectnum); + } + else if (prsectors[sectnum]->invalidate) + { + if (pr_verbosity >= 2) OSD_Printf("PR : Sector %i invalidated. Tesselating...\n", sectnum); + polymer_updategeometry(sectnum); + polymer_buildfloor(sectnum); + if (prsectors[sectnum]->invalidate) + prsectors[sectnum]->invalidate = 0; + } + + sec = §or[sectnum]; + wal = &wall[sec->wallptr]; + s = prsectors[sectnum]; ang = (float)(daang) / (2048.0f / 360.0f); - sec = §or[sectnum]; + pos[0] = -daposy; + pos[1] = daposz; + pos[2] = daposx; bglMatrixMode(GL_MODELVIEW); bglLoadIdentity(); bglRotatef(ang, 0.0f, 1.0f, 0.0f); + bglScalef(1.0f, 1.0f / 16.0f, 1.0f); + bglTranslatef(pos[0], pos[1], pos[2]); - bglBegin(GL_LINE_LOOP); + // floor + pth = gltexcache(sec->floorpicnum,sec->floorpal,0); + bglBindTexture(GL_TEXTURE_2D, pth ? pth->glpic : 0); bglColor4f(1.0f, 1.0f, 1.0f, 1.0f); + bglCallList(sectnum + 1); // DONT FORGET THE +1 DAMMIT - 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); + // ceiling + pth = gltexcache(sec->ceilingpicnum,sec->ceilingpal,0); + bglBindTexture(GL_TEXTURE_2D, pth ? pth->glpic : 0); + bglColor4f(1.0f, 0.0f, 0.0f, 1.0f); + bglPushMatrix(); + bglTranslatef(0.0f, sec->floorz - sec->ceilingz, 0.0f); + bglCallList(sectnum + 1); + bglPopMatrix(); + + // walls + i = 0; + while (i < sec->wallnum) + { + if (wal->nextsector == -1) + { // limit of the map + pth = gltexcache(wal->picnum,wal->pal,0); + bglBindTexture(GL_TEXTURE_2D, pth ? pth->glpic : 0); + bglColor4f(0.0f, 1.0f, 0.0f, 1.0f); + bglBegin(GL_QUADS); + bglVertex3d(s->verts[i].v[0], s->verts[i].v[1], s->verts[i].v[2]); + bglVertex3d(s->verts[wal->point2 - sec->wallptr].v[0], s->verts[wal->point2 - sec->wallptr].v[1], s->verts[wal->point2 - sec->wallptr].v[2]); + bglVertex3d(s->verts[wal->point2 - sec->wallptr].v[0], s->verts[wal->point2 - sec->wallptr].v[1] + (sec->floorz - sec->ceilingz), s->verts[wal->point2 - sec->wallptr].v[2]); + bglVertex3d(s->verts[i].v[0], s->verts[i].v[1] + (sec->floorz - sec->ceilingz), s->verts[i].v[2]); + bglEnd(); + } + else + { + nextsec = §or[wal->nextsector]; + zdiff = sec->floorz - nextsec->floorz; + if (zdiff > 0) + { // floor polymerization + pth = gltexcache(wal->picnum,wal->pal,0); + bglBindTexture(GL_TEXTURE_2D, pth ? pth->glpic : 0); + bglColor4f(0.0f, 0.0f, 1.0f, 1.0f); + bglBegin(GL_QUADS); + bglVertex3d(s->verts[i].v[0], s->verts[i].v[1], s->verts[i].v[2]); + bglVertex3d(s->verts[wal->point2 - sec->wallptr].v[0], s->verts[wal->point2 - sec->wallptr].v[1], s->verts[wal->point2 - sec->wallptr].v[2]); + bglVertex3d(s->verts[wal->point2 - sec->wallptr].v[0], s->verts[wal->point2 - sec->wallptr].v[1] + zdiff, s->verts[wal->point2 - sec->wallptr].v[2]); + bglVertex3d(s->verts[i].v[0], s->verts[i].v[1] + zdiff, s->verts[i].v[2]); + bglEnd(); + } + zdiff = sec->ceilingz - nextsec->ceilingz; + if (zdiff > 0) + { // ceiling polymerization + pth = gltexcache(wal->picnum,wal->pal,0); + bglBindTexture(GL_TEXTURE_2D, pth ? pth->glpic : 0); + bglColor4f(1.0f, 0.0f, 1.0f, 1.0f); + bglBegin(GL_QUADS); + bglVertex3d(s->verts[i].v[0], s->verts[i].v[1] + (sec->floorz - sec->ceilingz), s->verts[i].v[2]); + bglVertex3d(s->verts[wal->point2 - sec->wallptr].v[0], s->verts[wal->point2 - sec->wallptr].v[1] + (sec->floorz - sec->ceilingz), s->verts[wal->point2 - sec->wallptr].v[2]); + bglVertex3d(s->verts[wal->point2 - sec->wallptr].v[0], s->verts[wal->point2 - sec->wallptr].v[1] + zdiff + (sec->floorz - sec->ceilingz), s->verts[wal->point2 - sec->wallptr].v[2]); + bglVertex3d(s->verts[i].v[0], s->verts[i].v[1] + zdiff + (sec->floorz - sec->ceilingz), s->verts[i].v[2]); + bglEnd(); + } + } + + i++; + wal = &wall[sec->wallptr + 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(); + + if (pr_verbosity >= 3) OSD_Printf("PR : Finished drawing sector %i...\n", sectnum); } void polymer_drawrooms(long daposx, long daposy, long daposz, short daang, long dahoriz, short dacursectnum) { int i; - OSD_Printf("Polymer: drawing rooms\n"); + + 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); i++; } + + bglMatrixMode(GL_PROJECTION); + bglLoadMatrixf(polymostprojmatrix); + bglMatrixMode(GL_MODELVIEW); + bglLoadMatrixf(polymostmodelmatrix); + + if (pr_verbosity >= 3) OSD_Printf("PR : Rooms drawn.\n"); } diff --git a/polymer/build/src/polymost.c b/polymer/build/src/polymost.c index 2da4a7647..ca3fbae73 100644 --- a/polymer/build/src/polymost.c +++ b/polymer/build/src/polymost.c @@ -304,7 +304,8 @@ float alphahackarray[MAXTILES]; // every virtual texture, I use a cache where indexing is managed through a hash table. // -typedef struct pthtyp_t +// moved into polymost.h +/*typedef struct pthtyp_t { struct pthtyp_t *next; GLuint glpic; @@ -319,7 +320,7 @@ typedef struct pthtyp_t float scalex, scaley; struct pthtyp_t *wofb; // without fullbright struct pthtyp_t *ofb; // only fullbright -} pthtyp; +} pthtyp;*/ #define GLTEXCACHEADSIZ 8192 static pthtyp *gltexcachead[GLTEXCACHEADSIZ]; @@ -329,7 +330,7 @@ static long drawingskybox = 0; int gloadtile_art(long,long,long,pthtyp*,long); int gloadtile_hi(long,long,hicreplctyp*,long,pthtyp*,long,char); static int hicprecaching = 0; -static pthtyp * gltexcache (long dapicnum, long dapalnum, long dameth) +pthtyp * gltexcache (long dapicnum, long dapalnum, long dameth) { long i, j; hicreplctyp *si; @@ -3838,7 +3839,7 @@ 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))) + if (((tspr->cstat&2) || (gltexmayhavealpha(tspr->picnum,tspr->pal))) && ((tspr->cstat&48) != 0)) bglDepthMask(0); #endif diff --git a/polymer/eduke32/source/osdcmds.c b/polymer/eduke32/source/osdcmds.c index e601bc097..77e23811f 100644 --- a/polymer/eduke32/source/osdcmds.c +++ b/polymer/eduke32/source/osdcmds.c @@ -23,7 +23,9 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include "baselayer.h" #include "duke3d.h" #include "crc32.h" - +#if defined(POLYMOST) && defined(USE_OPENGL) +# include "polymer.h" +#endif #include struct osdcmd_cheatsinfo osdcmd_cheatsinfo_stat; @@ -469,6 +471,9 @@ struct cvarmappings { #if defined(POLYMOST) && defined(USE_OPENGL) { "r_anamorphic", "r_anamorphic: enable/disable widescreen mode", (void*)&glwidescreen, CVAR_BOOL, 0, 0, 1 }, { "r_projectionhack", "r_projectionhack: enable/disable projection hack", (void*)&glprojectionhacks, CVAR_BOOL, 0, 0, 1 }, + // polymer cvars + { "pr_verbosity", "pr_verbosity: verbosity level of the polymer renderer", (void*)&pr_verbosity, CVAR_INT, 0, 0, 3 }, + { "pr_wireframe", "pr_wireframe: toggles wireframe mode", (void*)&pr_wireframe, CVAR_BOOL, 0, 0, 1 }, #endif { "r_precache", "r_precache: enable/disable the pre-level caching routine", (void*)&useprecache, CVAR_BOOL, 0, 0, 1 } };