Polymer texturing and shading.

git-svn-id: https://svn.eduke32.com/eduke32@304 1a8010ca-5511-0410-912e-c29ae57300e0
This commit is contained in:
Plagman 2006-09-29 21:36:12 +00:00
parent a4c411d637
commit 2ce69e749f
7 changed files with 506 additions and 199 deletions

View file

@ -115,6 +115,7 @@ extern void (APIENTRY * bglEnableClientState)(GLenum cap);
extern void (APIENTRY * bglDisableClientState)(GLenum cap); extern void (APIENTRY * bglDisableClientState)(GLenum cap);
extern void (APIENTRY * bglVertexPointer)(GLint size, GLenum type, GLsizei stride, const GLvoid *pointer); extern void (APIENTRY * bglVertexPointer)(GLint size, GLenum type, GLsizei stride, const GLvoid *pointer);
extern void (APIENTRY * bglTexCoordPointer)(GLint size, GLenum type, GLsizei stride, const GLvoid *pointer); 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); extern void (APIENTRY * bglDrawElements)(GLenum mode, GLsizei count, GLenum type, const GLvoid *indices);
#ifdef RENDERTYPEWIN #ifdef RENDERTYPEWIN

View file

@ -16,15 +16,19 @@
# include "polymost.h" # include "polymost.h"
# include "pragmas.h" # include "pragmas.h"
void polymer_glinit(void); // CVARS
int polymer_init(void); extern char pr_verbosity;
void polymer_drawrooms(long daposx, long daposy, long daposz, short daang, long dahoriz, short dacursectnum); extern char pr_wireframe;
// DATA
typedef struct s_prsector { typedef struct s_prsector {
// geometry // geometry
GLdouble* verts; GLdouble* verts;
GLfloat* floorbuffer; GLfloat* floorbuffer;
GLfloat* ceilbuffer; GLfloat* ceilbuffer;
// attributes
GLfloat floorcolor[4], ceilcolor[4];
GLuint floorglpic, ceilglpic;
// elements // elements
GLushort* indices; GLushort* indices;
short curindice; short curindice;
@ -34,10 +38,38 @@ typedef struct s_prsector {
char invalidate; char invalidate;
} _prsector; } _prsector;
extern _prsector* prsectors[MAXSECTORS]; typedef struct s_prwall {
// geometry
GLfloat* wallbuffer;
GLfloat* overbuffer;
// attributes
GLfloat wallcolor[4], overcolor[4];
GLfloat wallglpic, overglpic;
// Polymer cvars char underover;
extern char pr_verbosity; char invalidate;
extern char pr_wireframe; } _prwall;
extern _prsector* prsectors[MAXSECTORS];
extern _prwall* prwalls[MAXWALLS];
// EXTERNAL FUNCTIONS
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);
// SECTOR MANAGEMENT
int polymer_initsector(short sectnum);
int polymer_updatesector(short sectnum);
void PR_CALLBACK polymer_tesscombine(GLdouble v[3], GLdouble *data[4], GLfloat weight[4], GLdouble **out);
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);
// WALL MANAGEMENT
int polymer_initwall(short wallnum);
void polymer_updatewall(short wallnum);
void polymer_drawwall(short wallnum);
#endif // !_polymer_h_ #endif // !_polymer_h_

View file

@ -35,4 +35,6 @@ typedef struct pthtyp_t
pthtyp * gltexcache (long dapicnum, long dapalnum, long dameth); pthtyp * gltexcache (long dapicnum, long dapalnum, long dameth);
extern palette_t hictinting[MAXPALOOKUPS];
#endif // !_polymost_h_ #endif // !_polymost_h_

View file

@ -6671,6 +6671,9 @@ long loadboard(char *filename, char fromwhere, long *daposx, long *daposy, long
#if defined(POLYMOST) && defined(USE_OPENGL) #if defined(POLYMOST) && defined(USE_OPENGL)
memset(spriteext, 0, sizeof(spriteext)); memset(spriteext, 0, sizeof(spriteext));
if (rendmode == 4)
polymer_loadboard();
#endif #endif
guniqhudid = 0; guniqhudid = 0;

View file

@ -99,6 +99,7 @@ void (APIENTRY * bglEnableClientState)(GLenum cap);
void (APIENTRY * bglDisableClientState)(GLenum cap); void (APIENTRY * bglDisableClientState)(GLenum cap);
void (APIENTRY * bglVertexPointer)(GLint size, GLenum type, GLsizei stride, const GLvoid *pointer); void (APIENTRY * bglVertexPointer)(GLint size, GLenum type, GLsizei stride, const GLvoid *pointer);
void (APIENTRY * bglTexCoordPointer)(GLint size, GLenum type, GLsizei stride, const GLvoid *pointer); void (APIENTRY * bglTexCoordPointer)(GLint size, GLenum type, GLsizei stride, const GLvoid *pointer);
void (APIENTRY * bglDrawArrays)(GLenum mode, GLint first, GLsizei count);
void (APIENTRY * bglDrawElements)(GLenum mode, GLsizei count, GLenum type, const GLvoid *indices); void (APIENTRY * bglDrawElements)(GLenum mode, GLsizei count, GLenum type, const GLvoid *indices);
#ifdef RENDERTYPEWIN #ifdef RENDERTYPEWIN
@ -267,6 +268,7 @@ int loadgldriver(const char *driver)
bglDisableClientState = GETPROC("glDisableClientState"); bglDisableClientState = GETPROC("glDisableClientState");
bglVertexPointer = GETPROC("glVertexPointer"); bglVertexPointer = GETPROC("glVertexPointer");
bglTexCoordPointer = GETPROC("glTexCoordPointer"); bglTexCoordPointer = GETPROC("glTexCoordPointer");
bglDrawArrays = GETPROC("glDrawArrays");
bglDrawElements = GETPROC("glDrawElements"); bglDrawElements = GETPROC("glDrawElements");
loadglextensions(); loadglextensions();

View file

@ -7,7 +7,7 @@
#include "kplib.h" #include "kplib.h"
#define HICEFFECTMASK (1|2) #define HICEFFECTMASK (1|2)
static palette_t hictinting[MAXPALOOKUPS]; palette_t hictinting[MAXPALOOKUPS];
//moved into polymost.h //moved into polymost.h
/*struct hicskybox_t { /*struct hicskybox_t {

View file

@ -2,20 +2,22 @@
#include "polymer.h" #include "polymer.h"
_prsector* prsectors[MAXSECTORS]; // CVARS
char pr_verbosity = 1; // 0: silent, 1: errors and one-times, 2: multiple-times, 3: flood
char pr_wireframe = 0;
// DATA
_prsector *prsectors[MAXSECTORS];
_prwall *prwalls[MAXWALLS];
float polymostprojmatrix[16]; float polymostprojmatrix[16];
float polymostmodelmatrix[16]; float polymostmodelmatrix[16];
// tesselation variables
GLUtesselator* prtess; GLUtesselator* prtess;
int tempverticescount; int tempverticescount;
GLdouble tempvertice[3]; GLdouble tempvertice[3];
// Polymer cvars // EXTERNAL FUNCTIONS
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 polymer_init(void)
{ {
int i; int i;
@ -29,6 +31,13 @@ int polymer_init(void)
i++; i++;
} }
i = 0;
while (i < MAXWALLS)
{
prwalls[i] = NULL;
i++;
}
prtess = gluNewTess(); prtess = gluNewTess();
if (prtess == 0) if (prtess == 0)
{ {
@ -36,6 +45,8 @@ int polymer_init(void)
return (0); return (0);
} }
polymer_loadboard();
if (pr_verbosity >= 1) OSD_Printf("PR : Initialization complete.\n"); if (pr_verbosity >= 1) OSD_Printf("PR : Initialization complete.\n");
return (1); return (1);
} }
@ -78,9 +89,103 @@ void polymer_glinit(void)
bglFrustum(-1.0f, 1.0f, -0.75f, 0.75, 1.0f, 1000000.0f); bglFrustum(-1.0f, 1.0f, -0.75f, 0.75, 1.0f, 1000000.0f);
bglMatrixMode(GL_MODELVIEW); bglMatrixMode(GL_MODELVIEW);
bglLoadIdentity(); bglLoadIdentity();
bglEnableClientState(GL_VERTEX_ARRAY);
bglEnableClientState(GL_TEXTURE_COORD_ARRAY);
} }
int polymer_updategeometry(short sectnum) void polymer_loadboard(void)
{
int i;
i = 0;
while (i < numsectors)
{
polymer_initsector(i);
polymer_updatesector(i);
polymer_buildfloor(i);
i++;
}
i = 0;
while (i < numwalls)
{
polymer_initwall(i);
polymer_updatewall(i);
i++;
}
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)
{
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);
i++;
}
bglMatrixMode(GL_PROJECTION);
bglLoadMatrixf(polymostprojmatrix);
bglMatrixMode(GL_MODELVIEW);
bglLoadMatrixf(polymostmodelmatrix);
if (pr_verbosity >= 3) OSD_Printf("PR : Rooms drawn.\n");
}
// SECTOR MANAGEMENT
int polymer_initsector(short sectnum)
{
sectortype *sec;
_prsector* s;
int i;
if (pr_verbosity >= 2) OSD_Printf("PR : Initalizing sector %i...\n", sectnum);
sec = &sector[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->verts = calloc(sec->wallnum, sizeof(GLdouble) * 3);
s->floorbuffer = calloc(sec->wallnum, sizeof(GLfloat) * 5);
s->ceilbuffer = calloc(sec->wallnum, sizeof(GLfloat) * 5);
if ((s->verts == NULL) || (s->floorbuffer == NULL) || (s->ceilbuffer == NULL))
{
if (pr_verbosity >= 1) OSD_Printf("PR : Cannot initialize geometry of sector %i : malloc failed.\n", sectnum);
return (0);
}
s->indices = NULL;
prsectors[sectnum] = s;
/*i = sec->wallptr;
while (i < (sec->wallptr + sec->wallnum))
{
polymer_initwall(i);
i++;
}*/
if (pr_verbosity >= 2) OSD_Printf("PR : Initalized sector %i.\n", sectnum);
return (1);
}
int polymer_updatesector(short sectnum)
{ {
_prsector* s; _prsector* s;
sectortype *sec; sectortype *sec;
@ -90,8 +195,11 @@ int polymer_updategeometry(short sectnum)
long tex, tey; long tex, tey;
float secangcos, secangsin, scalecoef; float secangcos, secangsin, scalecoef;
long ang; long ang;
short curstat; short curstat, curpicnum;
char curxpanning, curypanning;
GLfloat* curbuffer; GLfloat* curbuffer;
GLuint* curglpic;
pthtyp* pth;
s = prsectors[sectnum]; s = prsectors[sectnum];
sec = &sector[sectnum]; sec = &sector[sectnum];
@ -112,8 +220,9 @@ int polymer_updategeometry(short sectnum)
secangsin = (float)(sintable[ang&2047]) / 16383.0f; secangsin = (float)(sintable[ang&2047]) / 16383.0f;
} }
// geometry
i = 0; i = 0;
while (i < s->wallcount) while (i < sec->wallnum)
{ {
s->verts[(i*3)+2] = s->floorbuffer[(i*5)+2] = s->ceilbuffer[(i*5)+2] = -wal->x; s->verts[(i*3)+2] = s->floorbuffer[(i*5)+2] = s->ceilbuffer[(i*5)+2] = -wal->x;
s->verts[i*3] = s->floorbuffer[i*5] = s->ceilbuffer[i*5] = wal->y; s->verts[i*3] = s->floorbuffer[i*5] = s->ceilbuffer[i*5] = wal->y;
@ -125,6 +234,9 @@ int polymer_updategeometry(short sectnum)
j = 2; j = 2;
curstat = sec->floorstat; curstat = sec->floorstat;
curbuffer = s->floorbuffer; curbuffer = s->floorbuffer;
curpicnum = sec->floorpicnum;
curxpanning = sec->floorxpanning;
curypanning = sec->floorypanning;
while (j) while (j)
{ {
@ -132,10 +244,13 @@ int polymer_updategeometry(short sectnum)
{ {
curstat = sec->ceilingstat; curstat = sec->ceilingstat;
curbuffer = s->ceilbuffer; curbuffer = s->ceilbuffer;
curpicnum = sec->ceilingpicnum;
curxpanning = sec->ceilingxpanning;
curypanning = sec->ceilingypanning;
} }
tex = (curstat & 64) ? ((wal->x - wall[sec->wallptr].x) * secangsin) + ((-wal->y - -wall[sec->wallptr].y) * secangcos) : wal->x; tex = (curstat & 64) ? ((wal->x - wall[sec->wallptr].x) * secangsin) + ((-wal->y - -wall[sec->wallptr].y) * secangcos) : wal->x;
tey = (curstat & 64) ? ((wal->x - wall[sec->wallptr].x) * secangcos) - ((-wal->y - -wall[sec->wallptr].y) * secangsin) : -wal->y; tey = (curstat & 64) ? ((wal->x - wall[sec->wallptr].x) * secangcos) - ((wall[sec->wallptr].y - wal->y) * secangsin) : -wal->y;
if (curstat & 4) if (curstat & 4)
swaplong(&tex, &tey); swaplong(&tex, &tey);
@ -145,8 +260,43 @@ int polymer_updategeometry(short sectnum)
scalecoef = (curstat & 8) ? 8.0f : 16.0f; scalecoef = (curstat & 8) ? 8.0f : 16.0f;
curbuffer[(i*5)+3] = ((float)(tex) / (scalecoef * tilesizx[sec->floorpicnum])) + ((float)(sec->floorxpanning) / 256.0f); curbuffer[(i*5)+3] = ((float)(tex) / (scalecoef * tilesizx[curpicnum])) + ((float)(curxpanning) / 256.0f);
curbuffer[(i*5)+4] = ((float)(tey) / (scalecoef * tilesizy[sec->floorpicnum])) + ((float)(sec->floorypanning) / 256.0f); curbuffer[(i*5)+4] = ((float)(tey) / (scalecoef * tilesizy[curpicnum])) + ((float)(curypanning) / 256.0f);
j--;
}
//attributes
j = 2;
curbuffer = s->floorcolor;
curstat = sec->floorshade;
curxpanning = sec->floorpal;
curpicnum = sec->floorpicnum;
curglpic = &s->floorglpic;
while (j > 0)
{
if (j == 1)
{
curbuffer = s->ceilcolor;
curstat = sec->ceilingshade;
curxpanning = sec->ceilingpal;
curpicnum = sec->ceilingpicnum;
curglpic = &s->ceilglpic;
}
curbuffer[0] = curbuffer[1] = curbuffer[2] = ((float)(numpalookups-min(max(curstat,0),numpalookups)))/((float)numpalookups);
curbuffer[3] = 1.0f;
pth = gltexcache(curpicnum,curxpanning,0);
if (pth && (pth->flags & 2) && (pth->palnum != curxpanning)) {
curbuffer[0] *= (float)hictinting[curxpanning].r / 255.0;
curbuffer[1] *= (float)hictinting[curxpanning].g / 255.0;
curbuffer[2] *= (float)hictinting[curxpanning].b / 255.0;
}
*curglpic = (pth) ? pth->glpic : 0;
j--; j--;
} }
@ -160,13 +310,11 @@ int polymer_updategeometry(short sectnum)
return (0); return (0);
} }
// This callback is called by the tesselator when it detects an intersection between contours (HELLO ROTATING SPOTLIGHT IN E1L1).
void PR_CALLBACK polymer_tesscombine(GLdouble v[3], GLdouble *data[4], GLfloat weight[4], GLdouble **out) void PR_CALLBACK polymer_tesscombine(GLdouble v[3], GLdouble *data[4], GLfloat weight[4], GLdouble **out)
{ { // This callback is called by the tesselator when it detects an intersection between contours (HELLO ROTATING SPOTLIGHT IN E1L1).
GLdouble* ptr; GLdouble* ptr;
//tempverticescount++;
//tempvertices = realloc(tempvertices, tempverticescount * sizeof(GLdouble) * 3);
tempvertice[0] = v[0]; tempvertice[0] = v[0];
tempvertice[1] = v[1]; tempvertice[1] = v[1];
tempvertice[2] = v[2]; tempvertice[2] = v[2];
@ -177,30 +325,18 @@ void PR_CALLBACK polymer_tesscombine(GLdouble v[3], GLdouble *data[4], GLfloa
if (pr_verbosity >= 2) OSD_Printf("PR : Created additional geometry for sector tesselation.\n"); 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 PR_CALLBACK polymer_tesserror(GLenum error) void PR_CALLBACK polymer_tesserror(GLenum error)
{ { // This callback is called by the tesselator whenever it raises an error.
if (pr_verbosity >= 1) OSD_Printf("PR : Tesselation error number %i reported : %s.\n", error, gluErrorString(errno)); if (pr_verbosity >= 1) OSD_Printf("PR : Tesselation error number %i reported : %s.\n", error, gluErrorString(errno));
} }
// Passing an edgeflag callback forces the tesselator to output a triangle list
void PR_CALLBACK polymer_tessedgeflag(GLboolean flag) void PR_CALLBACK polymer_tessedgeflag(GLenum error)
{ { // Passing an edgeflag callback forces the tesselator to output a triangle list
flag = 0;
return; return;
} }
void PR_CALLBACK polymer_tessbegin(GLenum type)
{
if (type != GL_TRIANGLES)
{
OSD_Printf("PR : NOT A TRIANGLE LIST !§//... !\n");
}
}
void PR_CALLBACK polymer_tessend(void)
{
}
void PR_CALLBACK polymer_tessvertex(void* vertex, void* sector) void PR_CALLBACK polymer_tessvertex(void* vertex, void* sector)
{ {
_prsector* s; _prsector* s;
@ -213,13 +349,11 @@ void PR_CALLBACK polymer_tessvertex(void* vertex, void* sector)
s->indicescount++; s->indicescount++;
s->indices = realloc(s->indices, s->indicescount * sizeof(GLushort)); s->indices = realloc(s->indices, s->indicescount * sizeof(GLushort));
} }
s->indices[s->curindice] = (GLushort)vertex; s->indices[s->curindice] = (int)vertex;
s->curindice++; s->curindice++;
} }
// This function tesselates the floor/ceiling of a sector and stores the triangles in a display list.
int polymer_buildfloor(short sectnum) int polymer_buildfloor(short sectnum)
{ { // This function tesselates the floor/ceiling of a sector and stores the triangles in a display list.
_prsector* s; _prsector* s;
sectortype *sec; sectortype *sec;
int i; int i;
@ -232,15 +366,14 @@ int polymer_buildfloor(short sectnum)
if (s == NULL) if (s == NULL)
return (-1); return (-1);
if (s->indices != NULL) if (s->indices == NULL)
free(s->indices); {
s->indicescount = (sec->wallnum - 2) * 3;
s->indicescount = (s->wallcount - 2) * 3;
s->indices = calloc(s->indicescount, sizeof(GLushort)); s->indices = calloc(s->indicescount, sizeof(GLushort));
}
s->curindice = 0; s->curindice = 0;
//gluTessCallback(prtess, GLU_TESS_BEGIN, polymer_tessbegin);
//gluTessCallback(prtess, GLU_TESS_END, polymer_tessend);
gluTessCallback(prtess, GLU_TESS_VERTEX_DATA, polymer_tessvertex); gluTessCallback(prtess, GLU_TESS_VERTEX_DATA, polymer_tessvertex);
gluTessCallback(prtess, GLU_TESS_EDGE_FLAG, polymer_tessedgeflag); gluTessCallback(prtess, GLU_TESS_EDGE_FLAG, polymer_tessedgeflag);
//gluTessCallback(prtess, GLU_TESS_COMBINE, polymer_tesscombine); //gluTessCallback(prtess, GLU_TESS_COMBINE, polymer_tesscombine);
@ -270,180 +403,314 @@ int polymer_buildfloor(short sectnum)
return (1); return (1);
} }
int polymer_initsector(short sectnum)
{
sectortype *sec;
_prsector* s;
if (pr_verbosity >= 2) OSD_Printf("PR : Initalizing sector %i...\n", sectnum);
sec = &sector[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 = calloc(s->wallcount, sizeof(GLdouble) * 3);
s->floorbuffer = calloc(s->wallcount, sizeof(GLfloat) * 5);
s->ceilbuffer = calloc(s->wallcount, sizeof(GLfloat) * 5);
if ((s->verts == NULL) || (s->floorbuffer == NULL) || (s->ceilbuffer == NULL))
{
if (pr_verbosity >= 1) OSD_Printf("PR : Cannot initialize geometry of sector %i : malloc failed.\n", sectnum);
return (0);
}
s->indices = NULL;
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) void polymer_drawsector(long daposx, long daposy, long daposz, short daang, long dahoriz, short sectnum)
{ {
sectortype *sec, *nextsec; sectortype *sec, *nextsec;
walltype *wal; walltype *wal;
_prsector* s; _prsector* s;
float ang; float ang, horizang;
double pos[3]; double pos[3];
int i; int i;
long zdiff; long zdiff;
pthtyp* pth;
if (pr_verbosity >= 3) OSD_Printf("PR : Drawing sector %i...\n", sectnum); if (pr_verbosity >= 3) OSD_Printf("PR : Drawing sector %i...\n", 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);
prsectors[sectnum]->invalidate = 0;
}
sec = &sector[sectnum]; sec = &sector[sectnum];
wal = &wall[sec->wallptr]; wal = &wall[sec->wallptr];
s = prsectors[sectnum]; s = prsectors[sectnum];
if (prsectors[sectnum] == NULL)
{
polymer_initsector(sectnum);
polymer_updatesector(sectnum);
polymer_buildfloor(sectnum);
}
else if (prsectors[sectnum]->invalidate)
{
if (pr_verbosity >= 2) OSD_Printf("PR : Sector %i invalidated. Tesselating...\n", sectnum);
polymer_updatesector(sectnum);
i = 0;
while (i < sec->wallnum)
{
polymer_updatewall(sec->wallptr + i);
i++;
}
polymer_buildfloor(sectnum);
prsectors[sectnum]->invalidate = 0;
}
ang = (float)(daang) / (2048.0f / 360.0f); ang = (float)(daang) / (2048.0f / 360.0f);
horizang = (float)(100 - dahoriz) / (256.0f / 90.0f);
pos[0] = -daposy; pos[0] = -daposy;
pos[1] = daposz; pos[1] = daposz;
pos[2] = daposx; pos[2] = daposx;
bglEnableClientState(GL_VERTEX_ARRAY);
bglEnableClientState(GL_TEXTURE_COORD_ARRAY);
bglMatrixMode(GL_MODELVIEW); bglMatrixMode(GL_MODELVIEW);
bglLoadIdentity(); bglLoadIdentity();
bglRotatef(horizang, 1.0f, 0.0f, 0.0f);
bglRotatef(ang, 0.0f, 1.0f, 0.0f); bglRotatef(ang, 0.0f, 1.0f, 0.0f);
bglScalef(1.0f, 1.0f / 16.0f, 1.0f); bglScalef(1.0f, 1.0f / 16.0f, 1.0f);
bglTranslatef(pos[0], pos[1], pos[2]); bglTranslatef(pos[0], pos[1], pos[2]);
bglEnable(GL_TEXTURE_2D);
// floor // floor
pth = gltexcache(sec->floorpicnum,sec->floorpal,0); bglBindTexture(GL_TEXTURE_2D, s->floorglpic);
bglBindTexture(GL_TEXTURE_2D, pth ? pth->glpic : 0); bglColor4f(s->floorcolor[0], s->floorcolor[1], s->floorcolor[2], s->floorcolor[3]);
bglColor4f(1.0f, 1.0f, 1.0f, 1.0f);
bglVertexPointer(3, GL_FLOAT, 5 * sizeof(GLfloat), s->floorbuffer); bglVertexPointer(3, GL_FLOAT, 5 * sizeof(GLfloat), s->floorbuffer);
bglTexCoordPointer(2, GL_FLOAT, 5 * sizeof(GLfloat), &s->floorbuffer[3]); bglTexCoordPointer(2, GL_FLOAT, 5 * sizeof(GLfloat), &s->floorbuffer[3]);
bglDrawElements(GL_TRIANGLES, s->indicescount, GL_UNSIGNED_SHORT, s->indices); bglDrawElements(GL_TRIANGLES, s->indicescount, GL_UNSIGNED_SHORT, s->indices);
// ceiling // ceiling
pth = gltexcache(sec->ceilingpicnum,sec->ceilingpal,0); bglBindTexture(GL_TEXTURE_2D, s->ceilglpic);
bglBindTexture(GL_TEXTURE_2D, pth ? pth->glpic : 0); bglColor4f(s->ceilcolor[0], s->ceilcolor[1], s->ceilcolor[2], s->ceilcolor[3]);
bglVertexPointer(3, GL_FLOAT, 5 * sizeof(GLfloat), s->ceilbuffer); bglVertexPointer(3, GL_FLOAT, 5 * sizeof(GLfloat), s->ceilbuffer);
bglTexCoordPointer(2, GL_FLOAT, 5 * sizeof(GLfloat), &s->ceilbuffer[3]); bglTexCoordPointer(2, GL_FLOAT, 5 * sizeof(GLfloat), &s->ceilbuffer[3]);
bglDrawElements(GL_TRIANGLES, s->indicescount, GL_UNSIGNED_SHORT, s->indices); bglDrawElements(GL_TRIANGLES, s->indicescount, GL_UNSIGNED_SHORT, s->indices);
bglDisableClientState(GL_TEXTURE_COORD_ARRAY); // walls
bglDisableClientState(GL_VERTEX_ARRAY);
/*// walls
i = 0; i = 0;
while (i < sec->wallnum) while (i < sec->wallnum)
{ {
if (wal->nextsector == -1) polymer_drawwall(sec->wallptr + i);
{ // 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 = &sector[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++; i++;
wal = &wall[sec->wallptr + i]; wal = &wall[sec->wallptr + i];
}*/ }
if (pr_verbosity >= 3) OSD_Printf("PR : Finished drawing sector %i...\n", sectnum); 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) // WALL MANAGEMENT
int polymer_initwall(short wallnum)
{ {
_prwall *w;
if (pr_verbosity >= 2) OSD_Printf("PR : Initalizing wall %i...\n", wallnum);
w = malloc(sizeof(_prwall));
if (w == NULL)
{
if (pr_verbosity >= 1) OSD_Printf("PR : Cannot initialize wall %i : malloc failed.\n", wallnum);
return (0);
}
w->invalidate = w->underover = 0;
w->wallbuffer = w->overbuffer = NULL;
prwalls[wallnum] = w;
if (pr_verbosity >= 2) OSD_Printf("PR : Initalized wall %i.\n", wallnum);
return (1);
}
void polymer_updatewall(short wallnum)
{
short nwallnum, nnwallnum;
walltype *wal;
sectortype *sec, *nsec;
_prwall *w;
_prsector *s, *ns;
pthtyp* pth;
long xref[2], yref, xdif, ydif, dist, ypancoef;
int i; int i;
if (pr_verbosity >= 3) OSD_Printf("PR : Drawing rooms...\n"); wal = &wall[wallnum];
sec = &sector[sectorofwall(wallnum)];
w = prwalls[wallnum];
s = prsectors[sectorofwall(wallnum)];
polymer_glinit(); if (w->wallbuffer == NULL)
w->wallbuffer = calloc(4, sizeof(GLfloat) * 5);
w->underover = 0;
w->wallcolor[0] = w->wallcolor[1] = w->wallcolor[2] = ((float)(numpalookups-min(max(wal->shade,0),numpalookups)))/((float)numpalookups);
w->wallcolor[3] = 1.0f;
if (wal->cstat & 8)
{
xref[0] = wall[wal->point2].x;
xref[1] = wall[wal->point2].y;
}
else
{
xref[0] = wal->x;
xref[1] = wal->y;
}
if (wal->nextsector == -1)
{
memcpy(w->wallbuffer, &s->floorbuffer[(wallnum - sec->wallptr) * 5], sizeof(GLfloat) * 3);
memcpy(&w->wallbuffer[5], &s->floorbuffer[(wal->point2 - sec->wallptr) * 5], sizeof(GLfloat) * 3);
memcpy(&w->wallbuffer[10], &s->ceilbuffer[(wal->point2 - sec->wallptr) * 5], sizeof(GLfloat) * 3);
memcpy(&w->wallbuffer[15], &s->ceilbuffer[(wallnum - sec->wallptr) * 5], sizeof(GLfloat) * 3);
pth = gltexcache(wal->picnum, wal->pal, 0);
w->wallglpic = pth ? pth->glpic : 0;
if (pth && (pth->flags & 2) && (pth->palnum != wal->pal)) {
w->wallcolor[0] *= (float)hictinting[wal->pal].r / 255.0;
w->wallcolor[1] *= (float)hictinting[wal->pal].g / 255.0;
w->wallcolor[2] *= (float)hictinting[wal->pal].b / 255.0;
}
if (wal->cstat & 4)
yref = sec->floorz;
else
yref = sec->ceilingz;
ypancoef = (int)(256.0f / tilesizy[wal->picnum]);
i = 0; i = 0;
while (i < numsectors) while (i < 4)
{ {
polymer_drawsector(daposx, daposy, daposz, daang, dahoriz, i); xdif = xref[0] + w->wallbuffer[(i * 5) + 2];
ydif = xref[1] - w->wallbuffer[(i * 5)];
dist = ((xdif * xdif) + (ydif * ydif)) != 0;
w->wallbuffer[(i * 5) + 3] = ((dist * 8.0f * wal->xrepeat) + wal->xpanning) / (float)(tilesizx[wal->picnum]);
w->wallbuffer[(i * 5) + 4] = (-(float)(yref + w->wallbuffer[(i * 5) + 1]) / ((tilesizy[wal->picnum] * 2048.0f) / (float)(wal->yrepeat))) + ((float)(wal->ypanning) / (float)(ypancoef * tilesizy[wal->picnum]));
if (wal->cstat & 256) w->wallbuffer[(i * 5) + 4] = -w->wallbuffer[(i * 5) + 4];
i++; i++;
} }
bglMatrixMode(GL_PROJECTION); w->underover |= 1;
bglLoadMatrixf(polymostprojmatrix); }
bglMatrixMode(GL_MODELVIEW); else
bglLoadMatrixf(polymostmodelmatrix); {
nwallnum = wal->nextwall;
nnwallnum = wall[nwallnum].point2;
nsec = &sector[wal->nextsector];
ns = prsectors[wal->nextsector];
if (pr_verbosity >= 3) OSD_Printf("PR : Rooms drawn.\n"); if (((s->floorbuffer[((wallnum - sec->wallptr) * 5) + 1] != ns->floorbuffer[((nnwallnum - nsec->wallptr) * 5) + 1]) ||
(s->floorbuffer[((wal->point2 - sec->wallptr) * 5) + 1] != ns->floorbuffer[((nwallnum - nsec->wallptr) * 5) + 1])) &&
(s->floorbuffer[((wallnum - sec->wallptr) * 5) + 1] <= ns->floorbuffer[((nnwallnum - nsec->wallptr) * 5) + 1]))
{
memcpy(w->wallbuffer, &s->floorbuffer[(wallnum - sec->wallptr) * 5], sizeof(GLfloat) * 3);
memcpy(&w->wallbuffer[5], &s->floorbuffer[(wal->point2 - sec->wallptr) * 5], sizeof(GLfloat) * 3);
memcpy(&w->wallbuffer[10], &ns->floorbuffer[(nwallnum - nsec->wallptr) * 5], sizeof(GLfloat) * 3);
memcpy(&w->wallbuffer[15], &ns->floorbuffer[(nnwallnum - nsec->wallptr) * 5], sizeof(GLfloat) * 3);
pth = gltexcache(wal->picnum, wal->pal, 0);
w->wallglpic = pth ? pth->glpic : 0;
if (pth && (pth->flags & 2) && (pth->palnum != wal->pal)) {
w->wallcolor[0] *= (float)hictinting[wal->pal].r / 255.0;
w->wallcolor[1] *= (float)hictinting[wal->pal].g / 255.0;
w->wallcolor[2] *= (float)hictinting[wal->pal].b / 255.0;
}
if (wal->cstat & 4)
yref = sec->ceilingz;
else
yref = nsec->floorz;
ypancoef = (int)(256.0f / tilesizy[wal->picnum]);
i = 0;
while (i < 4)
{
xdif = xref[0] + w->wallbuffer[(i * 5) + 2];
ydif = xref[1] - w->wallbuffer[(i * 5)];
dist = ((xdif * xdif) + (ydif * ydif)) != 0;
w->wallbuffer[(i * 5) + 3] = ((dist * 8.0f * wal->xrepeat) + wal->xpanning) / (float)(tilesizx[wal->picnum]);
w->wallbuffer[(i * 5) + 4] = (-(float)(yref + w->wallbuffer[(i * 5) + 1]) / ((tilesizy[wal->picnum] * 2048.0f) / (float)(wal->yrepeat))) + ((float)(wal->ypanning) / (float)(ypancoef * tilesizy[wal->picnum]));
if (wal->cstat & 256) w->wallbuffer[(i * 5) + 4] = -w->wallbuffer[(i * 5) + 4];
i++;
}
w->underover |= 1;
}
if (((s->ceilbuffer[((wallnum - sec->wallptr) * 5) + 1] != ns->ceilbuffer[((nnwallnum - nsec->wallptr) * 5) + 1]) ||
(s->ceilbuffer[((wal->point2 - sec->wallptr) * 5) + 1] != ns->ceilbuffer[((nwallnum - nsec->wallptr) * 5) + 1])) &&
(s->ceilbuffer[((wallnum - sec->wallptr) * 5) + 1] >= ns->ceilbuffer[((nnwallnum - nsec->wallptr) * 5) + 1]))
{
if (w->overbuffer == NULL)
w->overbuffer = calloc(4, sizeof(GLfloat) * 5);
memcpy(w->overbuffer, &ns->ceilbuffer[(nnwallnum - nsec->wallptr) * 5], sizeof(GLfloat) * 3);
memcpy(&w->overbuffer[5], &ns->ceilbuffer[(nwallnum - nsec->wallptr) * 5], sizeof(GLfloat) * 3);
memcpy(&w->overbuffer[10], &s->ceilbuffer[(wal->point2 - sec->wallptr) * 5], sizeof(GLfloat) * 3);
memcpy(&w->overbuffer[15], &s->ceilbuffer[(wallnum - sec->wallptr) * 5], sizeof(GLfloat) * 3);
pth = gltexcache((wal->overpicnum) ? wal->overpicnum : wal->picnum, wal->pal, 0);
w->overglpic = pth ? pth->glpic : 0;
memcpy(w->overcolor, w->wallcolor, sizeof(GLfloat) * 4);
if (pth && (pth->flags & 2) && (pth->palnum != wal->pal)) {
w->overcolor[0] *= (float)hictinting[wal->pal].r / 255.0;
w->overcolor[1] *= (float)hictinting[wal->pal].g / 255.0;
w->overcolor[2] *= (float)hictinting[wal->pal].b / 255.0;
}
if (wal->cstat & 4)
yref = sec->ceilingz;
else
yref = nsec->ceilingz;
ypancoef = (int)(256.0f / tilesizy[wal->picnum]);
i = 0;
while (i < 4)
{
xdif = xref[0] + w->overbuffer[(i * 5) + 2];
ydif = xref[1] - w->overbuffer[(i * 5)];
dist = ((xdif * xdif) + (ydif * ydif)) != 0;
w->overbuffer[(i * 5) + 3] = ((dist * 8.0f * wal->xrepeat) + wal->xpanning) / (float)(tilesizx[wal->picnum]);
w->overbuffer[(i * 5) + 4] = (-(float)(yref + w->overbuffer[(i * 5) + 1]) / ((tilesizy[wal->picnum] * 2048.0f) / (float)(wal->yrepeat))) + ((float)(wal->ypanning) / (float)(ypancoef * tilesizy[wal->picnum]));
if (wal->cstat & 256) w->overbuffer[(i * 5) + 4] = -w->overbuffer[(i * 5) + 4];
i++;
}
w->underover |= 2;
}
}
if (pr_verbosity >= 3) OSD_Printf("PR : Updated wall %i.\n", wallnum);
}
void polymer_drawwall(short wallnum)
{
_prwall *w;
if (pr_verbosity >= 3) OSD_Printf("PR : Drawing wall %i...\n", wallnum);
w = prwalls[wallnum];
if (w->underover & 1)
{
bglBindTexture(GL_TEXTURE_2D, w->wallglpic);
bglColor4f(w->wallcolor[0], w->wallcolor[1], w->wallcolor[2], w->wallcolor[3]);
bglVertexPointer(3, GL_FLOAT, 5 * sizeof(GLfloat), w->wallbuffer);
bglTexCoordPointer(2, GL_FLOAT, 5 * sizeof(GLfloat), &w->wallbuffer[3]);
bglDrawArrays(GL_QUADS, 0, 4);
}
if (w->underover & 2)
{
bglBindTexture(GL_TEXTURE_2D, w->overglpic);
bglColor4f(w->overcolor[0], w->overcolor[1], w->overcolor[2], w->overcolor[3]);
bglVertexPointer(3, GL_FLOAT, 5 * sizeof(GLfloat), w->overbuffer);
bglTexCoordPointer(2, GL_FLOAT, 5 * sizeof(GLfloat), &w->overbuffer[3]);
bglDrawArrays(GL_QUADS, 0, 4);
}
if (pr_verbosity >= 3) OSD_Printf("PR : Finished drawing wall %i...\n", wallnum);
} }