1
0
Fork 0
forked from fte/fteqw

Renders a little bit better now.

git-svn-id: https://svn.code.sf.net/p/fteqw/code/trunk@565 fc73d0e0-1445-4013-8a0c-d673dee63da5
This commit is contained in:
Spoike 2004-12-05 08:27:38 +00:00
parent 820907cb25
commit 7acdaa8779

View file

@ -102,6 +102,17 @@ typedef struct {
#define LINEDEF_STARTONMAP 256 #define LINEDEF_STARTONMAP 256
//others are ignored. //others are ignored.
typedef struct {
char name[8];
short width;
short height;
int gltexture;
// shader_t *glshader; // :o)
} gldoomtexture_t;
static gldoomtexture_t *gldoomtextures;
static int numgldoomtextures;
typedef struct { typedef struct {
short texx; short texx;
short texy; short texy;
@ -111,11 +122,13 @@ typedef struct {
unsigned short sector; unsigned short sector;
} dsidedef_t; } dsidedef_t;
typedef struct { typedef struct {
float texx; unsigned short texx;
float texy; unsigned short texy;
int uppertex;
int lowertex; unsigned short uppertex;
int middletex; unsigned short lowertex;
unsigned short middletex;
unsigned short sector; unsigned short sector;
} msidedef_t; } msidedef_t;
@ -239,12 +252,10 @@ extern char loadname[];
qbyte doompalette[768]; qbyte doompalette[768];
static qboolean paletteloaded; static qboolean paletteloaded;
int Doom_LoadFlat(char *name) void Doom_LoadPalette(void)
{ {
char *file; char *file;
char texname[64];
int tex; int tex;
if (!paletteloaded) if (!paletteloaded)
{ {
paletteloaded = true; paletteloaded = true;
@ -264,6 +275,15 @@ int Doom_LoadFlat(char *name)
} }
} }
} }
}
int Doom_LoadFlat(char *name)
{
char *file;
char texname[64];
int tex;
Doom_LoadPalette();
sprintf(texname, "flat-%-.8s", name); sprintf(texname, "flat-%-.8s", name);
strlwr(texname); strlwr(texname);
@ -288,6 +308,42 @@ int Doom_LoadFlat(char *name)
return tex; return tex;
} }
static void GLR_DrawWall(unsigned short texnum, unsigned short s, unsigned short t, float x1, float y1, float frontfloor, float x2, float y2, float backfloor, qboolean unpegged)
{
gldoomtexture_t *tex = gldoomtextures+texnum;
float len = sqrt((x1-x2)*(x1-x2) + (y1-y2)*(y1-y2));
float s1, s2;
float t1, t2;
s1 = s/tex->width;
s2 = s1 + len/tex->width;
if (unpegged)
{
t2 = t/tex->height;
t1 = t2 - (backfloor-frontfloor)/tex->height;
}
else
{
t1 = t/tex->height;
t2 = t1 + (backfloor-frontfloor)/tex->height;
}
GL_Bind(tex->gltexture);
glBegin(GL_QUADS);
glTexCoord2f(s1, t2);
glVertex3f(x1, y1, frontfloor);
glTexCoord2f(s1, t1);
glVertex3f(x1, y1, backfloor);
glTexCoord2f(s2, t1);
glVertex3f(x2, y2, backfloor);
glTexCoord2f(s2, t2);
glVertex3f(x2, y2, frontfloor);
glEnd();
}
static void GLR_DrawSSector(unsigned int ssec) static void GLR_DrawSSector(unsigned int ssec)
{ {
short v0, v1; short v0, v1;
@ -321,17 +377,12 @@ static void GLR_DrawSSector(unsigned int ssec)
if (sec->floorheight < sec2->floorheight) if (sec->floorheight < sec2->floorheight)
{ {
GL_Bind(sidedefsm[sd].lowertex); GLR_DrawWall(sidedefsm[sd].lowertex,
glBegin(GL_QUADS); sidedefsm[ld->sidedef[1-segsl[seg].direction]].texx,
glTexCoord2f(0, 1); sidedefsm[ld->sidedef[1-segsl[seg].direction]].texy,
glVertex3f(vertexesl[v0].xpos, vertexesl[v0].ypos, sec->floorheight); vertexesl[v0].xpos, vertexesl[v0].ypos, sec->floorheight,
glTexCoord2f(0, 0); vertexesl[v1].xpos, vertexesl[v1].ypos, sec2->floorheight, ld->flags & LINEDEF_LOWERUNPEGGED);
glVertex3f(vertexesl[v0].xpos, vertexesl[v0].ypos, sec2->floorheight);
glTexCoord2f(1, 0);
glVertex3f(vertexesl[v1].xpos, vertexesl[v1].ypos, sec2->floorheight);
glTexCoord2f(1, 1);
glVertex3f(vertexesl[v1].xpos, vertexesl[v1].ypos, sec->floorheight);
glEnd();
c_brush_polys++; c_brush_polys++;
} }
@ -339,6 +390,14 @@ static void GLR_DrawSSector(unsigned int ssec)
{ {
// if (sec2->ceilingheight != sec2->floorheight) // if (sec2->ceilingheight != sec2->floorheight)
// sec2->floorheight = sec2->ceilingheight-32; // sec2->floorheight = sec2->ceilingheight-32;
GLR_DrawWall(sidedefsm[sd].uppertex,
sidedefsm[ld->sidedef[1-segsl[seg].direction]].texx,
sidedefsm[ld->sidedef[1-segsl[seg].direction]].texy,
vertexesl[v0].xpos, vertexesl[v0].ypos, sec2->ceilingheight,
vertexesl[v1].xpos, vertexesl[v1].ypos, sec->ceilingheight, ld->flags & LINEDEF_UPPERUNPEGGED);
/*
GL_Bind(sidedefsm[sd].uppertex); GL_Bind(sidedefsm[sd].uppertex);
glBegin(GL_QUADS); glBegin(GL_QUADS);
glTexCoord2f(0, 1); glTexCoord2f(0, 1);
@ -349,12 +408,18 @@ static void GLR_DrawSSector(unsigned int ssec)
glVertex3f(vertexesl[v1].xpos, vertexesl[v1].ypos, sec->ceilingheight); glVertex3f(vertexesl[v1].xpos, vertexesl[v1].ypos, sec->ceilingheight);
glTexCoord2f(1, 1); glTexCoord2f(1, 1);
glVertex3f(vertexesl[v1].xpos, vertexesl[v1].ypos, sec2->ceilingheight); glVertex3f(vertexesl[v1].xpos, vertexesl[v1].ypos, sec2->ceilingheight);
glEnd(); glEnd();*/
c_brush_polys++; c_brush_polys++;
} }
if (sidedefsm[sd].middletex) if (sidedefsm[sd].middletex)
{ {
GLR_DrawWall(sidedefsm[sd].middletex,
sidedefsm[ld->sidedef[segsl[seg].direction]].texx,
sidedefsm[ld->sidedef[segsl[seg].direction]].texy,
vertexesl[v1].xpos, vertexesl[v1].ypos, (sec2->ceilingheight < sec->ceilingheight)?sec2->ceilingheight:sec->ceilingheight,
vertexesl[v0].xpos, vertexesl[v0].ypos, (sec2->floorheight > sec->floorheight)?sec2->floorheight:sec->floorheight, false);
/*
GL_Bind(sidedefsm[sd].middletex); GL_Bind(sidedefsm[sd].middletex);
glBegin(GL_QUADS); glBegin(GL_QUADS);
if (sec2->ceilingheight < sec->ceilingheight) if (sec2->ceilingheight < sec->ceilingheight)
@ -386,11 +451,20 @@ static void GLR_DrawSSector(unsigned int ssec)
glVertex3f(vertexesl[v0].xpos, vertexesl[v0].ypos, sec->floorheight); glVertex3f(vertexesl[v0].xpos, vertexesl[v0].ypos, sec->floorheight);
} }
glEnd(); glEnd();
*/
c_brush_polys++; c_brush_polys++;
} }
} }
else else
{ //solid wall, draw full wall. { //solid wall, draw full wall.
GLR_DrawWall(sidedefsm[sd].middletex,
sidedefsm[ld->sidedef[segsl[seg].direction]].texx,
sidedefsm[ld->sidedef[segsl[seg].direction]].texy,
vertexesl[v0].xpos, vertexesl[v0].ypos, sec->floorheight,
vertexesl[v1].xpos, vertexesl[v1].ypos, sec->ceilingheight, false);
#if 0
GL_Bind(sidedefsm[sd].middletex); GL_Bind(sidedefsm[sd].middletex);
glBegin(GL_QUADS); glBegin(GL_QUADS);
/* if (ld->flags & LINEDEF_LOWERUNPEGGED) /* if (ld->flags & LINEDEF_LOWERUNPEGGED)
@ -416,6 +490,7 @@ static void GLR_DrawSSector(unsigned int ssec)
glVertex3f(vertexesl[v1].xpos, vertexesl[v1].ypos, sec->floorheight); glVertex3f(vertexesl[v1].xpos, vertexesl[v1].ypos, sec->floorheight);
} }
glEnd(); glEnd();
#endif
c_brush_polys++; c_brush_polys++;
} }
} }
@ -987,9 +1062,9 @@ static void Doom_ExtractPName(unsigned int *out, doomimage_t *di, int outwidth,
colpointers = (unsigned int*)(data+sizeof(doomimage_t)); colpointers = (unsigned int*)(data+sizeof(doomimage_t));
for (c = 0; c < di->width; c++) for (c = 0; c < di->width; c++)
{ {
if (c < 0) if (c+x < 0)
continue; continue;
if (c > outwidth) if (c+x >= outwidth)
break; break;
if (colpointers[c] >= com_filesize) if (colpointers[c] >= com_filesize)
@ -1003,11 +1078,19 @@ static void Doom_ExtractPName(unsigned int *out, doomimage_t *di, int outwidth,
rc = *coldata++; rc = *coldata++;
coldata++; coldata++; //one not drawn, on each side
fr+=y;
if (fr<0)
{
coldata -= fr; //plus
fr = 0;
}
if ((fr+rc) > outheight) if ((fr+rc) > outheight)
{ {
extra = rc - outheight - fr +1; extra = rc - (outheight - fr) +1;
rc = outheight - fr; rc = outheight - fr;
if (rc < 0) if (rc < 0)
break; break;
@ -1017,18 +1100,18 @@ static void Doom_ExtractPName(unsigned int *out, doomimage_t *di, int outwidth,
while(rc) while(rc)
{ {
out[c + fr*outwidth] = (gammatable[doompalette[*coldata*3]]) + (gammatable[doompalette[*coldata*3+1]]<<8) + (gammatable[doompalette[*coldata*3+2]]<<16); out[c+x + fr*outwidth] = (gammatable[doompalette[*coldata*3]]) + (gammatable[doompalette[*coldata*3+1]]<<8) + (gammatable[doompalette[*coldata*3+2]]<<16) + (255<<24);
coldata++; coldata++;
fr++; fr++;
rc--; rc--;
} }
coldata+=extra; coldata+=extra; //one not drawn, on each side
} }
} }
} }
static int Doom_LoadPatchFromTexWad(char *name, void *texlump) static int Doom_LoadPatchFromTexWad(char *name, void *texlump, unsigned short *width, unsigned short *height)
{ {
char patch[32] = "patches/"; char patch[32] = "patches/";
unsigned int *tex; unsigned int *tex;
@ -1046,6 +1129,9 @@ static int Doom_LoadPatchFromTexWad(char *name, void *texlump)
if (!strncmp(tx->name, name, 8)) if (!strncmp(tx->name, name, 8))
{ {
tex = BZ_Malloc(tx->width*tx->height*4); tex = BZ_Malloc(tx->width*tx->height*4);
memset(tex, 255, tx->width*tx->height*4);
*width = tx->width;
*height = tx->height;
tc = (ddoomtexturecomponant_t*)(tx+1); tc = (ddoomtexturecomponant_t*)(tx+1);
for (i = 0; i < tx->componantcount; i++, tc++) for (i = 0; i < tx->componantcount; i++, tc++)
{ {
@ -1069,20 +1155,40 @@ static int Doom_LoadPatchFromTexWad(char *name, void *texlump)
static int Doom_LoadPatch(char *name) static int Doom_LoadPatch(char *name)
{ {
int texnum; int texnum;
for (texnum = 0; texnum < numgldoomtextures; texnum++) //a hash table might be a good plan.
{
if(!strncmp(name, gldoomtextures[texnum].name, 8))
{
return texnum;
}
}
//couldn't find it.
// texnum = numgldoomtextures;
gldoomtextures = BZ_Realloc(gldoomtextures, sizeof(*gldoomtextures)*((numgldoomtextures+16)&~15));
numgldoomtextures++;
strncpy(gldoomtextures[texnum].name, name, 8);
if (textures1) if (textures1)
{ {
texnum = Doom_LoadPatchFromTexWad(name, textures1); gldoomtextures[texnum].gltexture = Doom_LoadPatchFromTexWad(name, textures1, &gldoomtextures[texnum].width, &gldoomtextures[texnum].height);
if (texnum) if (gldoomtextures[texnum].gltexture)
return texnum; return texnum;
} }
if (textures2) if (textures2)
{ {
texnum = Doom_LoadPatchFromTexWad(name, textures2); gldoomtextures[texnum].gltexture = Doom_LoadPatchFromTexWad(name, textures2, &gldoomtextures[texnum].width, &gldoomtextures[texnum].height);
if (texnum) if (gldoomtextures[texnum].gltexture)
return texnum; return texnum;
} }
//all else failed. //all else failed.
return Mod_LoadHiResTexture(name, true, false, true); gldoomtextures[texnum].gltexture = Mod_LoadHiResTexture(name, true, false, true);
gldoomtextures[texnum].width = image_width;
gldoomtextures[texnum].height = image_height;
return texnum;
} }
#endif #endif
static void CleanWalls(dsidedef_t *sidedefsl) static void CleanWalls(dsidedef_t *sidedefsl)
@ -1143,8 +1249,8 @@ static void CleanWalls(dsidedef_t *sidedefsl)
} }
#endif #endif
sidedefsm[i].sector = sidedefsl[i].sector; sidedefsm[i].sector = sidedefsl[i].sector;
sidedefsm[i].texx = sidedefsl[i].texx/64.0f; sidedefsm[i].texx = sidedefsl[i].texx;
sidedefsm[i].texy = sidedefsl[i].texy/64.0f; sidedefsm[i].texy = sidedefsl[i].texy;
} }
} }
@ -1503,6 +1609,10 @@ qboolean Mod_LoadDoomLevel(model_t *mod)
sectorl = (void *)COM_LoadMallocFile (va("%s.sectors", name)); sectorl = (void *)COM_LoadMallocFile (va("%s.sectors", name));
sectorc = com_filesize/sizeof(*sectorl); sectorc = com_filesize/sizeof(*sectorl);
numgldoomtextures=0;
Doom_LoadPalette();
Doom_LoadVerticies(name); Doom_LoadVerticies(name);
Doom_LoadSSegs(name); Doom_LoadSSegs(name);
@ -1630,7 +1740,7 @@ int Doom_PointContents(hull_t *hull, vec3_t p)
return FTECONTENTS_EMPTY; return FTECONTENTS_EMPTY;
} }
#define NEWTRACES //#define NEWTRACES
#ifdef NEWTRACES #ifdef NEWTRACES
static qboolean ispoint; static qboolean ispoint;
static void ClipToBlockMap(hull_t *hull, int block, vec3_t start, vec3_t end, trace_t *trace) static void ClipToBlockMap(hull_t *hull, int block, vec3_t start, vec3_t end, trace_t *trace)
@ -1642,6 +1752,12 @@ static void ClipToBlockMap(hull_t *hull, int block, vec3_t start, vec3_t end, tr
float d1, d2; //distance start, end float d1, d2; //distance start, end
if (block < 0 || block >= blockmapl->columns*blockmapl->rows)
{
trace->fraction = 0;
return;
}
trace->endpos[0] = end[0]; trace->endpos[0] = end[0];
trace->endpos[1] = end[1]; trace->endpos[1] = end[1];
@ -1679,6 +1795,15 @@ static void ClipToBlockMap(hull_t *hull, int block, vec3_t start, vec3_t end, tr
if (d1 < 0 && d2 < 0) if (d1 < 0 && d2 < 0)
continue; //both points on the back side. continue; //both points on the back side.
//line crossed plane
if (d1<0) //moved onto backside
{
LeaveSector(sidedefsm[ld->sidedef[0]].sector);
EnterSector(sidedefsm[ld->sidedef[1]].sector);
}
} }
} }