mirror of
https://git.code.sf.net/p/quake/quakeforge
synced 2024-11-06 13:11:20 +00:00
3715430479
The major change is that we no longer require libGL to even exist on the system at compile time for the GL targets, we dynamicly link to the libGL of choice at run time. (This probably breaks most non-linux systems, and all GL targets except -glx, some fixup will be needed.) (This also kills glquake, dead dead DEAD! GONE FOREVER! WHEE!) Some gl_draw cleanup. Commented out equake alias model occlusion test stuff, very experimental. Added the .lo and .la patterns to the .gitignore files. Some minor sbar cleanup. (We don't use the disc in use symbol for anything.)
343 lines
8.2 KiB
C
343 lines
8.2 KiB
C
/*
|
|
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
|
|
|
|
$Id$
|
|
*/
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
# include "config.h"
|
|
#endif
|
|
#ifdef HAVE_STRING_H
|
|
# include <string.h>
|
|
#endif
|
|
#ifdef HAVE_STRINGS_H
|
|
# include <strings.h>
|
|
#endif
|
|
|
|
#include "compat.h"
|
|
#include "QF/console.h"
|
|
#include "QF/cvar.h"
|
|
#include "QF/render.h"
|
|
#include "QF/tga.h"
|
|
#include "QF/vfs.h"
|
|
#include "QF/vid.h"
|
|
|
|
#include "r_shared.h"
|
|
#include "view.h"
|
|
#include "r_cvar.h"
|
|
|
|
#include "QF/GL/defines.h"
|
|
#include "QF/GL/funcs.h"
|
|
#include "QF/GL/qf_sky.h"
|
|
#include "QF/GL/qf_textures.h"
|
|
#include "QF/GL/qf_rlight.h"
|
|
#include "QF/GL/qf_vid.h"
|
|
|
|
extern model_t *loadmodel;
|
|
|
|
extern int skytexturenum;
|
|
|
|
int solidskytexture;
|
|
int alphaskytexture;
|
|
float speedscale; // for top sky and bottom sky
|
|
|
|
// Set to true if a valid skybox is loaded --KB
|
|
qboolean skyloaded = false;
|
|
|
|
|
|
char *suf[6] = { "rt", "bk", "lf", "ft", "up", "dn" };
|
|
void
|
|
R_LoadSkys (const char *skyname)
|
|
{
|
|
int i;
|
|
VFile *f;
|
|
char name[64];
|
|
|
|
if (strcasecmp (skyname, "none") == 0) {
|
|
skyloaded = false;
|
|
return;
|
|
}
|
|
|
|
skyloaded = true;
|
|
for (i = 0; i < 6; i++) {
|
|
byte *targa_rgba;
|
|
|
|
QFGL_glBindTexture (GL_TEXTURE_2D, SKY_TEX + i);
|
|
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);
|
|
skyloaded = false;
|
|
continue;
|
|
}
|
|
targa_rgba = LoadTGA (f);
|
|
|
|
QFGL_glTexImage2D (GL_TEXTURE_2D, 0, gl_solid_format, 256, 256, 0, GL_RGBA,
|
|
GL_UNSIGNED_BYTE, targa_rgba);
|
|
|
|
free (targa_rgba);
|
|
|
|
QFGL_glTexParameterf (GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
|
QFGL_glTexParameterf (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
|
}
|
|
if (!skyloaded)
|
|
Con_Printf ("Unable to load skybox %s, using normal sky\n", skyname);
|
|
}
|
|
|
|
|
|
void
|
|
R_SkyBoxPolyVec (vec5_t v)
|
|
{
|
|
// avoid interpolation seams
|
|
// s = s * (254.0/256.0) + (1.0/256.0);
|
|
// t = t * (254.0/256.0) + (1.0/256.0);
|
|
QFGL_glTexCoord2fv (v);
|
|
QFGL_glVertex3f (r_refdef.vieworg[0] + v[2],
|
|
r_refdef.vieworg[1] + v[3], r_refdef.vieworg[2] + v[4]);
|
|
}
|
|
|
|
|
|
#define ftc(x) (x * (254.0/256.0) + (1.0/256.0))
|
|
vec5_t skyvec[6][4] = {
|
|
{
|
|
// 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}
|
|
},
|
|
{
|
|
// 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}
|
|
},
|
|
{
|
|
// 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}
|
|
},
|
|
{
|
|
// 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}
|
|
},
|
|
{
|
|
// 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}
|
|
},
|
|
{
|
|
// 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}
|
|
}
|
|
};
|
|
#undef ftc
|
|
|
|
|
|
void
|
|
R_DrawSkyBox (void)
|
|
{
|
|
int i, j;
|
|
|
|
QFGL_glDisable (GL_DEPTH_TEST);
|
|
QFGL_glDepthRange (gldepthmax, gldepthmax);
|
|
for (i = 0; i < 6; i++) {
|
|
QFGL_glBindTexture (GL_TEXTURE_2D, SKY_TEX + i);
|
|
QFGL_glBegin (GL_QUADS);
|
|
for (j = 0; j < 4; j++)
|
|
R_SkyBoxPolyVec (skyvec[i][j]);
|
|
QFGL_glEnd ();
|
|
}
|
|
|
|
QFGL_glEnable (GL_DEPTH_TEST);
|
|
QFGL_glDepthRange (gldepthmin, gldepthmax);
|
|
}
|
|
|
|
|
|
vec3_t domescale;
|
|
|
|
void
|
|
R_DrawSkyLayer (float s)
|
|
{
|
|
int a, b;
|
|
float x, y, a1x, a1y, a2x, a2y;
|
|
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];
|
|
|
|
QFGL_glBegin (GL_TRIANGLE_STRIP);
|
|
QFGL_glTexCoord2f (0.5 + s * (1.0 / 128.0), 0.5 + s * (1.0 / 128.0));
|
|
QFGL_glVertex3f (r_refdef.vieworg[0],
|
|
r_refdef.vieworg[1], r_refdef.vieworg[2] + domescale[2]);
|
|
for (b = 1; b < 8; b++) {
|
|
x = bubble_costable[b * 2 + 16];
|
|
y = -bubble_sintable[b * 2 + 16];
|
|
|
|
v[0] = a1x * x;
|
|
v[1] = a1y * x;
|
|
v[2] = y * domescale[2];
|
|
QFGL_glTexCoord2f ((v[0] + s) * (1.0 / 128.0),
|
|
(v[1] + s) * (1.0 / 128.0));
|
|
QFGL_glVertex3f (v[0] + r_refdef.vieworg[0],
|
|
v[1] + r_refdef.vieworg[1], v[2] + r_refdef.vieworg[2]);
|
|
|
|
v[0] = a2x * x;
|
|
v[1] = a2y * x;
|
|
v[2] = y * domescale[2];
|
|
QFGL_glTexCoord2f ((v[0] + s) * (1.0 / 128.0),
|
|
(v[1] + s) * (1.0 / 128.0));
|
|
QFGL_glVertex3f (v[0] + r_refdef.vieworg[0],
|
|
v[1] + r_refdef.vieworg[1], v[2] + r_refdef.vieworg[2]);
|
|
}
|
|
QFGL_glTexCoord2f (0.5 + s * (1.0 / 128.0), 0.5 + s * (1.0 / 128.0));
|
|
QFGL_glVertex3f (r_refdef.vieworg[0],
|
|
r_refdef.vieworg[1], r_refdef.vieworg[2] - domescale[2]);
|
|
QFGL_glEnd ();
|
|
}
|
|
}
|
|
|
|
|
|
void
|
|
R_DrawSkyDome (void)
|
|
{
|
|
QFGL_glDisable (GL_DEPTH_TEST);
|
|
QFGL_glDepthRange (gldepthmax, gldepthmax);
|
|
|
|
QFGL_glDisable (GL_BLEND);
|
|
|
|
// base sky
|
|
QFGL_glBindTexture (GL_TEXTURE_2D, solidskytexture);
|
|
domescale[0] = 512;
|
|
domescale[1] = 512;
|
|
domescale[2] = 128;
|
|
speedscale = r_realtime * 8;
|
|
speedscale -= (int) speedscale & ~127;
|
|
R_DrawSkyLayer (speedscale);
|
|
QFGL_glEnable (GL_BLEND);
|
|
|
|
// clouds
|
|
if (gl_skymultipass->int_val) {
|
|
QFGL_glBindTexture (GL_TEXTURE_2D, alphaskytexture);
|
|
domescale[0] = 512;
|
|
domescale[1] = 512;
|
|
domescale[2] = 128;
|
|
speedscale = r_realtime * 16;
|
|
speedscale -= (int) speedscale & ~127;
|
|
R_DrawSkyLayer (speedscale);
|
|
}
|
|
|
|
QFGL_glEnable (GL_DEPTH_TEST);
|
|
QFGL_glDepthRange (gldepthmin, gldepthmax);
|
|
}
|
|
|
|
|
|
void
|
|
R_DrawSky (void)
|
|
{
|
|
if (skyloaded)
|
|
R_DrawSkyBox ();
|
|
else
|
|
R_DrawSkyDome ();
|
|
}
|
|
|
|
|
|
/*
|
|
R_InitSky
|
|
|
|
A sky texture is 256*128, with the right side being a masked overlay
|
|
*/
|
|
void
|
|
R_InitSky (texture_t *mt)
|
|
{
|
|
int i, j, p;
|
|
byte *src;
|
|
unsigned int trans[128 * 128];
|
|
unsigned int transpix;
|
|
int r, g, b;
|
|
unsigned int *rgba;
|
|
|
|
src = (byte *) mt + mt->offsets[0];
|
|
|
|
// make an average value for the back to avoid
|
|
// a fringe on the top level
|
|
|
|
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++;
|
|
QFGL_glBindTexture (GL_TEXTURE_2D, solidskytexture);
|
|
QFGL_glTexImage2D (GL_TEXTURE_2D, 0, gl_solid_format, 128, 128, 0, GL_RGBA,
|
|
GL_UNSIGNED_BYTE, trans);
|
|
QFGL_glTexParameterf (GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
|
QFGL_glTexParameterf (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
|
|
|
|
|
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++;
|
|
QFGL_glBindTexture (GL_TEXTURE_2D, alphaskytexture);
|
|
QFGL_glTexImage2D (GL_TEXTURE_2D, 0, gl_alpha_format, 128, 128, 0, GL_RGBA,
|
|
GL_UNSIGNED_BYTE, trans);
|
|
QFGL_glTexParameterf (GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
|
QFGL_glTexParameterf (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
|
}
|