mirror of
https://git.code.sf.net/p/quake/newtree
synced 2024-11-10 06:42:26 +00:00
merge in knghtbrd's work, minus his over-bright stuff (it causes textures to
not be drawn when multitexture is not available (or at least I think that's the condition)). More specificly, his altered blend states.
This commit is contained in:
parent
acb5f4b21a
commit
18a9900b21
10 changed files with 259 additions and 731 deletions
|
@ -75,7 +75,6 @@ typedef void (GLAPIENTRY *PRIORTEXFUNCPTR)(GLsizei, const GLuint *,
|
|||
const GLclampf *);
|
||||
typedef void (GLAPIENTRY *TEXSUBIMAGEPTR)(int, int, int, int, int, int, int, int, void *);
|
||||
|
||||
extern BINDTEXFUNCPTR bindTexFunc;
|
||||
extern DELTEXFUNCPTR delTexFunc;
|
||||
extern TEXSUBIMAGEPTR TexSubImage2DFunc;
|
||||
|
||||
|
@ -176,8 +175,6 @@ extern texture_t *r_notexture_mip;
|
|||
extern int d_lightstylevalue[256]; // 8.8 fraction of base light value
|
||||
|
||||
extern qboolean envmap;
|
||||
extern int currenttexture;
|
||||
extern int cnttextures[2];
|
||||
extern int particletexture;
|
||||
extern int netgraphtexture; // netgraph texture
|
||||
extern int playertextures;
|
||||
|
@ -195,6 +192,7 @@ extern cvar_t *r_lightmap;
|
|||
extern cvar_t *r_shadows;
|
||||
extern cvar_t *r_mirroralpha;
|
||||
extern cvar_t *r_wateralpha;
|
||||
extern cvar_t *r_waterripple;
|
||||
extern cvar_t *r_dynamic;
|
||||
extern cvar_t *r_novis;
|
||||
extern cvar_t *r_netgraph;
|
||||
|
@ -233,7 +231,6 @@ extern const char *gl_version;
|
|||
extern const char *gl_extensions;
|
||||
|
||||
void R_TranslatePlayerSkin (int playernum);
|
||||
void GL_Bind (int texnum);
|
||||
|
||||
// Multitexture
|
||||
#define TEXTURE0_SGIS 0x835E
|
||||
|
@ -263,8 +260,7 @@ void EmitWaterPolys (msurface_t *fa);
|
|||
void EmitSkyPolys (msurface_t *fa);
|
||||
void R_DrawSkyChain (msurface_t *s);
|
||||
void R_LoadSkys (char *);
|
||||
void R_ClearSkyBox (void);
|
||||
void R_DrawSkyBox (void);
|
||||
void R_DrawSky (void);
|
||||
|
||||
//
|
||||
// gl_draw.c
|
||||
|
|
|
@ -36,6 +36,7 @@
|
|||
#include "console.h"
|
||||
#include "quakefs.h"
|
||||
#include "sound.h"
|
||||
#include "client.h"
|
||||
|
||||
#include <string.h>
|
||||
|
||||
|
@ -703,8 +704,9 @@ void Draw_ConsoleBackground (int lines)
|
|||
}
|
||||
}
|
||||
|
||||
Draw_AltString8 (vid.conwidth - strlen(cl_verstring->string)*8 - 11,
|
||||
lines-14, cl_verstring->string);
|
||||
if (!cls.download)
|
||||
Draw_AltString8 (vid.conwidth - strlen(cl_verstring->string)
|
||||
* 8 - 11, lines-14, cl_verstring->string);
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -122,20 +122,6 @@ typedef struct
|
|||
gltexture_t gltextures[MAX_GLTEXTURES];
|
||||
int numgltextures;
|
||||
|
||||
void GL_Bind (int texnum)
|
||||
{
|
||||
if (gl_nobind->value)
|
||||
texnum = char_texture;
|
||||
if (currenttexture == texnum)
|
||||
return;
|
||||
currenttexture = texnum;
|
||||
#ifdef _WIN32
|
||||
bindTexFunc (GL_TEXTURE_2D, texnum);
|
||||
#else
|
||||
glBindTexture (GL_TEXTURE_2D, texnum);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
=============================================================================
|
||||
|
@ -204,7 +190,7 @@ int scrap_uploads;
|
|||
void Scrap_Upload (void)
|
||||
{
|
||||
scrap_uploads++;
|
||||
GL_Bind(scrap_texnum);
|
||||
glBindTexture (GL_TEXTURE_2D, scrap_texnum);
|
||||
GL_Upload8 (scrap_texels[0], BLOCK_WIDTH, BLOCK_HEIGHT, false, true);
|
||||
scrap_dirty = false;
|
||||
}
|
||||
|
@ -376,9 +362,9 @@ void Draw_TextureMode_f (void)
|
|||
{
|
||||
if (glt->mipmap)
|
||||
{
|
||||
GL_Bind (glt->texnum);
|
||||
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, gl_filter_min);
|
||||
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, gl_filter_max);
|
||||
glBindTexture (GL_TEXTURE_2D, glt->texnum);
|
||||
glTexParameterf (GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, gl_filter_min);
|
||||
glTexParameterf (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, gl_filter_max);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -479,7 +465,7 @@ void Draw_Character8 (int x, int y, int num)
|
|||
fcol = col*0.0625;
|
||||
size = 0.0625;
|
||||
|
||||
GL_Bind (char_texture);
|
||||
glBindTexture (GL_TEXTURE_2D, char_texture);
|
||||
|
||||
glColor3f (0.5, 0.5, 0.5);
|
||||
glBegin (GL_QUADS);
|
||||
|
@ -536,7 +522,7 @@ void Draw_Crosshair(void)
|
|||
|
||||
pColor = (unsigned char *) &d_8to24table[(byte) crosshaircolor->value];
|
||||
glColor4ubv ( pColor );
|
||||
GL_Bind (cs_texture);
|
||||
glBindTexture (GL_TEXTURE_2D, cs_texture);
|
||||
|
||||
glBegin (GL_QUADS);
|
||||
glTexCoord2f (0, 0);
|
||||
|
@ -581,7 +567,7 @@ void Draw_Pic (int x, int y, qpic_t *pic)
|
|||
Scrap_Upload ();
|
||||
gl = (glpic_t *)pic->data;
|
||||
glColor3f (0.4, 0.4, 0.4);
|
||||
GL_Bind (gl->texnum);
|
||||
glBindTexture (GL_TEXTURE_2D, gl->texnum);
|
||||
glBegin (GL_QUADS);
|
||||
glTexCoord2f (gl->sl, gl->tl);
|
||||
glVertex2f (x, y);
|
||||
|
@ -607,7 +593,7 @@ void Draw_AlphaPic (int x, int y, qpic_t *pic, float alpha)
|
|||
Scrap_Upload ();
|
||||
gl = (glpic_t *)pic->data;
|
||||
glColor4f (0.4, 0.4, 0.4, alpha);
|
||||
GL_Bind (gl->texnum);
|
||||
glBindTexture (GL_TEXTURE_2D, gl->texnum);
|
||||
glBegin (GL_QUADS);
|
||||
glTexCoord2f (gl->sl, gl->tl);
|
||||
glVertex2f (x, y);
|
||||
|
@ -641,7 +627,7 @@ void Draw_SubPic(int x, int y, qpic_t *pic, int srcx, int srcy, int width, int h
|
|||
newth = newtl + (height*oldglheight)/pic->height;
|
||||
|
||||
glColor3f (0.4, 0.4, 0.4);
|
||||
GL_Bind (gl->texnum);
|
||||
glBindTexture (GL_TEXTURE_2D, gl->texnum);
|
||||
glBegin (GL_QUADS);
|
||||
glTexCoord2f (newsl, newtl);
|
||||
glVertex2f (x, y);
|
||||
|
@ -686,7 +672,7 @@ void Draw_TransPicTranslate (int x, int y, qpic_t *pic, byte *translation)
|
|||
byte *src;
|
||||
int p;
|
||||
|
||||
GL_Bind (translate_texture);
|
||||
glBindTexture (GL_TEXTURE_2D, translate_texture);
|
||||
|
||||
c = pic->width * pic->height;
|
||||
|
||||
|
@ -779,7 +765,7 @@ Draw_ConsoleBackground ( int lines )
|
|||
glColor4f (0.5, 0.5, 0.5, alpha);
|
||||
|
||||
// draw the console texture
|
||||
GL_Bind (gl->texnum);
|
||||
glBindTexture (GL_TEXTURE_2D, gl->texnum);
|
||||
glBegin (GL_QUADS);
|
||||
glTexCoord2f (gl->sl, gl->tl + ofs);
|
||||
glVertex2f (0, 0);
|
||||
|
@ -822,7 +808,7 @@ refresh window.
|
|||
void Draw_TileClear (int x, int y, int w, int h)
|
||||
{
|
||||
glColor3f (0.5, 0.5, 0.5);
|
||||
GL_Bind (*(int *)draw_backtile->data);
|
||||
glBindTexture (GL_TEXTURE_2D, *(int *)draw_backtile->data);
|
||||
glBegin (GL_QUADS);
|
||||
glTexCoord2f (x/64.0, y/64.0);
|
||||
glVertex2f (x, y);
|
||||
|
@ -1380,7 +1366,7 @@ SetupTexture:
|
|||
glt->height = height;
|
||||
glt->mipmap = mipmap;
|
||||
|
||||
GL_Bind(glt->texnum);
|
||||
glBindTexture (GL_TEXTURE_2D, glt->texnum);
|
||||
|
||||
GL_Upload8 (data, width, height, mipmap, alpha);
|
||||
|
||||
|
@ -1399,17 +1385,10 @@ int GL_LoadPicTexture (qpic_t *pic)
|
|||
|
||||
/****************************************/
|
||||
|
||||
static GLenum oldtarget = 0; // TEXTURE0_SGIS;
|
||||
|
||||
void GL_SelectTexture (GLenum target)
|
||||
{
|
||||
if (!gl_mtexable)
|
||||
return;
|
||||
qglSelectTexture (target + gl_mtex_enum);
|
||||
if (target == oldtarget)
|
||||
return;
|
||||
cnttextures[oldtarget] = currenttexture;
|
||||
currenttexture = cnttextures[target];
|
||||
oldtarget = target;
|
||||
}
|
||||
|
||||
|
|
|
@ -149,7 +149,7 @@ void R_NetGraph (void)
|
|||
Draw_String8 (8, y, st);
|
||||
y += 8;
|
||||
|
||||
GL_Bind(netgraphtexture);
|
||||
glBindTexture (GL_TEXTURE_2D, netgraphtexture);
|
||||
|
||||
glTexImage2D (GL_TEXTURE_2D, 0, gl_alpha_format,
|
||||
NET_TIMINGS, NET_GRAPHHEIGHT, 0, GL_RGBA,
|
||||
|
|
|
@ -494,7 +494,7 @@ void R_DrawParticles (void)
|
|||
float scale;
|
||||
qboolean alphaTestEnabled;
|
||||
|
||||
GL_Bind(particletexture);
|
||||
glBindTexture (GL_TEXTURE_2D, particletexture);
|
||||
alphaTestEnabled = glIsEnabled(GL_ALPHA_TEST);
|
||||
|
||||
if (alphaTestEnabled)
|
||||
|
|
|
@ -60,9 +60,6 @@ int c_brush_polys, c_alias_polys;
|
|||
|
||||
qboolean envmap; // true during envmap command capture
|
||||
|
||||
int currenttexture = -1; // to avoid unnecessary texture sets
|
||||
|
||||
int cnttextures[2] = {-1, -1}; // cached
|
||||
|
||||
int particletexture; // little dot for particles
|
||||
int playertextures; // up to 16 color translated skins
|
||||
|
@ -103,6 +100,7 @@ cvar_t *r_lightmap;
|
|||
cvar_t *r_shadows;
|
||||
cvar_t *r_mirroralpha;
|
||||
cvar_t *r_wateralpha;
|
||||
cvar_t *r_waterripple;
|
||||
cvar_t *r_dynamic;
|
||||
cvar_t *r_novis;
|
||||
cvar_t *r_netgraph;
|
||||
|
@ -292,7 +290,7 @@ void R_DrawSpriteModel (entity_t *e)
|
|||
|
||||
GL_DisableMultitexture();
|
||||
|
||||
GL_Bind(frame->gl_texturenum);
|
||||
glBindTexture (GL_TEXTURE_2D, frame->gl_texturenum);
|
||||
|
||||
glEnable (GL_ALPHA_TEST);
|
||||
glBegin (GL_QUADS);
|
||||
|
@ -364,8 +362,8 @@ void GL_DrawAliasFrame (aliashdr_t *paliashdr, int posenum)
|
|||
trivertx_t *verts;
|
||||
int *order;
|
||||
int count;
|
||||
|
||||
lastposenum = posenum;
|
||||
|
||||
lastposenum = posenum;
|
||||
|
||||
verts = (trivertx_t *)((byte *)paliashdr + paliashdr->posedata);
|
||||
verts += posenum * paliashdr->poseverts;
|
||||
|
@ -593,7 +591,7 @@ void R_DrawAliasModel (entity_t *e)
|
|||
|
||||
GL_DisableMultitexture();
|
||||
|
||||
glPushMatrix ();
|
||||
glPushMatrix ();
|
||||
R_RotateForEntity (e);
|
||||
|
||||
if (!strcmp (clmodel->name, "progs/eyes.mdl") ) {
|
||||
|
@ -606,7 +604,7 @@ void R_DrawAliasModel (entity_t *e)
|
|||
}
|
||||
|
||||
anim = (int)(cl.time*10) & 3;
|
||||
GL_Bind(paliashdr->gl_texturenum[currententity->skinnum][anim]);
|
||||
glBindTexture (GL_TEXTURE_2D, paliashdr->gl_texturenum[currententity->skinnum][anim]);
|
||||
|
||||
// we can't dynamically colormap textures, so they are cached
|
||||
// seperately for the players. Heads are just uncolored.
|
||||
|
@ -618,7 +616,7 @@ void R_DrawAliasModel (entity_t *e)
|
|||
R_TranslatePlayerSkin(i);
|
||||
}
|
||||
if (i >= 0 && i<MAX_CLIENTS)
|
||||
GL_Bind(playertextures + i);
|
||||
glBindTexture (GL_TEXTURE_2D, playertextures + i);
|
||||
}
|
||||
|
||||
if (gl_smoothmodels->value)
|
||||
|
|
|
@ -114,7 +114,7 @@ void R_InitParticleTexture (void)
|
|||
// particle texture
|
||||
//
|
||||
particletexture = texture_extension_number++;
|
||||
GL_Bind(particletexture);
|
||||
glBindTexture (GL_TEXTURE_2D, particletexture);
|
||||
|
||||
for (x=0 ; x<8 ; x++)
|
||||
{
|
||||
|
@ -238,6 +238,7 @@ void R_Init (void)
|
|||
r_shadows = Cvar_Get("r_shadows", "0", CVAR_NONE, "None");
|
||||
r_mirroralpha = Cvar_Get("r_mirroralpha", "1", CVAR_NONE, "None");
|
||||
r_wateralpha = Cvar_Get("r_wateralpha", "1", CVAR_NONE, "None");
|
||||
r_waterripple = Cvar_Get ("r_waterripple", "0", CVAR_NONE, "None");
|
||||
r_dynamic = Cvar_Get("r_dynamic", "1", CVAR_NONE, "None");
|
||||
r_novis = Cvar_Get("r_novis", "0", CVAR_NONE, "None");
|
||||
r_speeds = Cvar_Get("r_speeds", "0", CVAR_NONE, "None");
|
||||
|
@ -247,7 +248,7 @@ void R_Init (void)
|
|||
gl_texsort = Cvar_Get("gl_texsort", "1", CVAR_NONE, "None");
|
||||
|
||||
if (gl_mtexable)
|
||||
gl_texsort->value = 0.0;
|
||||
Cvar_SetValue(gl_texsort, 0.0);
|
||||
|
||||
gl_cull = Cvar_Get("gl_cull", "1", CVAR_NONE, "None");
|
||||
gl_smoothmodels = Cvar_Get("gl_smoothmodels", "1", CVAR_NONE, "None");
|
||||
|
@ -361,7 +362,7 @@ void R_TranslatePlayerSkin (int playernum)
|
|||
|
||||
// because this happens during gameplay, do it fast
|
||||
// instead of sending it through gl_upload 8
|
||||
GL_Bind(playertextures + playernum);
|
||||
glBindTexture (GL_TEXTURE_2D, playertextures + playernum);
|
||||
|
||||
#if 0
|
||||
s = 320*200;
|
||||
|
|
|
@ -75,7 +75,7 @@ cvar_t *gl_colorlights;
|
|||
#define BLOCK_WIDTH 128
|
||||
#define BLOCK_HEIGHT 128
|
||||
|
||||
#define MAX_LIGHTMAPS 256
|
||||
#define MAX_LIGHTMAPS 64
|
||||
int active_lightmaps;
|
||||
|
||||
typedef struct glRect_s {
|
||||
|
@ -336,9 +336,6 @@ extern int solidskytexture;
|
|||
extern int alphaskytexture;
|
||||
extern float speedscale; // for top sky and bottom sky
|
||||
|
||||
void DrawGLWaterPoly (glpoly_t *p);
|
||||
void DrawGLWaterPolyLightmap (glpoly_t *p);
|
||||
|
||||
lpMTexFUNC qglMTexCoord2f = NULL;
|
||||
lpSelTexFUNC qglSelectTexture = NULL;
|
||||
|
||||
|
@ -378,14 +375,13 @@ void R_DrawSequentialPoly (msurface_t *s)
|
|||
float *v;
|
||||
int i;
|
||||
texture_t *t;
|
||||
vec3_t nv;
|
||||
glRect_t *theRect;
|
||||
|
||||
//
|
||||
// normal lightmaped poly
|
||||
//
|
||||
|
||||
if (! (s->flags & (SURF_DRAWSKY|SURF_DRAWTURB|SURF_UNDERWATER) ) )
|
||||
if (!(s->flags & (SURF_DRAWSKY|SURF_DRAWTURB)))
|
||||
{
|
||||
R_RenderDynamicLightmaps (s);
|
||||
if (gl_mtexable)
|
||||
|
@ -395,11 +391,11 @@ void R_DrawSequentialPoly (msurface_t *s)
|
|||
t = R_TextureAnimation (s->texinfo->texture);
|
||||
// Binds world to texture env 0
|
||||
GL_SelectTexture(0);
|
||||
GL_Bind (t->gl_texturenum);
|
||||
glBindTexture (GL_TEXTURE_2D, t->gl_texturenum);
|
||||
// glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
|
||||
// Binds lightmap to texenv 1
|
||||
GL_EnableMultitexture(); // Same as SelectTexture (TEXTURE1)
|
||||
GL_Bind (lightmap_textures + s->lightmaptexturenum);
|
||||
glBindTexture (GL_TEXTURE_2D, lightmap_textures + s->lightmaptexturenum);
|
||||
i = s->lightmaptexturenum;
|
||||
if (lightmap_modified[i])
|
||||
{
|
||||
|
@ -414,6 +410,7 @@ void R_DrawSequentialPoly (msurface_t *s)
|
|||
theRect->w = 0;
|
||||
}
|
||||
glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
|
||||
|
||||
glBegin(GL_POLYGON);
|
||||
v = p->verts[0];
|
||||
for (i=0 ; i<p->numverts ; i++, v+= VERTEXSIZE)
|
||||
|
@ -428,22 +425,22 @@ void R_DrawSequentialPoly (msurface_t *s)
|
|||
p = s->polys;
|
||||
|
||||
t = R_TextureAnimation (s->texinfo->texture);
|
||||
GL_Bind (t->gl_texturenum);
|
||||
glBindTexture (GL_TEXTURE_2D, t->gl_texturenum);
|
||||
glBegin (GL_POLYGON);
|
||||
v = p->verts[0];
|
||||
for (i=0 ; i<p->numverts ; i++, v+= VERTEXSIZE)
|
||||
{
|
||||
glTexCoord2f (v[3], v[4]);
|
||||
glTexCoord2fv (&v[3]);
|
||||
glVertex3fv (v);
|
||||
}
|
||||
glEnd ();
|
||||
|
||||
GL_Bind (lightmap_textures + s->lightmaptexturenum);
|
||||
glBindTexture (GL_TEXTURE_2D, lightmap_textures + s->lightmaptexturenum);
|
||||
glBegin (GL_POLYGON);
|
||||
v = p->verts[0];
|
||||
for (i=0 ; i<p->numverts ; i++, v+= VERTEXSIZE)
|
||||
{
|
||||
glTexCoord2f (v[5], v[6]);
|
||||
glTexCoord2fv (&v[5]);
|
||||
glVertex3fv (v);
|
||||
}
|
||||
glEnd ();
|
||||
|
@ -457,139 +454,12 @@ void R_DrawSequentialPoly (msurface_t *s)
|
|||
|
||||
if (s->flags & SURF_DRAWTURB)
|
||||
{
|
||||
GL_DisableMultitexture();
|
||||
GL_Bind (s->texinfo->texture->gl_texturenum);
|
||||
EmitWaterPolys (s);
|
||||
return;
|
||||
}
|
||||
|
||||
//
|
||||
// subdivided sky warp
|
||||
//
|
||||
if (s->flags & SURF_DRAWSKY)
|
||||
{
|
||||
GL_DisableMultitexture();
|
||||
GL_Bind (solidskytexture);
|
||||
speedscale = realtime*8;
|
||||
speedscale -= (int)speedscale & ~127;
|
||||
|
||||
EmitSkyPolys (s);
|
||||
|
||||
GL_Bind (alphaskytexture);
|
||||
speedscale = realtime*16;
|
||||
speedscale -= (int)speedscale & ~127;
|
||||
EmitSkyPolys (s);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
//
|
||||
// underwater warped with lightmap
|
||||
//
|
||||
R_RenderDynamicLightmaps (s);
|
||||
if (gl_mtexable)
|
||||
{
|
||||
p = s->polys;
|
||||
|
||||
t = R_TextureAnimation (s->texinfo->texture);
|
||||
GL_SelectTexture(0);
|
||||
GL_Bind (t->gl_texturenum);
|
||||
GL_EnableMultitexture();
|
||||
GL_Bind (lightmap_textures + s->lightmaptexturenum);
|
||||
i = s->lightmaptexturenum;
|
||||
if (lightmap_modified[i])
|
||||
{
|
||||
lightmap_modified[i] = false;
|
||||
theRect = &lightmap_rectchange[i];
|
||||
glTexSubImage2D(GL_TEXTURE_2D, 0, 0, theRect->t,
|
||||
BLOCK_WIDTH, theRect->h, gl_lightmap_format, GL_UNSIGNED_BYTE,
|
||||
lightmaps+(i* BLOCK_HEIGHT + theRect->t) *BLOCK_WIDTH*lightmap_bytes);
|
||||
theRect->l = BLOCK_WIDTH;
|
||||
theRect->t = BLOCK_HEIGHT;
|
||||
theRect->h = 0;
|
||||
theRect->w = 0;
|
||||
}
|
||||
glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
|
||||
glBegin (GL_TRIANGLE_FAN);
|
||||
v = p->verts[0];
|
||||
for (i=0 ; i<p->numverts ; i++, v+= VERTEXSIZE)
|
||||
{
|
||||
qglMTexCoord2f (gl_mtex_enum + 0, v[3], v[4]);
|
||||
qglMTexCoord2f (gl_mtex_enum + 1, v[5], v[6]);
|
||||
|
||||
nv[0] = v[0] + 8*sin(v[1]*0.05+realtime)*sin(v[2]*0.05+realtime);
|
||||
nv[1] = v[1] + 8*sin(v[0]*0.05+realtime)*sin(v[2]*0.05+realtime);
|
||||
nv[2] = v[2];
|
||||
|
||||
glVertex3fv (nv);
|
||||
}
|
||||
glEnd ();
|
||||
} else {
|
||||
p = s->polys;
|
||||
|
||||
t = R_TextureAnimation (s->texinfo->texture);
|
||||
GL_Bind (t->gl_texturenum);
|
||||
DrawGLWaterPoly (p);
|
||||
|
||||
GL_Bind (lightmap_textures + s->lightmaptexturenum);
|
||||
DrawGLWaterPolyLightmap (p);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
================
|
||||
DrawGLWaterPoly
|
||||
|
||||
Warp the vertex coordinates
|
||||
================
|
||||
*/
|
||||
void DrawGLWaterPoly (glpoly_t *p)
|
||||
{
|
||||
int i;
|
||||
float *v;
|
||||
vec3_t nv;
|
||||
|
||||
GL_DisableMultitexture();
|
||||
|
||||
glBegin (GL_TRIANGLE_FAN);
|
||||
v = p->verts[0];
|
||||
for (i=0 ; i<p->numverts ; i++, v+= VERTEXSIZE)
|
||||
{
|
||||
glTexCoord2f (v[3], v[4]);
|
||||
|
||||
nv[0] = v[0] + 8*sin(v[1]*0.05+realtime)*sin(v[2]*0.05+realtime);
|
||||
nv[1] = v[1] + 8*sin(v[0]*0.05+realtime)*sin(v[2]*0.05+realtime);
|
||||
nv[2] = v[2];
|
||||
|
||||
glVertex3fv (nv);
|
||||
}
|
||||
glEnd ();
|
||||
}
|
||||
|
||||
void DrawGLWaterPolyLightmap (glpoly_t *p)
|
||||
{
|
||||
int i;
|
||||
float *v;
|
||||
vec3_t nv;
|
||||
|
||||
GL_DisableMultitexture();
|
||||
|
||||
glBegin (GL_TRIANGLE_FAN);
|
||||
v = p->verts[0];
|
||||
for (i=0 ; i<p->numverts ; i++, v+= VERTEXSIZE)
|
||||
{
|
||||
glTexCoord2f (v[5], v[6]);
|
||||
|
||||
nv[0] = v[0] + 8*sin(v[1]*0.05+realtime)*sin(v[2]*0.05+realtime);
|
||||
nv[1] = v[1] + 8*sin(v[0]*0.05+realtime)*sin(v[2]*0.05+realtime);
|
||||
nv[2] = v[2];
|
||||
|
||||
glVertex3fv (nv);
|
||||
}
|
||||
glEnd ();
|
||||
}
|
||||
|
||||
/*
|
||||
================
|
||||
DrawGLPoly
|
||||
|
@ -604,7 +474,7 @@ void DrawGLPoly (glpoly_t *p)
|
|||
v = p->verts[0];
|
||||
for (i=0 ; i<p->numverts ; i++, v+= VERTEXSIZE)
|
||||
{
|
||||
glTexCoord2f (v[3], v[4]);
|
||||
glTexCoord2fv (&v[3]);
|
||||
glVertex3fv (v);
|
||||
}
|
||||
glEnd ();
|
||||
|
@ -635,21 +505,11 @@ void R_BlendLightmaps (void)
|
|||
p = lightmap_polys[i];
|
||||
if (!p)
|
||||
continue;
|
||||
GL_Bind(lightmap_textures+i);
|
||||
glBindTexture (GL_TEXTURE_2D, lightmap_textures+i);
|
||||
if (lightmap_modified[i])
|
||||
{
|
||||
lightmap_modified[i] = false;
|
||||
theRect = &lightmap_rectchange[i];
|
||||
// theRect->l = 0;
|
||||
// theRect->t = 0;
|
||||
// theRect->w = BLOCK_WIDTH;
|
||||
// theRect->h = BLOCK_HEIGHT;
|
||||
// glTexImage2D (GL_TEXTURE_2D, 0, lightmap_bytes
|
||||
// , BLOCK_WIDTH, BLOCK_HEIGHT, 0,
|
||||
// gl_lightmap_format, GL_UNSIGNED_BYTE, lightmaps+i*BLOCK_WIDTH*BLOCK_HEIGHT*lightmap_bytes);
|
||||
// glTexImage2D (GL_TEXTURE_2D, 0, lightmap_bytes
|
||||
// , BLOCK_WIDTH, theRect->h, 0,
|
||||
// gl_lightmap_format, GL_UNSIGNED_BYTE, lightmaps+(i*BLOCK_HEIGHT+theRect->t)*BLOCK_WIDTH*lightmap_bytes);
|
||||
glTexSubImage2D(GL_TEXTURE_2D, 0, 0, theRect->t,
|
||||
BLOCK_WIDTH, theRect->h, gl_lightmap_format, GL_UNSIGNED_BYTE,
|
||||
lightmaps+(i* BLOCK_HEIGHT + theRect->t) *BLOCK_WIDTH*lightmap_bytes);
|
||||
|
@ -660,23 +520,14 @@ void R_BlendLightmaps (void)
|
|||
}
|
||||
for ( ; p ; p=p->chain)
|
||||
{
|
||||
// if (p->flags & SURF_UNDERWATER)
|
||||
// DrawGLWaterPolyLightmap (p);
|
||||
if (((r_viewleaf->contents==CONTENTS_EMPTY && (p->flags & SURF_UNDERWATER)) ||
|
||||
(r_viewleaf->contents!=CONTENTS_EMPTY && !(p->flags & SURF_UNDERWATER)))
|
||||
&& !(p->flags & SURF_DONTWARP))
|
||||
DrawGLWaterPolyLightmap (p);
|
||||
else
|
||||
glBegin (GL_POLYGON);
|
||||
v = p->verts[0];
|
||||
for (j=0 ; j<p->numverts ; j++, v+= VERTEXSIZE)
|
||||
{
|
||||
glBegin (GL_POLYGON);
|
||||
v = p->verts[0];
|
||||
for (j=0 ; j<p->numverts ; j++, v+= VERTEXSIZE)
|
||||
{
|
||||
glTexCoord2f (v[5], v[6]);
|
||||
glVertex3fv (v);
|
||||
}
|
||||
glEnd ();
|
||||
glTexCoord2fv (&v[5]);
|
||||
glVertex3fv (v);
|
||||
}
|
||||
glEnd ();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -703,12 +554,12 @@ void R_RenderBrushPoly (msurface_t *fa)
|
|||
|
||||
if (fa->flags & SURF_DRAWSKY)
|
||||
{ // warp texture, no lightmaps
|
||||
EmitBothSkyLayers (fa);
|
||||
// EmitBothSkyLayers (fa);
|
||||
return;
|
||||
}
|
||||
|
||||
t = R_TextureAnimation (fa->texinfo->texture);
|
||||
GL_Bind (t->gl_texturenum);
|
||||
glBindTexture (GL_TEXTURE_2D, t->gl_texturenum);
|
||||
|
||||
if (fa->flags & SURF_DRAWTURB)
|
||||
{ // warp texture, no lightmaps
|
||||
|
@ -716,12 +567,7 @@ void R_RenderBrushPoly (msurface_t *fa)
|
|||
return;
|
||||
}
|
||||
|
||||
if (((r_viewleaf->contents==CONTENTS_EMPTY && (fa->flags & SURF_UNDERWATER)) ||
|
||||
(r_viewleaf->contents!=CONTENTS_EMPTY && !(fa->flags & SURF_UNDERWATER)))
|
||||
&& !(fa->flags & SURF_DONTWARP))
|
||||
DrawGLWaterPoly (fa->polys);
|
||||
else
|
||||
DrawGLPoly (fa->polys);
|
||||
DrawGLPoly (fa->polys);
|
||||
|
||||
// add the poly to the proper lightmap chain
|
||||
|
||||
|
@ -855,7 +701,7 @@ void R_DrawWaterSurfaces (void)
|
|||
// go back to the world matrix
|
||||
//
|
||||
|
||||
glLoadMatrixf (r_world_matrix);
|
||||
glLoadMatrixf (r_world_matrix);
|
||||
|
||||
if (r_wateralpha->value < 1.0) {
|
||||
glColor4f (0.5, 0.5, 0.5, r_wateralpha->value);
|
||||
|
@ -868,7 +714,7 @@ void R_DrawWaterSurfaces (void)
|
|||
return;
|
||||
|
||||
for ( s = waterchain ; s ; s=s->texturechain) {
|
||||
GL_Bind (s->texinfo->texture->gl_texturenum);
|
||||
glBindTexture (GL_TEXTURE_2D, s->texinfo->texture->gl_texturenum);
|
||||
EmitWaterPolys (s);
|
||||
}
|
||||
|
||||
|
@ -888,7 +734,7 @@ void R_DrawWaterSurfaces (void)
|
|||
|
||||
// set modulate mode explicitly
|
||||
|
||||
GL_Bind (t->gl_texturenum);
|
||||
glBindTexture (GL_TEXTURE_2D, t->gl_texturenum);
|
||||
|
||||
for ( ; s ; s=s->texturechain)
|
||||
EmitWaterPolys (s);
|
||||
|
@ -919,7 +765,6 @@ void DrawTextureChains (void)
|
|||
|
||||
if (skychain)
|
||||
{
|
||||
R_DrawSkyChain(skychain);
|
||||
skychain = NULL;
|
||||
}
|
||||
|
||||
|
@ -934,17 +779,17 @@ void DrawTextureChains (void)
|
|||
s = t->texturechain;
|
||||
if (!s)
|
||||
continue;
|
||||
if (i == skytexturenum)
|
||||
/* if (i == skytexturenum)
|
||||
R_DrawSkyChain (s);
|
||||
else if (i == mirrortexturenum && r_mirroralpha->value != 1.0)
|
||||
else*/ if (i == mirrortexturenum && r_mirroralpha->value != 1.0)
|
||||
{
|
||||
R_MirrorChain (s);
|
||||
continue;
|
||||
}
|
||||
else
|
||||
{
|
||||
if ((s->flags & SURF_DRAWTURB) && r_wateralpha->value != 1.0)
|
||||
continue; // draw translucent water later
|
||||
// if ((s->flags & SURF_DRAWTURB) && r_wateralpha->value != 1.0)
|
||||
// continue; // draw translucent water later
|
||||
for ( ; s ; s=s->texturechain)
|
||||
R_RenderBrushPoly (s);
|
||||
}
|
||||
|
@ -970,7 +815,6 @@ void R_DrawBrushModel (entity_t *e)
|
|||
qboolean rotated;
|
||||
|
||||
currententity = e;
|
||||
currenttexture = -1;
|
||||
|
||||
clmodel = e->model;
|
||||
|
||||
|
@ -1131,10 +975,7 @@ void R_RecursiveWorldNode (mnode_t *node)
|
|||
break;
|
||||
}
|
||||
|
||||
if (dot >= 0)
|
||||
side = 0;
|
||||
else
|
||||
side = 1;
|
||||
side = dot < 0;
|
||||
|
||||
// recurse down the children, front side first
|
||||
R_RecursiveWorldNode (node->children[side]);
|
||||
|
@ -1150,41 +991,33 @@ void R_RecursiveWorldNode (mnode_t *node)
|
|||
side = SURF_PLANEBACK;
|
||||
else if (dot > BACKFACE_EPSILON)
|
||||
side = 0;
|
||||
for ( ; c ; c--, surf++)
|
||||
{
|
||||
for ( ; c ; c--, surf++)
|
||||
if (surf->visframe != r_framecount)
|
||||
continue;
|
||||
|
||||
// don't backface underwater surfaces, because they warp
|
||||
if ((dot < 0) ^ !!(surf->flags & SURF_PLANEBACK))
|
||||
continue; // wrong side
|
||||
|
||||
// if sorting by texture, just store it out
|
||||
if (gl_texsort->value)
|
||||
{
|
||||
if (surf->visframe != r_framecount)
|
||||
continue;
|
||||
|
||||
// don't backface underwater surfaces, because they warp
|
||||
// if ( !(surf->flags & SURF_UNDERWATER) && ( (dot < 0) ^ !!(surf->flags & SURF_PLANEBACK)) )
|
||||
// continue; // wrong side
|
||||
if ( !(((r_viewleaf->contents==CONTENTS_EMPTY && (surf->flags & SURF_UNDERWATER)) ||
|
||||
(r_viewleaf->contents!=CONTENTS_EMPTY && !(surf->flags & SURF_UNDERWATER)))
|
||||
&& !(surf->flags & SURF_DONTWARP)) && ( (dot < 0) ^ !!(surf->flags & SURF_PLANEBACK)) )
|
||||
continue; // wrong side
|
||||
|
||||
// if sorting by texture, just store it out
|
||||
if (gl_texsort->value)
|
||||
if (!mirror
|
||||
|| surf->texinfo->texture != cl.worldmodel->textures[mirrortexturenum])
|
||||
{
|
||||
if (!mirror
|
||||
|| surf->texinfo->texture != cl.worldmodel->textures[mirrortexturenum])
|
||||
{
|
||||
surf->texturechain = surf->texinfo->texture->texturechain;
|
||||
surf->texinfo->texture->texturechain = surf;
|
||||
}
|
||||
} else if (surf->flags & SURF_DRAWSKY) {
|
||||
surf->texturechain = skychain;
|
||||
skychain = surf;
|
||||
} else if (surf->flags & SURF_DRAWTURB) {
|
||||
surf->texturechain = waterchain;
|
||||
waterchain = surf;
|
||||
} else
|
||||
R_DrawSequentialPoly (surf);
|
||||
|
||||
surf->texturechain = surf->texinfo->texture->texturechain;
|
||||
surf->texinfo->texture->texturechain = surf;
|
||||
}
|
||||
} else if (surf->flags & SURF_DRAWSKY) {
|
||||
surf->texturechain = skychain;
|
||||
skychain = surf;
|
||||
} else if (surf->flags & SURF_DRAWTURB) {
|
||||
surf->texturechain = waterchain;
|
||||
waterchain = surf;
|
||||
} else
|
||||
R_DrawSequentialPoly (surf);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// recurse down the back side
|
||||
|
@ -1208,26 +1041,17 @@ void R_DrawWorld (void)
|
|||
VectorCopy (r_refdef.vieworg, modelorg);
|
||||
|
||||
currententity = &ent;
|
||||
currenttexture = -1;
|
||||
|
||||
glColor3f (1.0, 1.0, 1.0);
|
||||
memset (lightmap_polys, 0, sizeof(lightmap_polys));
|
||||
// Be sure to clear the skybox --KB
|
||||
R_ClearSkyBox ();
|
||||
R_DrawSky ();
|
||||
|
||||
R_RecursiveWorldNode (cl.worldmodel->nodes);
|
||||
|
||||
DrawTextureChains ();
|
||||
|
||||
R_BlendLightmaps ();
|
||||
|
||||
// Adjust the depth range and draw the skybox, ensuring it's behind
|
||||
// everhting else. This fixes the problem where some things are
|
||||
// drawn as sky when something else should be drawn. --KB
|
||||
glColor3f (0.5, 0.5, 0.5);
|
||||
glDepthRange (gldepthmax, gldepthmax);
|
||||
R_DrawSkyBox ();
|
||||
glDepthRange (gldepthmin, gldepthmax);
|
||||
}
|
||||
|
||||
|
||||
|
@ -1543,7 +1367,7 @@ void GL_BuildLightmaps (void)
|
|||
lightmap_rectchange[i].t = BLOCK_HEIGHT;
|
||||
lightmap_rectchange[i].w = 0;
|
||||
lightmap_rectchange[i].h = 0;
|
||||
GL_Bind(lightmap_textures + i);
|
||||
glBindTexture (GL_TEXTURE_2D, lightmap_textures + i);
|
||||
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
||||
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
||||
glTexImage2D (GL_TEXTURE_2D, 0, lightmap_bytes, BLOCK_WIDTH,
|
||||
|
|
568
source/gl_warp.c
568
source/gl_warp.c
|
@ -223,7 +223,7 @@ void EmitWaterPolys (msurface_t *fa)
|
|||
float *v;
|
||||
int i;
|
||||
float s, t, os, ot;
|
||||
|
||||
vec3_t nv;
|
||||
|
||||
for (p=fa->polys ; p ; p=p->next)
|
||||
{
|
||||
|
@ -240,80 +240,20 @@ void EmitWaterPolys (msurface_t *fa)
|
|||
t *= (1.0/64);
|
||||
|
||||
glTexCoord2f (s, t);
|
||||
glVertex3fv (v);
|
||||
|
||||
VectorCopy (v, nv);
|
||||
nv[2] += r_waterripple->value
|
||||
* turbsin[(int)((v[3]*0.125+realtime) * TURBSCALE) & 255]
|
||||
* turbsin[(int)((v[4]*0.125+realtime) * TURBSCALE) & 255]
|
||||
* (1.0 / 64.0);
|
||||
|
||||
glVertex3fv (nv);
|
||||
}
|
||||
glEnd ();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/*
|
||||
=============
|
||||
EmitSkyPolys
|
||||
=============
|
||||
*/
|
||||
void EmitSkyPolys (msurface_t *fa)
|
||||
{
|
||||
glpoly_t *p;
|
||||
float *v;
|
||||
int i;
|
||||
float s, t;
|
||||
vec3_t dir;
|
||||
float length;
|
||||
|
||||
for (p=fa->polys ; p ; p=p->next)
|
||||
{
|
||||
glBegin (GL_POLYGON);
|
||||
for (i=0,v=p->verts[0] ; i<p->numverts ; i++, v+=VERTEXSIZE)
|
||||
{
|
||||
VectorSubtract (v, r_origin, dir);
|
||||
dir[2] *= 3; // flatten the sphere
|
||||
|
||||
length = dir[0]*dir[0] + dir[1]*dir[1] + dir[2]*dir[2];
|
||||
length = sqrt (length);
|
||||
length = 6*63/length;
|
||||
|
||||
dir[0] *= length;
|
||||
dir[1] *= length;
|
||||
|
||||
s = (speedscale + dir[0]) * (1.0/128);
|
||||
t = (speedscale + dir[1]) * (1.0/128);
|
||||
|
||||
glTexCoord2f (s, t);
|
||||
glVertex3fv (v);
|
||||
}
|
||||
glEnd ();
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
===============
|
||||
EmitBothSkyLayers
|
||||
|
||||
Does a sky warp on the pre-fragmented glpoly_t chain
|
||||
This will be called for brushmodels, the world
|
||||
will have them chained together.
|
||||
===============
|
||||
*/
|
||||
void EmitBothSkyLayers (msurface_t *fa)
|
||||
{
|
||||
GL_DisableMultitexture();
|
||||
|
||||
GL_Bind (solidskytexture);
|
||||
speedscale = realtime*8;
|
||||
speedscale -= (int)speedscale & ~127 ;
|
||||
|
||||
EmitSkyPolys (fa);
|
||||
|
||||
GL_Bind (alphaskytexture);
|
||||
speedscale = realtime*16;
|
||||
speedscale -= (int)speedscale & ~127 ;
|
||||
|
||||
EmitSkyPolys (fa);
|
||||
}
|
||||
|
||||
/*
|
||||
=================================================================
|
||||
|
||||
|
@ -620,7 +560,7 @@ void R_LoadSkys (char * skyname)
|
|||
skyloaded = true;
|
||||
for (i=0 ; i<6 ; i++)
|
||||
{
|
||||
GL_Bind (SKY_TEX + i);
|
||||
glBindTexture (GL_TEXTURE_2D, SKY_TEX + i);
|
||||
snprintf (name, sizeof(name),"env/%s%s.tga", skyname, suf[i]);
|
||||
COM_FOpenFile (name, &f);
|
||||
if (!f)
|
||||
|
@ -630,13 +570,10 @@ void R_LoadSkys (char * skyname)
|
|||
continue;
|
||||
}
|
||||
LoadTGA (f);
|
||||
// LoadPCX (f);
|
||||
|
||||
glTexImage2D (GL_TEXTURE_2D, 0, gl_solid_format, 256, 256, 0, GL_RGBA, GL_UNSIGNED_BYTE, targa_rgba);
|
||||
// glTexImage2D (GL_TEXTURE_2D, 0, gl_solid_format, 256, 256, 0, GL_RGBA, GL_UNSIGNED_BYTE, pcx_rgb);
|
||||
|
||||
free (targa_rgba);
|
||||
// free (pcx_rgb);
|
||||
|
||||
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
||||
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
||||
|
@ -646,353 +583,188 @@ void R_LoadSkys (char * skyname)
|
|||
skyname);
|
||||
}
|
||||
|
||||
|
||||
vec3_t skyclip[6] = {
|
||||
{1,1,0},
|
||||
{1,-1,0},
|
||||
{0,-1,1},
|
||||
{0,1,1},
|
||||
{1,0,1},
|
||||
{-1,0,1}
|
||||
};
|
||||
int c_sky;
|
||||
|
||||
// 1 = s, 2 = t, 3 = 2048
|
||||
int st_to_vec[6][3] =
|
||||
void
|
||||
R_SkyBoxPolyVec(vec5_t v)
|
||||
{
|
||||
{3,-1,2},
|
||||
{-3,1,2},
|
||||
// avoid interpolation seams
|
||||
// s = s * (254.0/256.0) + (1.0/256.0);
|
||||
// t = t * (254.0/256.0) + (1.0/256.0);
|
||||
glTexCoord2fv (v);
|
||||
glVertex3f (r_refdef.vieworg[0] + v[2],
|
||||
r_refdef.vieworg[1] + v[3],
|
||||
r_refdef.vieworg[2] + v[4]);
|
||||
}
|
||||
|
||||
{1,3,2},
|
||||
{-1,-3,2},
|
||||
#define ftc(x) (x * (254.0/256.0) + (1.0/256.0))
|
||||
|
||||
{-2,-1,3}, // 0 degrees yaw, look straight up
|
||||
{2,-1,-3} // look straight down
|
||||
|
||||
// {-1,2,3},
|
||||
// {1,2,-3}
|
||||
vec5_t skyvec[6][4] = {
|
||||
{
|
||||
// right
|
||||
{ftc(1), ftc(0), 1024, 1024, 1024},
|
||||
{ftc(1), ftc(1), 1024, 1024, -1024},
|
||||
{ftc(0), ftc(1), -1024, 1024, -1024},
|
||||
{ftc(0), ftc(0), -1024, 1024, 1024}
|
||||
},
|
||||
{
|
||||
// back
|
||||
{ftc(1), ftc(0), -1024, 1024, 1024},
|
||||
{ftc(1), ftc(1), -1024, 1024, -1024},
|
||||
{ftc(0), ftc(1), -1024, -1024, -1024},
|
||||
{ftc(0), ftc(0), -1024, -1024, 1024}
|
||||
},
|
||||
{
|
||||
// left
|
||||
{ftc(1), ftc(0), -1024, -1024, 1024},
|
||||
{ftc(1), ftc(1), -1024, -1024, -1024},
|
||||
{ftc(0), ftc(1), 1024, -1024, -1024},
|
||||
{ftc(0), ftc(0), 1024, -1024, 1024}
|
||||
},
|
||||
{
|
||||
// front
|
||||
{ftc(1), ftc(0), 1024, -1024, 1024},
|
||||
{ftc(1), ftc(1), 1024, -1024, -1024},
|
||||
{ftc(0), ftc(1), 1024, 1024, -1024},
|
||||
{ftc(0), ftc(0), 1024, 1024, 1024}
|
||||
},
|
||||
{
|
||||
// up
|
||||
{ftc(1), ftc(0), 1024, -1024, 1024},
|
||||
{ftc(1), ftc(1), 1024, 1024, 1024},
|
||||
{ftc(0), ftc(1), -1024, 1024, 1024},
|
||||
{ftc(0), ftc(0), -1024, -1024, 1024}
|
||||
},
|
||||
{
|
||||
// down
|
||||
{ftc(1), ftc(0), 1024, 1024, -1024},
|
||||
{ftc(1), ftc(1), 1024, -1024, -1024},
|
||||
{ftc(0), ftc(1), -1024, -1024, -1024},
|
||||
{ftc(0), ftc(0), -1024, 1024, -1024}
|
||||
}
|
||||
};
|
||||
|
||||
// s = [0]/[2], t = [1]/[2]
|
||||
int vec_to_st[6][3] =
|
||||
#undef ftc
|
||||
|
||||
void
|
||||
R_DrawSkyBox (void)
|
||||
{
|
||||
{-2,3,1},
|
||||
{2,3,-1},
|
||||
int i, j;
|
||||
|
||||
{1,3,2},
|
||||
{-1,3,-2},
|
||||
GL_DisableMultitexture ();
|
||||
glEnable (GL_DEPTH_TEST);
|
||||
glDepthFunc (GL_ALWAYS);
|
||||
// glDisable (GL_BLEND);
|
||||
// glTexEnvf (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
|
||||
glDepthRange (gldepthmax, gldepthmax);
|
||||
glColor3f (0.5, 0.5, 0.5);
|
||||
|
||||
{-2,-1,3},
|
||||
{-2,1,-3}
|
||||
|
||||
// {-1,2,3},
|
||||
// {1,2,-3}
|
||||
};
|
||||
|
||||
float skymins[2][6], skymaxs[2][6];
|
||||
|
||||
void DrawSkyPolygon (int nump, vec3_t vecs)
|
||||
{
|
||||
int i,j;
|
||||
vec3_t v, av;
|
||||
float s, t, dv;
|
||||
int axis;
|
||||
float *vp;
|
||||
|
||||
c_sky++;
|
||||
// decide which face it maps to
|
||||
VectorCopy (vec3_origin, v);
|
||||
for (i=0, vp=vecs ; i<nump ; i++, vp+=3)
|
||||
for (i = 0; i < 6; i++)
|
||||
{
|
||||
VectorAdd (vp, v, v);
|
||||
}
|
||||
av[0] = fabs(v[0]);
|
||||
av[1] = fabs(v[1]);
|
||||
av[2] = fabs(v[2]);
|
||||
if (av[0] > av[1] && av[0] > av[2])
|
||||
{
|
||||
if (v[0] < 0)
|
||||
axis = 1;
|
||||
else
|
||||
axis = 0;
|
||||
}
|
||||
else if (av[1] > av[2] && av[1] > av[0])
|
||||
{
|
||||
if (v[1] < 0)
|
||||
axis = 3;
|
||||
else
|
||||
axis = 2;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (v[2] < 0)
|
||||
axis = 5;
|
||||
else
|
||||
axis = 4;
|
||||
glBindTexture(GL_TEXTURE_2D, SKY_TEX + i);
|
||||
glBegin(GL_QUADS);
|
||||
for (j = 0; j < 4; j++)
|
||||
R_SkyBoxPolyVec(skyvec[i][j]);
|
||||
glEnd();
|
||||
}
|
||||
|
||||
// project new texture coords
|
||||
for (i=0 ; i<nump ; i++, vecs+=3)
|
||||
{
|
||||
j = vec_to_st[axis][2];
|
||||
if (j > 0)
|
||||
dv = vecs[j - 1];
|
||||
else
|
||||
dv = -vecs[-j - 1];
|
||||
|
||||
j = vec_to_st[axis][0];
|
||||
if (j < 0)
|
||||
s = -vecs[-j -1] / dv;
|
||||
else
|
||||
s = vecs[j-1] / dv;
|
||||
j = vec_to_st[axis][1];
|
||||
if (j < 0)
|
||||
t = -vecs[-j -1] / dv;
|
||||
else
|
||||
t = vecs[j-1] / dv;
|
||||
|
||||
if (s < skymins[0][axis])
|
||||
skymins[0][axis] = s;
|
||||
if (t < skymins[1][axis])
|
||||
skymins[1][axis] = t;
|
||||
if (s > skymaxs[0][axis])
|
||||
skymaxs[0][axis] = s;
|
||||
if (t > skymaxs[1][axis])
|
||||
skymaxs[1][axis] = t;
|
||||
}
|
||||
}
|
||||
|
||||
#define MAX_CLIP_VERTS 64
|
||||
void ClipSkyPolygon (int nump, vec3_t vecs, int stage)
|
||||
{
|
||||
float *norm;
|
||||
float *v;
|
||||
qboolean front, back;
|
||||
float d, e;
|
||||
float dists[MAX_CLIP_VERTS];
|
||||
int sides[MAX_CLIP_VERTS];
|
||||
vec3_t newv[2][MAX_CLIP_VERTS];
|
||||
int newc[2];
|
||||
int i, j;
|
||||
|
||||
if (nump > MAX_CLIP_VERTS-2)
|
||||
Sys_Error ("ClipSkyPolygon: MAX_CLIP_VERTS");
|
||||
if (stage == 6)
|
||||
{ // fully clipped, so draw it
|
||||
DrawSkyPolygon (nump, vecs);
|
||||
return;
|
||||
}
|
||||
|
||||
front = back = false;
|
||||
norm = skyclip[stage];
|
||||
for (i=0, v = vecs ; i<nump ; i++, v+=3)
|
||||
{
|
||||
d = DotProduct (v, norm);
|
||||
if (d > ON_EPSILON)
|
||||
{
|
||||
front = true;
|
||||
sides[i] = SIDE_FRONT;
|
||||
}
|
||||
else if (d < ON_EPSILON)
|
||||
{
|
||||
back = true;
|
||||
sides[i] = SIDE_BACK;
|
||||
}
|
||||
else
|
||||
sides[i] = SIDE_ON;
|
||||
dists[i] = d;
|
||||
}
|
||||
|
||||
if (!front || !back)
|
||||
{ // not clipped
|
||||
ClipSkyPolygon (nump, vecs, stage+1);
|
||||
return;
|
||||
}
|
||||
|
||||
// clip it
|
||||
sides[i] = sides[0];
|
||||
dists[i] = dists[0];
|
||||
VectorCopy (vecs, (vecs+(i*3)) );
|
||||
newc[0] = newc[1] = 0;
|
||||
|
||||
for (i=0, v = vecs ; i<nump ; i++, v+=3)
|
||||
{
|
||||
switch (sides[i])
|
||||
{
|
||||
case SIDE_FRONT:
|
||||
VectorCopy (v, newv[0][newc[0]]);
|
||||
newc[0]++;
|
||||
break;
|
||||
case SIDE_BACK:
|
||||
VectorCopy (v, newv[1][newc[1]]);
|
||||
newc[1]++;
|
||||
break;
|
||||
case SIDE_ON:
|
||||
VectorCopy (v, newv[0][newc[0]]);
|
||||
newc[0]++;
|
||||
VectorCopy (v, newv[1][newc[1]]);
|
||||
newc[1]++;
|
||||
break;
|
||||
}
|
||||
|
||||
if (sides[i] == SIDE_ON || sides[i+1] == SIDE_ON || sides[i+1] == sides[i])
|
||||
continue;
|
||||
|
||||
d = dists[i] / (dists[i] - dists[i+1]);
|
||||
for (j=0 ; j<3 ; j++)
|
||||
{
|
||||
e = v[j] + d*(v[j+3] - v[j]);
|
||||
newv[0][newc[0]][j] = e;
|
||||
newv[1][newc[1]][j] = e;
|
||||
}
|
||||
newc[0]++;
|
||||
newc[1]++;
|
||||
}
|
||||
|
||||
// continue
|
||||
ClipSkyPolygon (newc[0], newv[0][0], stage+1);
|
||||
ClipSkyPolygon (newc[1], newv[1][0], stage+1);
|
||||
}
|
||||
|
||||
/*
|
||||
=================
|
||||
R_DrawSkyChain
|
||||
=================
|
||||
*/
|
||||
void R_DrawSkyChain (msurface_t *s)
|
||||
{
|
||||
msurface_t *fa;
|
||||
|
||||
int i;
|
||||
vec3_t verts[MAX_CLIP_VERTS];
|
||||
glpoly_t *p;
|
||||
|
||||
if (allowskybox && skyloaded)
|
||||
{
|
||||
c_sky = 0;
|
||||
GL_Bind(solidskytexture);
|
||||
|
||||
// calculate vertex values for sky box
|
||||
|
||||
for (fa=s ; fa ; fa=fa->texturechain)
|
||||
{
|
||||
for (p=fa->polys ; p ; p=p->next)
|
||||
{
|
||||
for (i=0 ; i<p->numverts ; i++)
|
||||
{
|
||||
VectorSubtract (p->verts[i], r_origin, verts[i]);
|
||||
}
|
||||
ClipSkyPolygon (p->numverts, verts[0], 0);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// skies have no lightmap to prevent overbrighting --KB
|
||||
glColor3f (0.5, 0.5, 0.5);
|
||||
|
||||
GL_DisableMultitexture();
|
||||
|
||||
// used when gl_texsort is on
|
||||
GL_Bind(solidskytexture);
|
||||
speedscale = realtime*8;
|
||||
speedscale -= (int)speedscale & ~127 ;
|
||||
|
||||
for (fa=s ; fa ; fa=fa->texturechain)
|
||||
EmitSkyPolys (fa);
|
||||
|
||||
GL_Bind (alphaskytexture);
|
||||
speedscale = realtime*16;
|
||||
speedscale -= (int)speedscale & ~127 ;
|
||||
|
||||
for (fa=s ; fa ; fa=fa->texturechain)
|
||||
EmitSkyPolys (fa);
|
||||
|
||||
// the rest of the texture chain does though --KB
|
||||
glColor3f (1.0, 1.0, 1.0);
|
||||
}
|
||||
glColor3f (1,1,1);
|
||||
glDepthFunc (GL_LEQUAL);
|
||||
glEnable (GL_DEPTH_TEST);
|
||||
glDepthRange(gldepthmin, gldepthmax);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
==============
|
||||
R_ClearSkyBox
|
||||
==============
|
||||
*/
|
||||
void R_ClearSkyBox (void)
|
||||
vec3_t domescale;
|
||||
void
|
||||
R_DrawSkyLayer (float s)
|
||||
{
|
||||
int i;
|
||||
|
||||
for (i=0 ; i<6 ; i++)
|
||||
float a, b, x, y, a1x, a1y, a2x, a2y;
|
||||
vec3_t v;
|
||||
|
||||
for (a = 0; a < 1; a += (1.0 / 32.0))
|
||||
{
|
||||
skymins[0][i] = skymins[1][i] = 9999;
|
||||
skymaxs[0][i] = skymaxs[1][i] = -9999;
|
||||
}
|
||||
}
|
||||
a1x = cos(a * M_PI * 2);
|
||||
a1y = -sin(a * M_PI * 2);
|
||||
a2x = cos((a+(1.0/32.0)) * M_PI * 2);
|
||||
a2y = -sin((a+(1.0/32.0)) * M_PI * 2);
|
||||
|
||||
glBegin (GL_TRIANGLE_STRIP);
|
||||
for (b = 0; b <= 1; b += (1.0 / 32.0))
|
||||
{
|
||||
x = cos(b * M_PI * 2);
|
||||
y = -sin(b * M_PI * 2);
|
||||
|
||||
void MakeSkyVec (float s, float t, int axis)
|
||||
{
|
||||
vec3_t v, b;
|
||||
int j, k;
|
||||
v[0] = a1x*x * domescale[0];
|
||||
v[1] = a1y*x * domescale[1];
|
||||
v[2] = y * domescale[2];
|
||||
glTexCoord2f((v[0] + s) * (1.0 / 128.0),
|
||||
(v[1] + s) * (1.0 / 128.0));
|
||||
glVertex3f(v[0] + r_refdef.vieworg[0],
|
||||
v[1] + r_refdef.vieworg[1],
|
||||
v[2] + r_refdef.vieworg[2]);
|
||||
|
||||
b[0] = s*2048;
|
||||
b[1] = t*2048;
|
||||
b[2] = 2048;
|
||||
|
||||
for (j=0 ; j<3 ; j++)
|
||||
{
|
||||
k = st_to_vec[axis][j];
|
||||
if (k < 0)
|
||||
v[j] = -b[-k - 1];
|
||||
else
|
||||
v[j] = b[k - 1];
|
||||
v[j] += r_origin[j];
|
||||
}
|
||||
|
||||
// avoid bilerp seam
|
||||
s = (s+1)*0.5;
|
||||
t = (t+1)*0.5;
|
||||
|
||||
if (s < 1.0/512)
|
||||
s = 1.0/512;
|
||||
else if (s > 511.0/512)
|
||||
s = 511.0/512;
|
||||
if (t < 1.0/512)
|
||||
t = 1.0/512;
|
||||
else if (t > 511.0/512)
|
||||
t = 511.0/512;
|
||||
|
||||
t = 1.0 - t;
|
||||
glTexCoord2f (s, t);
|
||||
glVertex3fv (v);
|
||||
}
|
||||
|
||||
/*
|
||||
==============
|
||||
R_DrawSkyBox
|
||||
==============
|
||||
*/
|
||||
int skytexorder[6] = {0,2,1,3,4,5};
|
||||
void R_DrawSkyBox (void)
|
||||
{
|
||||
int i;
|
||||
|
||||
for (i=0 ; i<6 ; i++)
|
||||
{
|
||||
if (skymins[0][i] >= skymaxs[0][i]
|
||||
|| skymins[1][i] >= skymaxs[1][i])
|
||||
continue;
|
||||
|
||||
GL_Bind (SKY_TEX+skytexorder[i]);
|
||||
glBegin (GL_QUADS);
|
||||
MakeSkyVec (skymins[0][i], skymins[1][i], i);
|
||||
MakeSkyVec (skymins[0][i], skymaxs[1][i], i);
|
||||
MakeSkyVec (skymaxs[0][i], skymaxs[1][i], i);
|
||||
MakeSkyVec (skymaxs[0][i], skymins[1][i], i);
|
||||
v[0] = a2x*x * domescale[0];
|
||||
v[1] = a2y*x * domescale[1];
|
||||
v[2] = y * domescale[2];
|
||||
glTexCoord2f((v[0] + s) * (1.0 / 128.0),
|
||||
(v[1] + s) * (1.0 / 128.0));
|
||||
glVertex3f(v[0] + r_refdef.vieworg[0],
|
||||
v[1] + r_refdef.vieworg[1],
|
||||
v[2] + r_refdef.vieworg[2]);
|
||||
}
|
||||
glEnd ();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
R_DrawSkyDome (void)
|
||||
{
|
||||
GL_DisableMultitexture ();
|
||||
glEnable (GL_DEPTH_TEST);
|
||||
glDepthFunc (GL_ALWAYS);
|
||||
// glDisable (GL_BLEND);
|
||||
// glTexEnvf (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
|
||||
glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
||||
glDepthRange (gldepthmax, gldepthmax);
|
||||
glColor3f (0.5, 0.5, 0.5);
|
||||
|
||||
// base sky
|
||||
glBindTexture (GL_TEXTURE_2D, solidskytexture);
|
||||
domescale[0] = 512;
|
||||
domescale[1] = 512;
|
||||
domescale[2] = 128;
|
||||
speedscale = realtime*8;
|
||||
speedscale -= (int)speedscale & ~127;
|
||||
R_DrawSkyLayer (speedscale);
|
||||
glEnable (GL_BLEND);
|
||||
|
||||
// clouds
|
||||
glBindTexture (GL_TEXTURE_2D, alphaskytexture);
|
||||
domescale[0] = 512;
|
||||
domescale[1] = 512;
|
||||
domescale[2] = 128;
|
||||
speedscale = realtime*16;
|
||||
speedscale -= (int)speedscale & ~127;
|
||||
R_DrawSkyLayer (speedscale);
|
||||
|
||||
// glDisable (GL_BLEND);
|
||||
glColor3f (1,1,1);
|
||||
glDepthFunc (GL_LEQUAL);
|
||||
glEnable (GL_DEPTH_TEST);
|
||||
glDepthRange (gldepthmin, gldepthmax);
|
||||
}
|
||||
|
||||
void
|
||||
R_DrawSky ( void )
|
||||
{
|
||||
if (skyloaded)
|
||||
R_DrawSkyBox();
|
||||
else
|
||||
R_DrawSkyDome();
|
||||
}
|
||||
|
||||
|
||||
|
||||
//===============================================================
|
||||
|
||||
/*
|
||||
|
@ -1036,7 +808,7 @@ void R_InitSky (texture_t *mt)
|
|||
|
||||
if (!solidskytexture)
|
||||
solidskytexture = texture_extension_number++;
|
||||
GL_Bind (solidskytexture );
|
||||
glBindTexture (GL_TEXTURE_2D, solidskytexture );
|
||||
glTexImage2D (GL_TEXTURE_2D, 0, gl_solid_format, 128, 128, 0, GL_RGBA, GL_UNSIGNED_BYTE, trans);
|
||||
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
||||
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
||||
|
@ -1054,7 +826,7 @@ void R_InitSky (texture_t *mt)
|
|||
|
||||
if (!alphaskytexture)
|
||||
alphaskytexture = texture_extension_number++;
|
||||
GL_Bind(alphaskytexture);
|
||||
glBindTexture (GL_TEXTURE_2D, alphaskytexture);
|
||||
glTexImage2D (GL_TEXTURE_2D, 0, gl_alpha_format, 128, 128, 0, GL_RGBA, GL_UNSIGNED_BYTE, trans);
|
||||
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
||||
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
||||
|
|
|
@ -152,6 +152,8 @@ typedef void (APIENTRY *lp3DFXFUNC) (int, int, int, int, int, const void*);
|
|||
lp3DFXFUNC glColorTableEXT;
|
||||
qboolean is8bit = false;
|
||||
qboolean isPermedia = false;
|
||||
int gl_mtex_enum = TEXTURE0_SGIS;
|
||||
qboolean gl_arb_mtex = false;
|
||||
qboolean gl_mtexable = false;
|
||||
|
||||
//====================================
|
||||
|
@ -517,51 +519,6 @@ void VID_UpdateWindowStatus (void)
|
|||
}
|
||||
|
||||
|
||||
//====================================
|
||||
|
||||
BINDTEXFUNCPTR bindTexFunc;
|
||||
|
||||
#define TEXTURE_EXT_STRING "GL_EXT_texture_object"
|
||||
|
||||
|
||||
void CheckTextureExtensions (void)
|
||||
{
|
||||
char *tmp;
|
||||
qboolean texture_ext;
|
||||
HINSTANCE hInstGL;
|
||||
|
||||
texture_ext = FALSE;
|
||||
/* check for texture extension */
|
||||
tmp = (unsigned char *)glGetString(GL_EXTENSIONS);
|
||||
while (*tmp)
|
||||
{
|
||||
if (strncmp((const char*)tmp, TEXTURE_EXT_STRING, strlen(TEXTURE_EXT_STRING)) == 0)
|
||||
texture_ext = TRUE;
|
||||
tmp++;
|
||||
}
|
||||
|
||||
if (!texture_ext || COM_CheckParm ("-gl11") )
|
||||
{
|
||||
hInstGL = LoadLibrary("opengl32.dll");
|
||||
|
||||
if (hInstGL == NULL)
|
||||
Sys_Error ("Couldn't load opengl32.dll\n");
|
||||
|
||||
bindTexFunc = (void *)GetProcAddress(hInstGL,"glBindTexture");
|
||||
|
||||
if (!bindTexFunc)
|
||||
Sys_Error ("No texture objects!");
|
||||
return;
|
||||
}
|
||||
|
||||
/* load library and get procedure adresses for texture extension API */
|
||||
if ((bindTexFunc = (BINDTEXFUNCPTR)
|
||||
wglGetProcAddress((LPCSTR) "glBindTextureEXT")) == NULL)
|
||||
{
|
||||
Sys_Error ("GetProcAddress for BindTextureEXT failed");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
void CheckArrayExtensions (void)
|
||||
{
|
||||
|
@ -612,9 +569,9 @@ void CheckMultiTextureExtensions(void)
|
|||
{
|
||||
Con_Printf ("GL_ARB_multitexture\n");
|
||||
qglMTexCoord2f =
|
||||
(void *)wglGetProcAddress("glMTexCoord2fARB");
|
||||
(void *)wglGetProcAddress("glMultiTexCoord2fARB");
|
||||
qglSelectTexture =
|
||||
(void *)wglGetProcAddress("glSelectTextureARB");
|
||||
(void *)wglGetProcAddress("glActiveTextureARB");
|
||||
gl_mtex_enum = GL_TEXTURE0_ARB;
|
||||
gl_mtexable = true;
|
||||
gl_arb_mtex = true;
|
||||
|
@ -674,7 +631,6 @@ void GL_Init (void)
|
|||
if (strnicmp(gl_renderer,"Permedia",8)==0)
|
||||
isPermedia = true;
|
||||
|
||||
CheckTextureExtensions ();
|
||||
CheckMultiTextureExtensions ();
|
||||
|
||||
glClearColor (0,0,0,0);
|
||||
|
|
Loading…
Reference in a new issue