2000-08-25 06:42:29 +00:00
|
|
|
/*
|
2000-10-27 10:50:32 +00:00
|
|
|
gl_view.c
|
2000-08-25 06:42:29 +00:00
|
|
|
|
2000-10-27 10:50:32 +00:00
|
|
|
OpenGL-specific view management functions
|
2000-08-25 06:42:29 +00:00
|
|
|
|
|
|
|
Copyright (C) 1996-1997 Id Software, Inc.
|
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or
|
|
|
|
modify it under the terms of the GNU General Public License
|
|
|
|
as published by the Free Software Foundation; either version 2
|
|
|
|
of the License, or (at your option) any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
|
|
|
|
|
|
See the GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program; if not, write to:
|
|
|
|
|
|
|
|
Free Software Foundation, Inc.
|
|
|
|
59 Temple Place - Suite 330
|
|
|
|
Boston, MA 02111-1307, USA
|
|
|
|
|
|
|
|
$Id$
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifdef HAVE_CONFIG_H
|
2000-08-26 05:48:38 +00:00
|
|
|
# include "config.h"
|
2000-08-25 06:42:29 +00:00
|
|
|
#endif
|
|
|
|
|
2000-08-26 05:48:38 +00:00
|
|
|
#include "view.h"
|
|
|
|
#include "client.h"
|
|
|
|
#include "host.h"
|
|
|
|
#include "console.h"
|
2000-10-02 17:26:39 +00:00
|
|
|
#include "compat.h"
|
2000-08-25 06:42:29 +00:00
|
|
|
|
2000-08-26 05:48:38 +00:00
|
|
|
byte ramps[3][256];
|
|
|
|
float v_blend[4]; // rgba 0.0 - 1.0
|
2000-08-25 06:42:29 +00:00
|
|
|
|
|
|
|
/*
|
2000-10-02 17:26:39 +00:00
|
|
|
V_CalcBlend
|
|
|
|
|
|
|
|
LordHavoc made this a real, (messy,) true alpha blend. Cleaned it up
|
|
|
|
a bit, but otherwise this is his code. --KB
|
2000-08-25 06:42:29 +00:00
|
|
|
*/
|
2000-10-02 17:26:39 +00:00
|
|
|
void
|
|
|
|
V_CalcBlend (void)
|
2000-08-25 06:42:29 +00:00
|
|
|
{
|
2000-10-27 10:50:32 +00:00
|
|
|
float r = 0;
|
|
|
|
float g = 0;
|
|
|
|
float b = 0;
|
|
|
|
float a = 0;
|
2000-08-25 06:42:29 +00:00
|
|
|
|
2000-10-27 10:50:32 +00:00
|
|
|
float a2, a3;
|
|
|
|
int i;
|
2000-08-25 06:42:29 +00:00
|
|
|
|
2000-10-27 10:50:32 +00:00
|
|
|
for (i = 0; i < NUM_CSHIFTS; i++) {
|
2000-08-25 06:42:29 +00:00
|
|
|
if (!gl_cshiftpercent->value)
|
|
|
|
continue;
|
|
|
|
|
2000-10-27 10:50:32 +00:00
|
|
|
a2 = ((cl.cshifts[i].percent * gl_cshiftpercent->value) / 100.0) / 255.0;
|
2000-08-25 06:42:29 +00:00
|
|
|
|
|
|
|
if (!a2)
|
|
|
|
continue;
|
2000-10-02 17:26:39 +00:00
|
|
|
|
|
|
|
a2 = min(a2, 1.0);
|
2000-10-27 10:50:32 +00:00
|
|
|
r += (cl.cshifts[i].destcolor[0]-r) * a2;
|
|
|
|
g += (cl.cshifts[i].destcolor[1]-g) * a2;
|
|
|
|
b += (cl.cshifts[i].destcolor[2]-b) * a2;
|
2000-10-02 17:26:39 +00:00
|
|
|
|
|
|
|
a3 = (1.0 - a) * (1.0 - a2);
|
|
|
|
a = 1.0 - a3;
|
|
|
|
}
|
|
|
|
|
|
|
|
// LordHavoc: saturate color
|
2000-10-27 10:50:32 +00:00
|
|
|
if (a) {
|
2000-10-02 17:26:39 +00:00
|
|
|
a2 = 1.0 / a;
|
|
|
|
r *= a2;
|
|
|
|
g *= a2;
|
|
|
|
b *= a2;
|
2000-10-27 10:50:32 +00:00
|
|
|
// don't clamp alpha here, we do it below
|
2000-08-25 06:42:29 +00:00
|
|
|
}
|
|
|
|
|
2000-10-27 10:50:32 +00:00
|
|
|
v_blend[0] = min (r, 255.0) / 255.0;
|
|
|
|
v_blend[1] = min (g, 255.0) / 255.0;
|
|
|
|
v_blend[2] = min (b, 255.0) / 255.0;
|
2000-10-02 17:26:39 +00:00
|
|
|
v_blend[3] = bound (0.0, a, 1.0);
|
2000-08-25 06:42:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2000-10-27 10:50:32 +00:00
|
|
|
V_UpdatePalette
|
|
|
|
|
|
|
|
In software, this function (duh) updates the palette. In GL, all it does is
|
|
|
|
set up some values for shifting the screen color in a particular direction.
|
2000-08-25 06:42:29 +00:00
|
|
|
*/
|
2000-10-27 10:50:32 +00:00
|
|
|
void
|
|
|
|
V_UpdatePalette (void)
|
2000-08-25 06:42:29 +00:00
|
|
|
{
|
2000-10-02 16:13:12 +00:00
|
|
|
int i, j;
|
2000-08-25 06:42:29 +00:00
|
|
|
qboolean new;
|
2000-10-02 16:13:12 +00:00
|
|
|
qboolean force;
|
2000-08-25 06:42:29 +00:00
|
|
|
|
|
|
|
V_CalcPowerupCshift ();
|
|
|
|
|
|
|
|
new = false;
|
|
|
|
|
2000-10-27 10:50:32 +00:00
|
|
|
for (i = 0; i < NUM_CSHIFTS; i++) {
|
2000-10-02 16:13:12 +00:00
|
|
|
if (cl.cshifts[i].percent != cl.prev_cshifts[i].percent) {
|
2000-08-25 06:42:29 +00:00
|
|
|
new = true;
|
|
|
|
cl.prev_cshifts[i].percent = cl.cshifts[i].percent;
|
|
|
|
}
|
2000-10-27 10:50:32 +00:00
|
|
|
for (j = 0; j < 3; j++) {
|
2000-10-02 16:13:12 +00:00
|
|
|
if (cl.cshifts[i].destcolor[j] != cl.prev_cshifts[i].destcolor[j]) {
|
2000-08-25 06:42:29 +00:00
|
|
|
new = true;
|
|
|
|
cl.prev_cshifts[i].destcolor[j] = cl.cshifts[i].destcolor[j];
|
|
|
|
}
|
2000-10-02 16:13:12 +00:00
|
|
|
}
|
2000-08-25 06:42:29 +00:00
|
|
|
}
|
2000-08-26 05:48:38 +00:00
|
|
|
|
2000-10-02 16:13:12 +00:00
|
|
|
// drop the damage value
|
2000-08-25 06:42:29 +00:00
|
|
|
cl.cshifts[CSHIFT_DAMAGE].percent -= host_frametime*150;
|
2000-10-27 10:50:32 +00:00
|
|
|
cl.cshifts[CSHIFT_DAMAGE].percent = max (cl.cshifts[CSHIFT_DAMAGE].percent, 0);
|
2000-08-25 06:42:29 +00:00
|
|
|
|
2000-10-02 16:13:12 +00:00
|
|
|
// drop the bonus value
|
2000-08-25 06:42:29 +00:00
|
|
|
cl.cshifts[CSHIFT_BONUS].percent -= host_frametime*100;
|
2000-10-27 10:50:32 +00:00
|
|
|
cl.cshifts[CSHIFT_BONUS].percent = max (cl.cshifts[CSHIFT_BONUS].percent, 0);
|
2000-08-25 06:42:29 +00:00
|
|
|
|
|
|
|
force = V_CheckGamma ();
|
|
|
|
if (!new && !force)
|
|
|
|
return;
|
|
|
|
|
|
|
|
V_CalcBlend ();
|
|
|
|
}
|
|
|
|
|
2000-08-26 05:48:38 +00:00
|
|
|
/*
|
2000-10-27 10:50:32 +00:00
|
|
|
* View Rendering
|
|
|
|
*/
|
2000-08-26 05:48:38 +00:00
|
|
|
|
|
|
|
/*
|
2000-10-27 10:50:32 +00:00
|
|
|
V_RenderView
|
2000-08-26 05:48:38 +00:00
|
|
|
|
2000-10-27 10:50:32 +00:00
|
|
|
The player's clipping box goes from (-16 -16 -24) to (16 16 32) from
|
|
|
|
the entity origin, so any view position inside that will be valid
|
2000-08-26 05:48:38 +00:00
|
|
|
*/
|
|
|
|
extern vrect_t scr_vrect;
|
|
|
|
|
2000-10-27 10:50:32 +00:00
|
|
|
void
|
|
|
|
V_RenderView (void)
|
2000-08-26 05:48:38 +00:00
|
|
|
{
|
|
|
|
if (con_forcedup)
|
|
|
|
return;
|
|
|
|
|
|
|
|
// don't allow cheats in multiplayer
|
2000-10-27 10:50:32 +00:00
|
|
|
if (cl.maxclients > 1) {
|
2000-08-26 05:48:38 +00:00
|
|
|
Cvar_Set(scr_ofsx, "0");
|
|
|
|
Cvar_Set(scr_ofsy, "0");
|
|
|
|
Cvar_Set(scr_ofsz, "0");
|
|
|
|
}
|
|
|
|
|
2000-10-27 10:50:32 +00:00
|
|
|
if (cl.intermission) { // intermission / finale rendering
|
2000-08-26 05:48:38 +00:00
|
|
|
V_CalcIntermissionRefdef ();
|
2000-10-27 10:50:32 +00:00
|
|
|
} else {
|
2000-08-26 05:48:38 +00:00
|
|
|
if (!cl.paused /* && (sv.maxclients > 1 || key_dest == key_game) */ )
|
|
|
|
V_CalcRefdef ();
|
|
|
|
}
|
|
|
|
|
2000-08-27 07:46:54 +00:00
|
|
|
R_PushDlights (vec3_origin);
|
2000-08-26 05:48:38 +00:00
|
|
|
|
2000-10-27 10:50:32 +00:00
|
|
|
R_RenderView ();
|
2000-08-26 05:48:38 +00:00
|
|
|
}
|
2000-09-24 14:15:06 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
BuildGammaTable
|
|
|
|
|
2000-10-27 10:50:32 +00:00
|
|
|
In software mode, this function gets the palette ready for changing...
|
2000-09-24 14:15:06 +00:00
|
|
|
in GL, it does very little as you can see.
|
|
|
|
*/
|
|
|
|
|
|
|
|
void
|
|
|
|
BuildGammaTable (float b, float c)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < 256; i++)
|
|
|
|
gammatable[i] = i;
|
|
|
|
return;
|
|
|
|
}
|