📄 gl_rsurf.c
字号:
EmitSkyPolys (s);
glEnable (GL_BLEND);
GL_Bind (alphaskytexture);
speedscale = realtime*16;
speedscale -= (int)speedscale & ~127;
EmitSkyPolys (s);
glDisable (GL_BLEND);
return;
}
//
// underwater warped with lightmap
//
R_RenderDynamicLightmaps (s);
if (gl_mtexable)
{
p = s->polys;
t = R_TextureAnimation (s->texinfo->texture);
GL_SelectTexture(TEXTURE0_SGIS);
GL_Bind (t->gl_texturenum);
glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
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;
}
// 2001-09-11 Colored lightning by LordHavoc/Sarcazm/Maddes start
if (gl_lightmap_format == GL_RGBA)
glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); // not inverse lighting
else
// 2001-09-11 Colored lightning by LordHavoc/Sarcazm/Maddes end
glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_BLEND);
glBegin (GL_TRIANGLE_FAN);
v = p->verts[0];
for (i=0 ; i<p->numverts ; i++, v+= VERTEXSIZE)
{
qglMTexCoord2fSGIS (TEXTURE0_SGIS, v[3], v[4]);
qglMTexCoord2fSGIS (TEXTURE1_SGIS, 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 ();
// 1999-12-28 OpenGL fullbright fix by Neal White III start
if (t->flags & FLAG_HAS_GLOWMAP)
{
GL_DisableMultitexture();
GL_Bind (t->gl_glowtexnum);
glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
glEnable (GL_BLEND);
glBlendFunc (GL_ONE, GL_ONE);
glBegin (GL_POLYGON);
v = p->verts[0];
for (i=0 ; i<p->numverts ; i++, v+= VERTEXSIZE)
{
glTexCoord2f (v[3], v[4]);
// Neal - DON'T DELETE - leaves unmoving glowmap on top
// I think this is a clue to the "underwater cracks" bug
//
//glVertex3fv (v);
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 ();
// restore it to Quake's default
glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glDisable (GL_BLEND);
}
// 1999-12-28 OpenGL fullbright fix by Neal White III end
}
else
{
p = s->polys;
t = R_TextureAnimation (s->texinfo->texture);
GL_Bind (t->gl_texturenum);
DrawGLWaterPoly (p);
GL_Bind (lightmap_textures + s->lightmaptexturenum);
glEnable (GL_BLEND);
DrawGLWaterPolyLightmap (p);
glDisable (GL_BLEND);
}
}
#endif
/*
================
DrawGLWaterPoly
Warp the vertex coordinates
================
*/
void DrawGLWaterPoly (glpoly_t *p)
{
int i;
float *v;
float s, t, os, ot;
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;
float s, t, os, ot;
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
================
*/
void DrawGLPoly (glpoly_t *p)
{
int i;
float *v;
glBegin (GL_POLYGON);
v = p->verts[0];
for (i=0 ; i<p->numverts ; i++, v+= VERTEXSIZE)
{
glTexCoord2f (v[3], v[4]);
glVertex3fv (v);
}
glEnd ();
}
/*
================
R_BlendLightmaps
================
*/
void R_BlendLightmaps (void)
{
int i, j;
glpoly_t *p;
float *v;
glRect_t *theRect;
if (r_fullbright->value)
return;
if (!gl_texsort->value)
return;
glDepthMask (0); // don't bother writing Z
if (gl_lightmap_format == GL_LUMINANCE)
glBlendFunc (GL_ZERO, GL_ONE_MINUS_SRC_COLOR);
else if (gl_lightmap_format == GL_INTENSITY)
{
glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
glColor4f (0,0,0,1);
glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
}
// 2001-09-11 Colored lightning by LordHavoc/Sarcazm/Maddes start
else if (gl_lightmap_format == GL_RGBA)
{
glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
glColor3f (1,1,1);
glBlendFunc(GL_ZERO, GL_SRC_COLOR);
}
// 2001-09-11 Colored lightning by LordHavoc/Sarcazm/Maddes end
// 2000-05-02 White effect fix by QSG start
else
{
glBlendFunc (GL_ZERO, GL_ONE_MINUS_SRC_COLOR);
}
// 2000-05-02 White effect fix by QSG end
if (!r_lightmap->value)
{
glEnable (GL_BLEND);
}
for (i=0 ; i<MAX_LIGHTMAPS ; i++)
{
p = lightmap_polys[i];
if (!p)
continue;
GL_Bind(lightmap_textures+i);
if (lightmap_modified[i])
{
lightmap_modified[i] = false;
theRect = &lightmap_rectchange[i];
// 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);
theRect->l = BLOCK_WIDTH;
theRect->t = BLOCK_HEIGHT;
theRect->h = 0;
theRect->w = 0;
}
for ( ; p ; p=p->chain)
{
if (p->flags & SURF_UNDERWATER)
DrawGLWaterPolyLightmap (p);
else
{
glBegin (GL_POLYGON);
v = p->verts[0];
for (j=0 ; j<p->numverts ; j++, v+= VERTEXSIZE)
{
glTexCoord2f (v[5], v[6]);
glVertex3fv (v);
}
glEnd ();
}
}
}
glDisable (GL_BLEND);
if (gl_lightmap_format == GL_LUMINANCE)
glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
else if (gl_lightmap_format == GL_INTENSITY)
{
glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
glColor4f (1,1,1,1);
}
// 2001-09-11 Colored lightning by LordHavoc/Sarcazm/Maddes start
else if (gl_lightmap_format == GL_RGBA)
{
glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
}
// 2001-09-11 Colored lightning by LordHavoc/Sarcazm/Maddes end
// 2000-05-02 White effect fix by QSG start
else
{
glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
}
// 2000-05-02 White effect fix by QSG end
glDepthMask (1); // back to normal Z buffering
}
/*
================
R_RenderBrushPoly
================
*/
void R_RenderBrushPoly (msurface_t *fa)
{
texture_t *t;
byte *base;
int maps;
glRect_t *theRect;
int smax, tmax;
c_brush_polys++;
if (fa->flags & SURF_DRAWSKY)
{ // warp texture, no lightmaps
EmitBothSkyLayers (fa);
return;
}
t = R_TextureAnimation (fa->texinfo->texture);
GL_Bind (t->gl_texturenum);
if (fa->flags & SURF_DRAWTURB)
{ // warp texture, no lightmaps
EmitWaterPolys (fa);
return;
}
if (fa->flags & SURF_UNDERWATER)
DrawGLWaterPoly (fa->polys);
else
DrawGLPoly (fa->polys);
// add the poly to the proper lightmap chain
fa->polys->chain = lightmap_polys[fa->lightmaptexturenum];
lightmap_polys[fa->lightmaptexturenum] = fa->polys;
// check for lightmap modification
for (maps = 0 ; maps < MAXLIGHTMAPS && fa->styles[maps] != 255 ;
maps++)
if (d_lightstylevalue[fa->styles[maps]] != fa->cached_light[maps])
goto dynamic;
if (fa->dlightframe == r_framecount // dynamic this frame
|| fa->cached_dlight) // dynamic previously
{
dynamic:
if (r_dynamic->value)
{
lightmap_modified[fa->lightmaptexturenum] = true;
theRect = &lightmap_rectchange[fa->lightmaptexturenum];
if (fa->light_t < theRect->t) {
if (theRect->h)
theRect->h += theRect->t - fa->light_t;
theRect->t = fa->light_t;
}
if (fa->light_s < theRect->l) {
if (theRect->w)
theRect->w += theRect->l - fa->light_s;
theRect->l = fa->light_s;
}
smax = (fa->extents[0]>>4)+1;
tmax = (fa->extents[1]>>4)+1;
if ((theRect->w + theRect->l) < (fa->light_s + smax))
theRect->w = (fa->light_s-theRect->l)+smax;
if ((theRect->h + theRect->t) < (fa->light_t + tmax))
theRect->h = (fa->light_t-theRect->t)+tmax;
base = lightmaps + fa->lightmaptexturenum*lightmap_bytes*BLOCK_WIDTH*BLOCK_HEIGHT;
base += fa->light_t * BLOCK_WIDTH * lightmap_bytes + fa->light_s * lightmap_bytes;
R_BuildLightMap (fa, base, BLOCK_WIDTH*lightmap_bytes);
}
}
}
/*
================
R_RenderDynamicLightmaps
Multitexture
================
*/
void R_RenderDynamicLightmaps (msurface_t *fa)
{
texture_t *t;
byte *base;
int maps;
glRect_t *theRect;
int smax, tmax;
c_brush_polys++;
if (fa->flags & ( SURF_DRAWSKY | SURF_DRAWTURB) )
return;
fa->polys->chain = lightmap_polys[fa->lightmaptexturenum];
lightmap_polys[fa->lightmaptexturenum] = fa->polys;
// check for lightmap modification
for (maps = 0 ; maps < MAXLIGHTMAPS && fa->styles[maps] != 255 ;
maps++)
if (d_lightstylevalue[fa->styles[maps]] != fa->cached_light[maps])
goto dynamic;
if (fa->dlightframe == r_framecount // dynamic this frame
|| fa->cached_dlight) // dynamic previously
{
dynamic:
if (r_dynamic->value)
{
lightmap_modified[fa->lightmaptexturenum] = true;
theRect = &lightmap_rectchange[fa->lightmaptexturenum];
if (fa->light_t < theRect->t) {
if (theRect->h)
theRect->h += theRect->t - fa->light_t;
theRect->t = fa->light_t;
}
if (fa->light_s < theRect->l) {
if (theRect->w)
theRect->w += theRect->l - fa->light_s;
theRect->l = fa->light_s;
}
smax = (fa->extents[0]>>4)+1;
tmax = (fa->extents[1]>>4)+1;
if ((theRect->w + theRect->l) < (fa->light_s + smax))
theRect->w = (fa->light_s-theRect->l)+smax;
if ((theRect->h + theRect->t) < (fa->light_t + tmax))
theRect->h = (fa->light_t-theRect->t)+tmax;
base = lightmaps + fa->lightmaptexturenum*lightmap_bytes*BLOCK_WIDTH*BLOCK_HEIGHT;
base += fa->light_t * BLOCK_WIDTH * lightmap_bytes + fa->light_s * lightmap_bytes;
R_BuildLightMap (fa, base, BLOCK_WIDTH*lightmap_bytes);
}
}
}
/*
================
R_MirrorChain
================
*/
void R_MirrorChain (msurface_t *s)
{
if (mirror)
return;
mirror = true;
mirror_plane = s->plane;
}
#if 0
/*
================
R_DrawWaterSurfaces
================
*/
void R_DrawWaterSurfaces (void)
{
int i;
msurface_t *s;
texture_t *t;
if (r_wateralpha->value == 1.0)
return;
//
// go back to the world matrix
//
glLoadMatrixf (r_world_matrix);
glEnable (GL_BLEND);
glColor4f (1,1,1,r_wateralpha->value);
glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
for (i=0 ; i<cl.worldmodel->numtextures ; i++)
{
t = cl.worldmodel->textures[i];
if (!t)
continue;
s = t->texturechain;
if (!s)
continue;
if ( !(s->flags & SURF_DRAWTURB) )
continue;
// set modulate mode explicitly
GL_Bind (t->gl_texturenum);
for ( ; s ; s=s->texturechain)
R_RenderBrushPoly (s);
t->texturechain = NULL;
}
glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
glColor4f (1,1,1,1);
glDisable (GL_BLEND);
}
#else
/*
================
R_DrawWaterSurfaces
================
*/
void R_DrawWaterSurfaces (void)
{
int i;
msurface_t *s;
texture_t *t;
if (r_wateralpha->value == 1.0 && gl_texsort->value)
return;
//
// go back to the world matrix
//
glLoadMatrixf (r_world_matrix);
if (r_wateralpha->value < 1.0) {
glEnable (GL_BLEND);
glColor4f (1,1,1,r_wateralpha->value);
glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
}
if (!gl_texsort->value) {
if (!waterchain)
return;
for ( s = waterchain ; s ; s=s->texturechain) {
GL_Bind (s->texinfo->texture->gl_texturenum);
EmitWaterPolys (s);
}
waterchain = NULL;
} else {
for (i=0 ; i<cl.worldmodel->numtextures ; i++)
{
t = cl.worldmodel->textures[i];
if (!t)
continue;
s = t->texturechain;
if (!s)
continue;
if ( !(s->flags & SURF_DRAWTURB ) )
continue;
// set modulate mode explicitly
GL_Bind (t->gl_texturenum);
for ( ; s ; s=s->texturechain)
EmitWaterPolys (s);
t->texturechain = NULL;
}
}
if (r_wateralpha->value < 1.0) {
glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
glColor4f (1,1,1,1);
glDisable (GL_BLEND);
}
}
#endif
/*
================
DrawTextureChains
================
*/
void DrawTextureChains (void)
{
int i;
msurface_t *s;
texture_t *t;
if (!gl_texsort->value) {
GL_DisableMultitexture();
if (skychain) {
R_DrawSkyChain(skychain);
skychain = NULL;
}
return;
}
for (i=0 ; i<cl.worldmodel->numtextures ; i++)
{
t = cl.worldmodel->textures[i];
if (!t)
continue;
s = t->texturechain;
if (!s)
continue;
if (i == skytexturenum)
R_DrawSkyChain (s);
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
for ( ; s ; s=s->texturechain)
R_RenderBrushPoly (s);
}
t->texturechain = NULL;
}
}
/*
=================
R_DrawBrushModel
=================
*/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -