2001-05-11 01:01:27 +00:00
|
|
|
/*
|
|
|
|
gl_sky.c
|
|
|
|
|
|
|
|
sky polygons
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
|
*/
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
# include "config.h"
|
|
|
|
#endif
|
2003-01-15 15:31:36 +00:00
|
|
|
|
|
|
|
static __attribute__ ((unused)) const char rcsid[] =
|
|
|
|
"$Id$";
|
|
|
|
|
2001-05-11 01:01:27 +00:00
|
|
|
#ifdef HAVE_STRING_H
|
|
|
|
# include <string.h>
|
|
|
|
#endif
|
|
|
|
#ifdef HAVE_STRINGS_H
|
|
|
|
# include <strings.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include "QF/console.h"
|
2001-05-31 03:41:35 +00:00
|
|
|
#include "QF/cvar.h"
|
2002-08-27 07:16:28 +00:00
|
|
|
#include "QF/quakefs.h"
|
2001-05-20 03:54:55 +00:00
|
|
|
#include "QF/render.h"
|
2001-12-21 01:41:19 +00:00
|
|
|
#include "QF/texture.h"
|
2001-05-11 01:01:27 +00:00
|
|
|
#include "QF/tga.h"
|
|
|
|
#include "QF/vid.h"
|
2001-06-24 09:25:55 +00:00
|
|
|
#include "QF/GL/defines.h"
|
|
|
|
#include "QF/GL/funcs.h"
|
2001-09-04 10:32:51 +00:00
|
|
|
#include "QF/GL/qf_rlight.h"
|
2001-06-24 09:25:55 +00:00
|
|
|
#include "QF/GL/qf_sky.h"
|
|
|
|
#include "QF/GL/qf_textures.h"
|
|
|
|
#include "QF/GL/qf_vid.h"
|
2001-05-11 01:01:27 +00:00
|
|
|
|
2001-08-22 11:00:25 +00:00
|
|
|
#include "compat.h"
|
2001-09-04 10:32:51 +00:00
|
|
|
#include "r_cvar.h"
|
2001-08-22 11:00:25 +00:00
|
|
|
#include "r_shared.h"
|
|
|
|
#include "view.h"
|
|
|
|
|
2003-01-06 18:28:13 +00:00
|
|
|
const char *suf[6] = { "rt", "bk", "lf", "ft", "up", "dn" };
|
2001-05-11 01:01:27 +00:00
|
|
|
int solidskytexture;
|
|
|
|
int alphaskytexture;
|
|
|
|
|
|
|
|
// Set to true if a valid skybox is loaded --KB
|
|
|
|
qboolean skyloaded = false;
|
|
|
|
|
2001-09-01 08:57:04 +00:00
|
|
|
|
2001-05-11 01:01:27 +00:00
|
|
|
void
|
|
|
|
R_LoadSkys (const char *skyname)
|
|
|
|
{
|
2001-09-01 08:57:04 +00:00
|
|
|
char name[64];
|
2001-05-11 01:01:27 +00:00
|
|
|
int i;
|
2002-08-27 07:16:28 +00:00
|
|
|
QFile *f;
|
2001-05-11 01:01:27 +00:00
|
|
|
|
|
|
|
if (strcasecmp (skyname, "none") == 0) {
|
|
|
|
skyloaded = false;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
skyloaded = true;
|
|
|
|
for (i = 0; i < 6; i++) {
|
2001-12-21 01:41:19 +00:00
|
|
|
tex_t *targa;
|
2001-05-11 01:01:27 +00:00
|
|
|
|
2001-06-26 02:26:46 +00:00
|
|
|
qfglBindTexture (GL_TEXTURE_2D, SKY_TEX + i);
|
2001-05-11 01:01:27 +00:00
|
|
|
snprintf (name, sizeof (name), "env/%s%s.tga", skyname, suf[i]);
|
|
|
|
COM_FOpenFile (name, &f);
|
|
|
|
if (!f) {
|
|
|
|
Con_DPrintf ("Couldn't load %s\n", name);
|
2002-01-11 01:26:21 +00:00
|
|
|
// also look in gfx/env, where Darkplaces looks for skies
|
2002-09-06 21:37:22 +00:00
|
|
|
snprintf (name, sizeof (name), "gfx/env/%s%s.tga", skyname,
|
|
|
|
suf[i]);
|
2002-01-11 01:26:21 +00:00
|
|
|
COM_FOpenFile (name, &f);
|
|
|
|
if (!f) {
|
|
|
|
Con_DPrintf ("Couldn't load %s\n", name);
|
|
|
|
skyloaded = false;
|
|
|
|
continue;
|
|
|
|
}
|
2001-05-11 01:01:27 +00:00
|
|
|
}
|
2001-12-21 01:41:19 +00:00
|
|
|
targa = LoadTGA (f);
|
2001-12-21 06:07:30 +00:00
|
|
|
Qclose (f);
|
2001-12-21 01:41:19 +00:00
|
|
|
|
2002-09-06 21:37:22 +00:00
|
|
|
qfglTexImage2D (GL_TEXTURE_2D, 0, gl_solid_format, targa->width,
|
|
|
|
targa->height, 0, GL_RGBA, GL_UNSIGNED_BYTE,
|
|
|
|
&targa->data);
|
2001-12-21 01:41:19 +00:00
|
|
|
|
2001-06-26 02:26:46 +00:00
|
|
|
qfglTexParameterf (GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
|
|
|
qfglTexParameterf (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
2001-05-11 01:01:27 +00:00
|
|
|
}
|
|
|
|
if (!skyloaded)
|
|
|
|
Con_Printf ("Unable to load skybox %s, using normal sky\n", skyname);
|
|
|
|
}
|
|
|
|
|
2003-01-07 22:12:54 +00:00
|
|
|
#if 0
|
|
|
|
#define ftc(x) (x * (254.0/256.0) + (1.0/256.0)) // avoid interpolation seams
|
|
|
|
#else
|
|
|
|
#define ftc(x) (x) // what seams?
|
|
|
|
#endif
|
2001-05-11 01:01:27 +00:00
|
|
|
vec5_t skyvec[6][4] = {
|
|
|
|
{
|
2001-08-22 11:00:25 +00:00
|
|
|
// right +y
|
|
|
|
{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}
|
|
|
|
},
|
2001-05-11 01:01:27 +00:00
|
|
|
{
|
2001-08-22 11:00:25 +00:00
|
|
|
// back -x
|
|
|
|
{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}
|
|
|
|
},
|
2001-05-11 01:01:27 +00:00
|
|
|
{
|
2001-08-22 11:00:25 +00:00
|
|
|
// left -y
|
|
|
|
{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}
|
|
|
|
},
|
2001-05-11 01:01:27 +00:00
|
|
|
{
|
2001-08-22 11:00:25 +00:00
|
|
|
// front +x
|
|
|
|
{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}
|
|
|
|
},
|
2001-05-11 01:01:27 +00:00
|
|
|
{
|
2001-08-22 11:00:25 +00:00
|
|
|
// up +z
|
|
|
|
{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}
|
|
|
|
},
|
2001-05-11 01:01:27 +00:00
|
|
|
{
|
2001-08-22 11:00:25 +00:00
|
|
|
// down -z
|
|
|
|
{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}
|
|
|
|
}
|
2001-05-11 01:01:27 +00:00
|
|
|
};
|
|
|
|
#undef ftc
|
|
|
|
|
2003-01-06 18:28:13 +00:00
|
|
|
static void
|
2001-05-11 01:01:27 +00:00
|
|
|
R_DrawSkyBox (void)
|
|
|
|
{
|
|
|
|
int i, j;
|
|
|
|
|
|
|
|
for (i = 0; i < 6; i++) {
|
2001-06-26 02:26:46 +00:00
|
|
|
qfglBindTexture (GL_TEXTURE_2D, SKY_TEX + i);
|
|
|
|
qfglBegin (GL_QUADS);
|
2003-01-07 22:12:54 +00:00
|
|
|
for (j = 0; j < 4; j++) {
|
|
|
|
float *v = (float *) skyvec[i][j];
|
|
|
|
|
|
|
|
qfglTexCoord2fv (v);
|
|
|
|
qfglVertex3f (r_refdef.vieworg[0] + v[2],
|
|
|
|
r_refdef.vieworg[1] + v[3],
|
|
|
|
r_refdef.vieworg[2] + v[4]);
|
|
|
|
}
|
2001-06-26 02:26:46 +00:00
|
|
|
qfglEnd ();
|
2001-05-11 01:01:27 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-01-07 22:12:54 +00:00
|
|
|
vec3_t domescale = {512.0, 512.0, 128.0};
|
2001-05-13 22:57:27 +00:00
|
|
|
|
2003-01-06 18:28:13 +00:00
|
|
|
static void
|
2001-05-11 01:01:27 +00:00
|
|
|
R_DrawSkyLayer (float s)
|
|
|
|
{
|
|
|
|
float x, y, a1x, a1y, a2x, a2y;
|
2001-09-01 08:57:04 +00:00
|
|
|
int a, b;
|
2001-05-11 01:01:27 +00:00
|
|
|
vec3_t v;
|
|
|
|
|
|
|
|
for (a = 0; a < 16; a++) {
|
|
|
|
a1x = bubble_costable[a * 2] * domescale[0];
|
|
|
|
a1y = -bubble_sintable[a * 2] * domescale[1];
|
|
|
|
a2x = bubble_costable[(a + 1) * 2] * domescale[0];
|
|
|
|
a2y = -bubble_sintable[(a + 1) * 2] * domescale[1];
|
|
|
|
|
2001-06-26 02:26:46 +00:00
|
|
|
qfglBegin (GL_TRIANGLE_STRIP);
|
|
|
|
qfglTexCoord2f (0.5 + s * (1.0 / 128.0), 0.5 + s * (1.0 / 128.0));
|
2001-09-09 21:41:35 +00:00
|
|
|
qfglVertex3f (r_refdef.vieworg[0], r_refdef.vieworg[1],
|
|
|
|
r_refdef.vieworg[2] + domescale[2]);
|
2001-05-11 01:01:27 +00:00
|
|
|
for (b = 1; b < 8; b++) {
|
2001-09-09 21:41:35 +00:00
|
|
|
x = bubble_costable[(b << 1) + 16];
|
|
|
|
y = -bubble_sintable[(b << 1) + 16];
|
2001-05-11 01:01:27 +00:00
|
|
|
|
|
|
|
v[0] = a1x * x;
|
|
|
|
v[1] = a1y * x;
|
|
|
|
v[2] = y * domescale[2];
|
2001-06-26 02:26:46 +00:00
|
|
|
qfglTexCoord2f ((v[0] + s) * (1.0 / 128.0),
|
2003-01-07 22:12:54 +00:00
|
|
|
(v[1] + s) * (1.0 / 128.0));
|
2001-08-22 11:00:25 +00:00
|
|
|
qfglVertex3f (v[0] + r_refdef.vieworg[0], v[1] +
|
|
|
|
r_refdef.vieworg[1], v[2] + r_refdef.vieworg[2]);
|
2001-05-11 01:01:27 +00:00
|
|
|
|
|
|
|
v[0] = a2x * x;
|
|
|
|
v[1] = a2y * x;
|
|
|
|
v[2] = y * domescale[2];
|
2001-06-26 02:26:46 +00:00
|
|
|
qfglTexCoord2f ((v[0] + s) * (1.0 / 128.0),
|
2003-01-07 22:12:54 +00:00
|
|
|
(v[1] + s) * (1.0 / 128.0));
|
2001-08-22 11:00:25 +00:00
|
|
|
qfglVertex3f (v[0] + r_refdef.vieworg[0], v[1] +
|
|
|
|
r_refdef.vieworg[1], v[2] + r_refdef.vieworg[2]);
|
2001-05-11 01:01:27 +00:00
|
|
|
}
|
2001-06-26 02:26:46 +00:00
|
|
|
qfglTexCoord2f (0.5 + s * (1.0 / 128.0), 0.5 + s * (1.0 / 128.0));
|
2003-01-07 22:12:54 +00:00
|
|
|
qfglVertex3f (r_refdef.vieworg[0], r_refdef.vieworg[1],
|
|
|
|
r_refdef.vieworg[2] - domescale[2]);
|
2001-06-26 02:26:46 +00:00
|
|
|
qfglEnd ();
|
2001-05-11 01:01:27 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-01-06 18:28:13 +00:00
|
|
|
static void
|
2001-05-11 01:01:27 +00:00
|
|
|
R_DrawSkyDome (void)
|
|
|
|
{
|
2001-09-03 06:12:10 +00:00
|
|
|
float speedscale; // for top sky and bottom sky
|
|
|
|
|
2001-05-11 01:01:27 +00:00
|
|
|
// base sky
|
2003-01-07 22:12:54 +00:00
|
|
|
qfglDisable (GL_BLEND);
|
2001-06-26 02:26:46 +00:00
|
|
|
qfglBindTexture (GL_TEXTURE_2D, solidskytexture);
|
2001-05-20 03:54:55 +00:00
|
|
|
speedscale = r_realtime * 8;
|
2001-05-11 01:01:27 +00:00
|
|
|
speedscale -= (int) speedscale & ~127;
|
|
|
|
R_DrawSkyLayer (speedscale);
|
2001-06-26 02:26:46 +00:00
|
|
|
qfglEnable (GL_BLEND);
|
2001-05-11 01:01:27 +00:00
|
|
|
|
|
|
|
// clouds
|
2002-10-10 19:49:36 +00:00
|
|
|
if (gl_sky_multipass->int_val) {
|
2001-06-26 02:26:46 +00:00
|
|
|
qfglBindTexture (GL_TEXTURE_2D, alphaskytexture);
|
2001-05-20 03:54:55 +00:00
|
|
|
speedscale = r_realtime * 16;
|
2001-05-11 01:01:27 +00:00
|
|
|
speedscale -= (int) speedscale & ~127;
|
|
|
|
R_DrawSkyLayer (speedscale);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-09-04 10:32:51 +00:00
|
|
|
inline void
|
2001-05-11 01:01:27 +00:00
|
|
|
R_DrawSky (void)
|
|
|
|
{
|
2003-01-07 22:12:54 +00:00
|
|
|
qfglDisable (GL_DEPTH_TEST);
|
|
|
|
qfglDepthMask (GL_FALSE);
|
2001-05-11 01:01:27 +00:00
|
|
|
if (skyloaded)
|
|
|
|
R_DrawSkyBox ();
|
|
|
|
else
|
|
|
|
R_DrawSkyDome ();
|
2003-01-07 22:12:54 +00:00
|
|
|
qfglDepthMask (GL_TRUE);
|
|
|
|
qfglEnable (GL_DEPTH_TEST);
|
2001-05-11 01:01:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
R_InitSky
|
|
|
|
|
|
|
|
A sky texture is 256*128, with the right side being a masked overlay
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
R_InitSky (texture_t *mt)
|
|
|
|
{
|
2001-09-01 08:57:04 +00:00
|
|
|
byte *src;
|
|
|
|
int i, j, p, r, g, b;
|
|
|
|
unsigned int transpix;
|
|
|
|
unsigned int trans[128 * 128];
|
2001-05-11 01:01:27 +00:00
|
|
|
unsigned int *rgba;
|
|
|
|
|
|
|
|
src = (byte *) mt + mt->offsets[0];
|
|
|
|
|
2001-09-01 08:57:04 +00:00
|
|
|
// make an average value for the back to avoid a fringe on the top level
|
2001-05-11 01:01:27 +00:00
|
|
|
|
|
|
|
r = g = b = 0;
|
|
|
|
for (i = 0; i < 128; i++)
|
|
|
|
for (j = 0; j < 128; j++) {
|
|
|
|
p = src[i * 256 + j + 128];
|
|
|
|
rgba = &d_8to24table[p];
|
|
|
|
trans[(i * 128) + j] = *rgba;
|
|
|
|
r += ((byte *) rgba)[0];
|
|
|
|
g += ((byte *) rgba)[1];
|
|
|
|
b += ((byte *) rgba)[2];
|
|
|
|
}
|
|
|
|
|
|
|
|
((byte *) & transpix)[0] = r / (128 * 128);
|
|
|
|
((byte *) & transpix)[1] = g / (128 * 128);
|
|
|
|
((byte *) & transpix)[2] = b / (128 * 128);
|
|
|
|
((byte *) & transpix)[3] = 0;
|
|
|
|
|
|
|
|
if (!solidskytexture)
|
|
|
|
solidskytexture = texture_extension_number++;
|
2001-06-26 02:26:46 +00:00
|
|
|
qfglBindTexture (GL_TEXTURE_2D, solidskytexture);
|
|
|
|
qfglTexImage2D (GL_TEXTURE_2D, 0, gl_solid_format, 128, 128, 0, GL_RGBA,
|
2002-06-15 10:52:14 +00:00
|
|
|
GL_UNSIGNED_BYTE, trans);
|
2001-06-26 02:26:46 +00:00
|
|
|
qfglTexParameterf (GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
|
|
|
qfglTexParameterf (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
2001-05-11 01:01:27 +00:00
|
|
|
|
|
|
|
for (i = 0; i < 128; i++)
|
|
|
|
for (j = 0; j < 128; j++) {
|
|
|
|
p = src[i * 256 + j];
|
|
|
|
if (p == 0)
|
|
|
|
trans[(i * 128) + j] = transpix;
|
|
|
|
else
|
|
|
|
trans[(i * 128) + j] = d_8to24table[p];
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!alphaskytexture)
|
|
|
|
alphaskytexture = texture_extension_number++;
|
2001-06-26 02:26:46 +00:00
|
|
|
qfglBindTexture (GL_TEXTURE_2D, alphaskytexture);
|
|
|
|
qfglTexImage2D (GL_TEXTURE_2D, 0, gl_alpha_format, 128, 128, 0, GL_RGBA,
|
2002-06-15 10:52:14 +00:00
|
|
|
GL_UNSIGNED_BYTE, trans);
|
2001-06-26 02:26:46 +00:00
|
|
|
qfglTexParameterf (GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
|
|
|
qfglTexParameterf (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
2001-05-11 01:01:27 +00:00
|
|
|
}
|