From 906ab864c2f4353751ff9a2f53f99145d26155fd Mon Sep 17 00:00:00 2001 From: Forest Hale Date: Sun, 2 Jul 2000 05:16:10 +0000 Subject: [PATCH] Brightness controls (brightness, contrast) and gl_lightmode cvar. --- source/gl_draw.c | 94 ++++++++++++++++++++++++----- source/gl_ngraph.c | 6 +- source/gl_part.c | 11 +++- source/gl_rlight.c | 6 +- source/gl_rmain.c | 72 +++++----------------- source/gl_rsurf.c | 145 ++++++++++++++++++++++++++++++++------------- source/gl_screen.c | 74 +++++++++++++++++++---- source/gl_warp.c | 11 +++- 8 files changed, 289 insertions(+), 130 deletions(-) diff --git a/source/gl_draw.c b/source/gl_draw.c index 6534eba..0209d3e 100644 --- a/source/gl_draw.c +++ b/source/gl_draw.c @@ -62,6 +62,7 @@ void LoadTGA (FILE *fin); extern byte *host_basepal; extern unsigned char d_15to8table[65536]; extern cvar_t *crosshair, *cl_crossx, *cl_crossy, *crosshaircolor; +extern qboolean lighthalf; cvar_t *gl_nobind; cvar_t *gl_max_size; @@ -71,6 +72,9 @@ cvar_t *gl_constretch; cvar_t *gl_conalpha; cvar_t *gl_conspin; cvar_t *cl_verstring; +cvar_t *gl_lightmode; // LordHavoc: lighting mode +cvar_t *brightness; // LordHavoc: brightness multiplier +cvar_t *contrast; // LordHavoc: contrast scaler extern byte *draw_chars; // 8*8 graphic characters qpic_t *draw_disc; @@ -389,6 +393,8 @@ void Draw_TextureMode_f (void) } } +extern void glrmain_init(); +extern void glrsurf_init(); /* =============== Draw_Init @@ -398,6 +404,13 @@ void Draw_Init (void) { int i; + // LordHavoc: lighting mode + gl_lightmode = Cvar_Get("gl_lightmode", "1", CVAR_ARCHIVE, + "Lighting mode (0 = GLQuake style, 1 = new style)"); + brightness = Cvar_Get("brightness", "1", CVAR_ARCHIVE, + "Brightness"); + contrast = Cvar_Get("contrast", "1", CVAR_ARCHIVE, + "contrast"); gl_nobind = Cvar_Get("gl_nobind", "0", CVAR_NONE, "whether or not to inhibit texture binding"); gl_max_size = Cvar_Get("gl_max_size", "1024", CVAR_NONE, @@ -421,6 +434,11 @@ void Draw_Init (void) !strncasecmp ((char *)gl_renderer, "Mesa",4)) Cvar_Set (gl_max_size, "256"); + // LordHavoc: 3DFX's dithering has terrible artifacting when using lightmode 1 + if (!strncasecmp ((char *)gl_renderer, "3dfx",4)) + Cvar_Set (gl_lightmode, "0"); + lighthalf = gl_lightmode->value != 0; // to avoid re-rendering all lightmaps on first frame + Cmd_AddCommand ("gl_texturemode", &Draw_TextureMode_f); // load the console background and the charset @@ -452,6 +470,10 @@ void Draw_Init (void) // draw_disc = Draw_PicFromWad ("disc"); draw_backtile = Draw_PicFromWad ("backtile"); + + // LordHavoc: call init code for other GL renderer modules; + glrmain_init(); + glrsurf_init(); } @@ -487,7 +509,10 @@ void Draw_Character8 (int x, int y, int num) glBindTexture (GL_TEXTURE_2D, char_texture); - glColor3f (0.5, 0.5, 0.5); + if (lighthalf) + glColor3f(0.5,0.5,0.5); + else + glColor3f(1,1,1); glBegin (GL_QUADS); glTexCoord2f (fcol, frow); glVertex2f (x, y); @@ -542,7 +567,10 @@ void Draw_Crosshair(void) y = scr_vrect.y + scr_vrect.height/2 - 3 + cl_crossy->value; pColor = (unsigned char *) &d_8to24table[(byte) crosshaircolor->value]; - glColor4ubv ( pColor ); + if (lighthalf) + glColor4ub((byte) ((int) pColor[0] >> 1),(byte) ((int) pColor[1] >> 1), (byte) ((int) pColor[2] >> 1), pColor[3]); + else + glColor4ubv(pColor); glBindTexture (GL_TEXTURE_2D, cs_texture); glBegin (GL_QUADS); @@ -587,7 +615,10 @@ void Draw_Pic (int x, int y, qpic_t *pic) if (scrap_dirty) Scrap_Upload (); gl = (glpic_t *)pic->data; - glColor3f (0.4, 0.4, 0.4); + if (lighthalf) + glColor3f(0.4,0.4,0.4); + else + glColor3f(0.8,0.8,0.8); glBindTexture (GL_TEXTURE_2D, gl->texnum); glBegin (GL_QUADS); glTexCoord2f (gl->sl, gl->tl); @@ -613,7 +644,10 @@ void Draw_AlphaPic (int x, int y, qpic_t *pic, float alpha) if (scrap_dirty) Scrap_Upload (); gl = (glpic_t *)pic->data; - glColor4f (0.4, 0.4, 0.4, alpha); + if (lighthalf) + glColor4f(0.4,0.4,0.4,alpha); + else + glColor4f(0.8,0.8,0.8,alpha); glBindTexture (GL_TEXTURE_2D, gl->texnum); glBegin (GL_QUADS); glTexCoord2f (gl->sl, gl->tl); @@ -625,7 +659,10 @@ void Draw_AlphaPic (int x, int y, qpic_t *pic, float alpha) glTexCoord2f (gl->sl, gl->th); glVertex2f (x, y+pic->height); glEnd (); - glColor3f (0.5, 0.5, 0.5); + if (lighthalf) + glColor3f(0.5,0.5,0.5); + else + glColor3f(1,1,1); } void Draw_SubPic(int x, int y, qpic_t *pic, int srcx, int srcy, int width, int height) @@ -647,7 +684,10 @@ void Draw_SubPic(int x, int y, qpic_t *pic, int srcx, int srcy, int width, int h newtl = gl->tl + (srcy*oldglheight)/pic->height; newth = newtl + (height*oldglheight)/pic->height; - glColor3f (0.4, 0.4, 0.4); + if (lighthalf) + glColor3f(0.4,0.4,0.4); + else + glColor3f(0.8,0.8,0.8); glBindTexture (GL_TEXTURE_2D, gl->texnum); glBegin (GL_QUADS); glTexCoord2f (newsl, newtl); @@ -716,7 +756,10 @@ void Draw_TransPicTranslate (int x, int y, qpic_t *pic, byte *translation) glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); - glColor3f (0.4, 0.4, 0.4); + if (lighthalf) + glColor3f(0.4,0.4,0.4); + else + glColor3f(0.8,0.8,0.8); glBegin (GL_QUADS); glTexCoord2f (0, 0); glVertex2f (x, y); @@ -783,7 +826,10 @@ Draw_ConsoleBackground ( int lines ) alpha = (float)(gl_conalpha->value * lines)/y; } - glColor4f (0.5, 0.5, 0.5, alpha); + if (lighthalf) + glColor4f(0.4,0.4,0.4,alpha); + else + glColor4f(0.8,0.8,0.8,alpha); // draw the console texture glBindTexture (GL_TEXTURE_2D, gl->texnum); @@ -801,7 +847,10 @@ Draw_ConsoleBackground ( int lines ) // turn off alpha blending if (alpha < 1.0) { - glColor3f (0.5, 0.5, 0.5); + if (lighthalf) + glColor3f(0.4,0.4,0.4); + else + glColor3f(0.8,0.8,0.8); } if (gl_conspin->value) @@ -828,7 +877,10 @@ refresh window. */ void Draw_TileClear (int x, int y, int w, int h) { - glColor3f (0.5, 0.5, 0.5); + if (lighthalf) + glColor3f(0.4,0.4,0.4); + else + glColor3f(0.8,0.8,0.8); glBindTexture (GL_TEXTURE_2D, *(int *)draw_backtile->data); glBegin (GL_QUADS); glTexCoord2f (x/64.0, y/64.0); @@ -853,9 +905,10 @@ Fills a box of pixels with a single color void Draw_Fill (int x, int y, int w, int h, int c) { glDisable (GL_TEXTURE_2D); - glColor3f (host_basepal[c*3]/510.0, - host_basepal[c*3+1]/510.0, - host_basepal[c*3+2]/510.0); + if (lighthalf) + glColor3f (host_basepal[c*3]/510.0, host_basepal[c*3+1]/510.0, host_basepal[c*3+2]/510.0); + else + glColor3f (host_basepal[c*3]/255.0, host_basepal[c*3+1]/255.0, host_basepal[c*3+2]/255.0); glBegin (GL_QUADS); @@ -865,7 +918,10 @@ void Draw_Fill (int x, int y, int w, int h, int c) glVertex2f (x, y+h); glEnd (); - glColor3f (0.5, 0.5, 0.5); + if (lighthalf) + glColor3f(0.5,0.5,0.5); + else + glColor3f(1,1,1); glEnable (GL_TEXTURE_2D); } //============================================================================= @@ -888,7 +944,10 @@ void Draw_FadeScreen (void) glVertex2f (0, vid.height); glEnd (); - glColor3f (0.5, 0.5, 0.5); + if (lighthalf) + glColor3f(0.5,0.5,0.5); + else + glColor3f(1,1,1); glEnable (GL_TEXTURE_2D); Sbar_Changed(); @@ -948,7 +1007,10 @@ void GL_Set2D (void) glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); - glColor3f (0.5, 0.5, 0.5); + if (lighthalf) + glColor3f(0.5,0.5,0.5); + else + glColor3f(1,1,1); } //==================================================================== diff --git a/source/gl_ngraph.c b/source/gl_ngraph.c index 55b0e38..c6be28d 100644 --- a/source/gl_ngraph.c +++ b/source/gl_ngraph.c @@ -55,6 +55,7 @@ extern byte *draw_chars; // 8*8 graphic characters +extern qboolean lighthalf; int netgraphtexture; // netgraph texture @@ -159,7 +160,10 @@ void R_NetGraph (void) glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); x = 8; - glColor3f (0.5, 0.5, 0.5); + if (lighthalf) + glColor3f(0.5,0.5,0.5); + else + glColor3f(1,1,1); glBegin (GL_QUADS); glTexCoord2f (0, 0); glVertex2f (x, y); diff --git a/source/gl_part.c b/source/gl_part.c index f08fcc1..92990a4 100644 --- a/source/gl_part.c +++ b/source/gl_part.c @@ -74,6 +74,7 @@ vec3_t r_pright, r_pup, r_ppn; fire_t r_fires[MAX_FIRES]; extern cvar_t *gl_fires; +extern qboolean lighthalf; /* =============== @@ -580,7 +581,10 @@ void R_DrawParticles (void) // theAlpha = 255*(8-p->ramp)/8; else theAlpha = 255; - glColor4ub (*at, *(at+1), *(at+2), theAlpha); + if (lighthalf) + glColor4ub((byte) ((int) at[0] >> 1), (byte) ((int) at[1] >> 1), (byte) ((int) at[2] >> 1), theAlpha); + else + glColor4ub(at[0], at[1], at[2], theAlpha); // glColor3ubv (at); // glColor3ubv ((byte *)&d_8to24table[(int)p->color]); glTexCoord2f (0,0); @@ -766,7 +770,10 @@ R_DrawFire (fire_t *f) // we're not - draw it glBegin (GL_TRIANGLE_FAN); - glColor3fv (f->color); + if (lighthalf) + glColor3f(f->color[0]*0.5,f->color[1]*0.5,f->color[2]*0.5); + else + glColor3fv(f->color); for (i=0 ; i<3 ; i++) vec[i] = f->origin[i] - vpn[i] * radius; glVertex3fv (vec); diff --git a/source/gl_rlight.c b/source/gl_rlight.c index 8fdb0a6..5b655dd 100644 --- a/source/gl_rlight.c +++ b/source/gl_rlight.c @@ -55,6 +55,7 @@ #include "glquake.h" int r_dlightframecount; +extern qboolean lighthalf; /* @@ -146,7 +147,10 @@ void R_RenderDlight (dlight_t *light) glBegin (GL_TRIANGLE_FAN); // glColor3f (0.2,0.1,0.0); // glColor3f (0.2,0.1,0.05); // changed dimlight effect - glColor3fv (light->color); + if (lighthalf) + glColor3f(light->color[0]*0.5,light->color[1]*0.5,light->color[2]*0.5); + else + glColor3fv (light->color); for (i=0 ; i<3 ; i++) v[i] = light->origin[i] - vpn[i]*rad; glVertex3fv (v); diff --git a/source/gl_rmain.c b/source/gl_rmain.c index dbad013..e40f75e 100644 --- a/source/gl_rmain.c +++ b/source/gl_rmain.c @@ -126,8 +126,14 @@ cvar_t *r_skyname; extern cvar_t *scr_fov; extern byte gammatable[256]; +extern qboolean lighthalf; static float vid_gamma = 1.0; +// LordHavoc: place for gl_rmain setup code +void glrmain_init() +{ +}; + /* GL_CheckGamma @@ -288,7 +294,10 @@ void R_DrawSpriteModel (entity_t *e) right = vright; } - glColor4f (0.5, 0.5, 0.5, 1); + if (lighthalf) + glColor4f(0.5,0.5,0.5,1); + else + glColor4f(1,1,1,1); GL_DisableMultitexture(); @@ -371,15 +380,6 @@ void GL_DrawAliasFrame (aliashdr_t *paliashdr, int posenum) verts += posenum * paliashdr->poseverts; order = (int *)((byte *)paliashdr + paliashdr->commands); - if (modelalpha == 0) - modelalpha = 1; - if (shadecolor[0] == 0) - shadecolor[0] = 1; - if (shadecolor[1] == 0) - shadecolor[1] = 1; - if (shadecolor[2] == 0) - shadecolor[2] = 1; - if (modelalpha != 1.0) glDepthMask(0); @@ -545,6 +545,12 @@ void R_DrawAliasModel (entity_t *e) shadecolor[0] = currententity->colormod[0]; shadecolor[1] = currententity->colormod[1]; shadecolor[2] = currententity->colormod[2]; + if (lighthalf) + { + shadecolor[0] *= 0.5; + shadecolor[1] *= 0.5; + shadecolor[2] *= 0.5; + } VectorCopy (currententity->origin, r_entorigin); VectorSubtract (r_origin, r_entorigin, modelorg); @@ -748,50 +754,6 @@ void R_DrawViewModel (void) glDepthRange (gldepthmin, gldepthmax); } - -/* -============ -R_PolyBlend -============ -*/ -void R_PolyBlend (void) -{ - if (!gl_polyblend->value) - return; - if (!v_blend[3]) - return; - -//Con_Printf("R_PolyBlend(): %4.2f %4.2f %4.2f %4.2f\n",v_blend[0], v_blend[1], v_blend[2], v_blend[3]); - - GL_DisableMultitexture(); - - glEnable (GL_BLEND); - glDisable (GL_DEPTH_TEST); - glDisable (GL_TEXTURE_2D); - - glLoadIdentity (); - - glRotatef (-90, 1, 0, 0); // put Z going up - glRotatef (90, 0, 0, 1); // put Z going up - - glBlendFunc (GL_SRC_ALPHA, GL_ONE); - // software alpha is about GL alpha squared --KB -// v_blend[3] = sqrt(v_blend[3]); - - glColor4fv (v_blend); - - glBegin (GL_QUADS); - glVertex3f (10, 100, 100); - glVertex3f (10, -100, 100); - glVertex3f (10, -100, -100); - glVertex3f (10, 100, -100); - glEnd (); - - glEnable (GL_TEXTURE_2D); - glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); -} - - int SignbitsForPlane (mplane_t *out) { int bits, j; @@ -1128,6 +1090,4 @@ void R_RenderView (void) // render mirror view // R_Mirror (); - - R_PolyBlend (); } diff --git a/source/gl_rsurf.c b/source/gl_rsurf.c index 4b421d0..ec94268 100644 --- a/source/gl_rsurf.c +++ b/source/gl_rsurf.c @@ -62,8 +62,8 @@ int skytexturenum; #define GL_RGBA4 0 #endif -extern vec3_t shadecolor; // Ender (Extend) Colormod -int lightmap_bytes; // 1 or 4 +extern vec3_t shadecolor; // Ender (Extend) Colormod +int lightmap_bytes; // 1 or 3 int lightmap_textures; @@ -74,7 +74,8 @@ cvar_t *gl_colorlights; #define BLOCK_WIDTH 128 #define BLOCK_HEIGHT 128 -#define MAX_LIGHTMAPS 64 +// LordHavoc: since lightmaps are now allocated only as needed, allow a ridiculous number :) +#define MAX_LIGHTMAPS 1024 int active_lightmaps; typedef struct glRect_s { @@ -89,7 +90,8 @@ int allocated[MAX_LIGHTMAPS][BLOCK_WIDTH]; // the lightmap texture data needs to be kept in // main memory so texsubimage can update properly -byte lightmaps[4*MAX_LIGHTMAPS*BLOCK_WIDTH*BLOCK_HEIGHT]; +// LordHavoc: changed to be allocated at runtime (typically lower memory usage) +byte *lightmaps[MAX_LIGHTMAPS]; // For gl_texsort 0 msurface_t *skychain = NULL; @@ -97,10 +99,38 @@ msurface_t *waterchain = NULL; void R_RenderDynamicLightmaps (msurface_t *fa); +extern qboolean lighthalf; + +// LordHavoc: place for gl_rsurf setup code +void glrsurf_init() +{ + memset(&lightmaps, 0, sizeof(lightmaps)); +} + +void recursivelightupdate(mnode_t *node) +{ + int c; + msurface_t *surf; + if (node->children[0]->contents >= 0) + recursivelightupdate(node->children[0]); + if (node->children[1]->contents >= 0) + recursivelightupdate(node->children[1]); + if (c = node->numsurfaces) + for (surf = cl.worldmodel->surfaces + node->firstsurface; c ; c--, surf++) + surf->cached_dlight = true; +} + +// LordHavoc: function to force all lightmaps to be updated +void R_ForceLightUpdate() +{ + if (cl.worldmodel && cl.worldmodel->nodes && cl.worldmodel->nodes->contents >= 0) + recursivelightupdate(cl.worldmodel->nodes); +} + /* R_AddDynamicLights - LordHavoc's redesigned this function completely + LordHavoc's lighting */ void R_AddDynamicLights (msurface_t *surf) @@ -247,33 +277,67 @@ store: { stride -= smax * 3; bl = blocklights; - for (i = 0; i < tmax; i++, dest += stride) - for (j=0 ; j> 8; - *dest++ = bound(0, t, 255); - t = (int) *bl++ >> 8; - *dest++ = bound(0, t, 255); - t = (int) *bl++ >> 8; - *dest++ = bound(0, t, 255); - } + if (lighthalf) + { + for (i = 0; i < tmax; i++, dest += stride) + for (j=0 ; j> 8; + *dest++ = bound(0, t, 255); + t = (int) *bl++ >> 8; + *dest++ = bound(0, t, 255); + t = (int) *bl++ >> 8; + *dest++ = bound(0, t, 255); + } + } + else + { + for (i = 0; i < tmax; i++, dest += stride) + for (j=0 ; j> 7; + *dest++ = bound(0, t, 255); + t = (int) *bl++ >> 7; + *dest++ = bound(0, t, 255); + t = (int) *bl++ >> 7; + *dest++ = bound(0, t, 255); + } + } } else { stride -= smax; bl = blocklights; - for (i = 0; i < tmax; i++, dest += stride) - for (j=0 ; j> 8; - t2 = bound(0, t, 255); - t = (int) *bl++ >> 8; - t2 += bound(0, t, 255); - t = (int) *bl++ >> 8; - t2 += bound(0, t, 255); - t2 *= (1.0/3.0); - *dest++ = t2; - } + if (lighthalf) + { + for (i = 0; i < tmax; i++, dest += stride) + for (j=0 ; j> 8; + t2 = bound(0, t, 255); + t = (int) *bl++ >> 8; + t2 += bound(0, t, 255); + t = (int) *bl++ >> 8; + t2 += bound(0, t, 255); + t2 *= (1.0/3.0); + *dest++ = t2; + } + } + else + { + for (i = 0; i < tmax; i++, dest += stride) + for (j=0 ; j> 7; + t2 = bound(0, t, 255); + t = (int) *bl++ >> 7; + t2 += bound(0, t, 255); + t = (int) *bl++ >> 7; + t2 += bound(0, t, 255); + t2 *= (1.0/3.0); + *dest++ = t2; + } + } } } @@ -599,8 +663,7 @@ dynamic: 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; + base = lightmaps[fa->lightmaptexturenum] + fa->light_t * BLOCK_WIDTH * lightmap_bytes + fa->light_s * lightmap_bytes; R_BuildLightMap (fa, base, BLOCK_WIDTH*lightmap_bytes); } } @@ -657,8 +720,7 @@ dynamic: 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; + base = lightmaps[fa->lightmaptexturenum] + fa->light_t * BLOCK_WIDTH * lightmap_bytes + fa->light_s * lightmap_bytes; R_BuildLightMap (fa, base, BLOCK_WIDTH*lightmap_bytes); } } @@ -698,13 +760,12 @@ void R_DrawWaterSurfaces (void) glLoadMatrixf (r_world_matrix); - if (r_wateralpha->value < 1.0) - { - glColor4f (0.5, 0.5, 0.5, r_wateralpha->value); - glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); - } + if (lighthalf) + glColor4f(0.5,0.5,0.5, r_wateralpha->value); else - glColor3f (0.5, 0.5, 0.5); + glColor4f(1,1,1, r_wateralpha->value); + if (r_wateralpha->value < 1.0) + glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); if (!gl_texsort->value) { @@ -745,8 +806,7 @@ void R_DrawWaterSurfaces (void) } - if (r_wateralpha->value < 1.0) - glColor3f (0.5, 0.5, 0.5); + glColor3f(1,1,1); } @@ -1147,6 +1207,10 @@ int AllocBlock (int w, int h, int *x, int *y) if (best + h > BLOCK_HEIGHT) continue; + // LordHavoc: allocate lightmaps only as needed + if (!lightmaps[texnum]) + lightmaps[texnum] = calloc(BLOCK_WIDTH * BLOCK_HEIGHT, 3); + for (i=0 ; iextents[1]>>4)+1; surf->lightmaptexturenum = AllocBlock (smax, tmax, &surf->light_s, &surf->light_t); - base = lightmaps + surf->lightmaptexturenum*lightmap_bytes*BLOCK_WIDTH*BLOCK_HEIGHT; - base += (surf->light_t * BLOCK_WIDTH + surf->light_s) * lightmap_bytes; + base = lightmaps[surf->lightmaptexturenum] + (surf->light_t * BLOCK_WIDTH + surf->light_s) * lightmap_bytes; R_BuildLightMap (surf, base, BLOCK_WIDTH*lightmap_bytes); } diff --git a/source/gl_screen.c b/source/gl_screen.c index 24ca61b..99d69d3 100644 --- a/source/gl_screen.c +++ b/source/gl_screen.c @@ -1114,6 +1114,9 @@ void SCR_TileClear (void) } float oldsbar = 0; +extern void R_ForceLightUpdate(); +qboolean lighthalf; +extern cvar_t *gl_lightmode, *brightness, *contrast; /* ================== @@ -1129,6 +1132,7 @@ needs almost the entire 256k of stack space! void SCR_UpdateScreen (void) { double time1 = 0, time2; + float f; if (block_drawing) return; @@ -1182,6 +1186,14 @@ void SCR_UpdateScreen (void) // // do 3D refresh drawing, and then update the screen // + + // LordHavoc: set lighthalf based on gl_lightmode cvar + if (lighthalf != (gl_lightmode->value != 0)) + { + lighthalf = gl_lightmode->value != 0; + R_ForceLightUpdate(); + } + SCR_SetUpToDrawConsole (); V_RenderView (); @@ -1233,19 +1245,59 @@ void SCR_UpdateScreen (void) M_Draw (); } - // LordHavoc's lighting fix - glDisable (GL_TEXTURE_2D); - glColor3f (1.0, 1.0, 1.0); - glBlendFunc (GL_DST_COLOR, GL_ONE); - glBegin (GL_QUADS); - glVertex2f (0,0); - glVertex2f (vid.width, 0); - glVertex2f (vid.width, vid.height); - glVertex2f (0, vid.height); - glEnd (); +// LordHavoc: adjustable brightness and contrast, +// also makes polyblend apply to whole screen + glDisable(GL_TEXTURE_2D); + glEnable(GL_BLEND); + brightness->value = bound(1, brightness->value, 5); + if (lighthalf) // LordHavoc: render was done at half brightness + f = brightness->value * 2; + else + f = brightness->value; + if (f > 1) + { + glBlendFunc (GL_DST_COLOR, GL_ONE); + glBegin (GL_QUADS); + while (f > 1) + { + if (f >= 2) + glColor3f (1, 1, 1); + else + glColor3f (f-1, f-1, f-1); + glVertex2f (0,0); + glVertex2f (vid.width, 0); + glVertex2f (vid.width, vid.height); + glVertex2f (0, vid.height); + f *= 0.5; + } + glEnd (); + } glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); - glEnable(GL_TEXTURE_2D); + contrast->value = bound(0.2, contrast->value, 1.0); + if ((gl_polyblend->value && v_blend[3]) || contrast->value < 1) + { + glBegin (GL_QUADS); + if (contrast->value < 1) + { + glColor4f (1, 1, 1, 1-contrast->value); + glVertex2f (0,0); + glVertex2f (vid.width, 0); + glVertex2f (vid.width, vid.height); + glVertex2f (0, vid.height); + } + if (gl_polyblend->value && v_blend[3]) + { + glColor4fv (v_blend); + glVertex2f (0,0); + glVertex2f (vid.width, 0); + glVertex2f (vid.width, vid.height); + glVertex2f (0, vid.height); + } + glEnd (); + } + glDisable(GL_BLEND); + glEnable(GL_TEXTURE_2D); V_UpdatePalette (); diff --git a/source/gl_warp.c b/source/gl_warp.c index 4b7b005..95d1d82 100644 --- a/source/gl_warp.c +++ b/source/gl_warp.c @@ -48,6 +48,7 @@ extern double realtime; extern model_t *loadmodel; extern int skytexturenum; +extern qboolean lighthalf; int solidskytexture; int alphaskytexture; @@ -655,7 +656,10 @@ R_DrawSkyBox (void) // glDisable (GL_BLEND); // glTexEnvf (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); glDepthRange (gldepthmax, gldepthmax); - glColor3f (0.5, 0.5, 0.5); + if (lighthalf) + glColor3f(0.5,0.5,0.5); + else + glColor3f(1,1,1); for (i = 0; i < 6; i++) { @@ -735,7 +739,10 @@ R_DrawSkyDome (void) // 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); + if (lighthalf) + glColor3f(0.5,0.5,0.5); + else + glColor3f(1,1,1); // base sky glBindTexture (GL_TEXTURE_2D, solidskytexture);