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
|
|
|
|
2001-05-11 01:01:27 +00:00
|
|
|
#ifdef HAVE_STRING_H
|
|
|
|
# include <string.h>
|
|
|
|
#endif
|
|
|
|
#ifdef HAVE_STRINGS_H
|
|
|
|
# include <strings.h>
|
|
|
|
#endif
|
|
|
|
|
2001-05-31 03:41:35 +00:00
|
|
|
#include "QF/cvar.h"
|
2003-09-04 18:46:59 +00:00
|
|
|
#include "QF/image.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"
|
2007-11-06 10:17:14 +00:00
|
|
|
#include "QF/sys.h"
|
2003-09-04 18:46:59 +00:00
|
|
|
#include "QF/va.h"
|
2001-05-11 01:01:27 +00:00
|
|
|
#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"
|
2012-02-14 08:28:09 +00:00
|
|
|
#include "r_internal.h"
|
2001-08-22 11:00:25 +00:00
|
|
|
|
2012-09-12 23:36:28 +00:00
|
|
|
// Note that the cube face names are from the perspective of looking at the
|
|
|
|
// cube from the outside on the -ve y axis with +x to the right, +y going in,
|
|
|
|
// +z up, and front is the nearest face.
|
2012-02-17 09:33:07 +00:00
|
|
|
static const char *suf[6] = { "rt", "bk", "lf", "ft", "up", "dn" };
|
2022-03-15 04:29:05 +00:00
|
|
|
GLuint gl_solidskytexture;
|
|
|
|
GLuint gl_alphaskytexture;
|
2001-05-11 01:01:27 +00:00
|
|
|
|
|
|
|
// Set to true if a valid skybox is loaded --KB
|
2012-02-17 09:33:07 +00:00
|
|
|
qboolean gl_skyloaded = false;
|
2001-05-11 01:01:27 +00:00
|
|
|
|
2001-09-01 08:57:04 +00:00
|
|
|
|
2012-02-17 09:33:07 +00:00
|
|
|
vec5_t gl_skyvec[6][4] = {
|
2003-04-04 07:00:51 +00:00
|
|
|
{
|
2012-09-12 23:36:28 +00:00
|
|
|
// right +x
|
|
|
|
{0, 0, 1024, 1024, 1024},
|
|
|
|
{0, 1, 1024, 1024, -1024},
|
|
|
|
{1, 1, 1024, -1024, -1024},
|
|
|
|
{1, 0, 1024, -1024, 1024}
|
2003-04-04 07:00:51 +00:00
|
|
|
},
|
|
|
|
{
|
2012-09-12 23:36:28 +00:00
|
|
|
// back +y
|
|
|
|
{0, 0, -1024, 1024, 1024},
|
|
|
|
{0, 1, -1024, 1024, -1024},
|
|
|
|
{1, 1, 1024, 1024, -1024},
|
|
|
|
{1, 0, 1024, 1024, 1024}
|
2003-04-04 07:00:51 +00:00
|
|
|
},
|
|
|
|
{
|
2012-09-12 23:36:28 +00:00
|
|
|
// left -x
|
|
|
|
{0, 0, -1024, -1024, 1024},
|
|
|
|
{0, 1, -1024, -1024, -1024},
|
|
|
|
{1, 1, -1024, 1024, -1024},
|
|
|
|
{1, 0, -1024, 1024, 1024}
|
2003-04-04 07:00:51 +00:00
|
|
|
},
|
|
|
|
{
|
2012-09-12 23:36:28 +00:00
|
|
|
// front -y
|
|
|
|
{0, 0, 1024, -1024, 1024},
|
|
|
|
{0, 1, 1024, -1024, -1024},
|
|
|
|
{1, 1, -1024, -1024, -1024},
|
|
|
|
{1, 0, -1024, -1024, 1024}
|
2003-04-04 07:00:51 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
// up +z
|
2012-09-12 23:36:28 +00:00
|
|
|
{0, 0, -1024, 1024, 1024},
|
|
|
|
{0, 1, 1024, 1024, 1024},
|
|
|
|
{1, 1, 1024, -1024, 1024},
|
|
|
|
{1, 0, -1024, -1024, 1024}
|
2003-04-04 07:00:51 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
// down -z
|
2012-09-12 23:36:28 +00:00
|
|
|
{0, 0, 1024, 1024, -1024},
|
|
|
|
{0, 1, -1024, 1024, -1024},
|
|
|
|
{1, 1, -1024, -1024, -1024},
|
|
|
|
{1, 0, 1024, -1024, -1024}
|
2003-04-04 07:00:51 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2012-02-18 13:28:42 +00:00
|
|
|
void
|
2012-02-22 07:32:34 +00:00
|
|
|
gl_R_LoadSkys (const char *skyname)
|
2001-05-11 01:01:27 +00:00
|
|
|
{
|
2003-09-04 18:46:59 +00:00
|
|
|
const char *name;
|
2003-12-23 22:24:48 +00:00
|
|
|
int i; // j
|
2001-05-11 01:01:27 +00:00
|
|
|
|
2010-12-10 03:50:38 +00:00
|
|
|
if (!skyname || !*skyname)
|
|
|
|
skyname = r_skyname->string;
|
|
|
|
|
2010-12-10 05:40:13 +00:00
|
|
|
if (!*skyname || strcasecmp (skyname, "none") == 0) {
|
2012-02-17 09:33:07 +00:00
|
|
|
gl_skyloaded = false;
|
2001-05-11 01:01:27 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-02-17 09:33:07 +00:00
|
|
|
gl_skyloaded = true;
|
2001-05-11 01:01:27 +00:00
|
|
|
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);
|
2004-03-15 21:45:45 +00:00
|
|
|
|
2021-01-31 07:01:20 +00:00
|
|
|
targa = LoadImage (name = va (0, "env/%s%s", skyname, suf[i]), 1);
|
2003-12-28 05:25:06 +00:00
|
|
|
if (!targa || targa->format < 3) { // FIXME Can't do PCX right now
|
2021-03-29 10:58:00 +00:00
|
|
|
Sys_MaskPrintf (SYS_dev, "Couldn't load %s\n", name);
|
2002-01-11 01:26:21 +00:00
|
|
|
// also look in gfx/env, where Darkplaces looks for skies
|
2021-01-31 07:01:20 +00:00
|
|
|
targa = LoadImage (name = va (0, "gfx/env/%s%s", skyname,
|
|
|
|
suf[i]), 1);
|
2003-09-04 18:46:59 +00:00
|
|
|
if (!targa) {
|
2021-03-29 10:58:00 +00:00
|
|
|
Sys_MaskPrintf (SYS_dev, "Couldn't load %s\n", name);
|
2012-02-17 09:33:07 +00:00
|
|
|
gl_skyloaded = false;
|
2002-01-11 01:26:21 +00:00
|
|
|
continue;
|
|
|
|
}
|
2001-05-11 01:01:27 +00:00
|
|
|
}
|
2001-12-21 01:41:19 +00:00
|
|
|
|
2003-12-28 05:25:06 +00:00
|
|
|
// FIXME need better texture loading
|
2002-09-06 21:37:22 +00:00
|
|
|
qfglTexImage2D (GL_TEXTURE_2D, 0, gl_solid_format, targa->width,
|
2003-12-28 05:25:06 +00:00
|
|
|
targa->height, 0,
|
|
|
|
targa->format == 3 ? GL_RGB : 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);
|
2012-02-17 09:33:07 +00:00
|
|
|
if (gl_Anisotropy)
|
2005-01-02 14:23:20 +00:00
|
|
|
qfglTexParameterf (GL_TEXTURE_2D, GL_TEXTURE_MAX_ANISOTROPY_EXT,
|
2012-02-17 09:33:07 +00:00
|
|
|
gl_aniso);
|
2004-03-15 21:45:45 +00:00
|
|
|
qfglTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
|
|
|
|
qfglTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
|
2003-04-04 07:00:51 +00:00
|
|
|
|
2003-12-23 22:24:48 +00:00
|
|
|
#if 0
|
2003-04-04 07:00:51 +00:00
|
|
|
for (j = 0; j < 4; j++) {
|
|
|
|
// set the texture coords to be 1/2 pixel in from the edge
|
2012-02-17 09:33:07 +00:00
|
|
|
if (gl_skyvec[i][j][0] < 0.5)
|
|
|
|
gl_skyvec[i][j][0] = 0.5 / targa->width;
|
2003-04-04 07:00:51 +00:00
|
|
|
else
|
2012-02-17 09:33:07 +00:00
|
|
|
gl_skyvec[i][j][0] = 1 - 0.5 / targa->width;
|
2003-04-04 07:00:51 +00:00
|
|
|
|
2012-02-17 09:33:07 +00:00
|
|
|
if (gl_skyvec[i][j][1] < 0.5)
|
|
|
|
gl_skyvec[i][j][1] = 0.5 / targa->height;
|
2003-04-04 07:00:51 +00:00
|
|
|
else
|
2012-02-17 09:33:07 +00:00
|
|
|
gl_skyvec[i][j][1] = 1 - 0.5 / targa->height;
|
2003-04-04 07:00:51 +00:00
|
|
|
}
|
2003-12-23 22:24:48 +00:00
|
|
|
#endif
|
2001-05-11 01:01:27 +00:00
|
|
|
}
|
2012-02-17 09:33:07 +00:00
|
|
|
if (!gl_skyloaded)
|
2007-11-06 10:17:14 +00:00
|
|
|
Sys_Printf ("Unable to load skybox %s, using normal sky\n", skyname);
|
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_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++) {
|
2012-02-17 09:33:07 +00:00
|
|
|
float *v = (float *) gl_skyvec[i][j];
|
2003-01-07 22:12:54 +00:00
|
|
|
|
|
|
|
qfglTexCoord2fv (v);
|
[renderer] Clean up use of vup/vright/vpn
This moves the common camera setup code out of the individual drivers,
and completely removes vup/vright/vpn from the non-software renderers.
This has highlighted the craziness around AngleVectors with it putting
+X forward, -Y right and +Z up. The main issue with this is it requires
a 90 degree pre-rotation about the Z axis to get the camera pointing in
the right direction, and that's for the native sw renderer (vulkan needs
a 90 degree pre-rotation about X, and gl and glsl need to invert an
axis, too), though at least it's just a matrix swizzle and vector
negation. However, it does mean the camera matrices can't be used
directly.
Also rename vpn to vfwd (still abbreviated, but fwd is much clearer in
meaning (to me, at least) than pn (plane normal, I guess, but which
way?)).
2022-03-14 00:34:24 +00:00
|
|
|
qfglVertex3f (r_refdef.frame.position[0] + v[2],
|
|
|
|
r_refdef.frame.position[1] + v[3],
|
|
|
|
r_refdef.frame.position[2] + v[4]);
|
2003-01-07 22:12:54 +00:00
|
|
|
}
|
2001-06-26 02:26:46 +00:00
|
|
|
qfglEnd ();
|
2001-05-11 01:01:27 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-02-17 09:33:07 +00:00
|
|
|
static vec3_t domescale = {2048.0, 2048.0, 512.0};
|
|
|
|
static vec3_t zenith = { 0.0, 0.0, 512.0};
|
|
|
|
static vec3_t nadir = { 0.0, 0.0, -512.0};
|
2003-04-05 07:59:29 +00:00
|
|
|
|
|
|
|
static inline void
|
|
|
|
skydome_vertex (const vec3_t v, float speedscale)
|
|
|
|
{
|
|
|
|
float length, s, t;
|
|
|
|
vec3_t dir, point;
|
|
|
|
|
|
|
|
VectorCopy (v, dir);
|
|
|
|
dir[2] *= 3.0;
|
|
|
|
|
|
|
|
length = DotProduct (dir, dir);
|
|
|
|
length = 2.953125 / sqrt (length);
|
|
|
|
|
|
|
|
dir[0] *= length;
|
|
|
|
dir[1] *= length;
|
|
|
|
|
|
|
|
s = speedscale + dir[0];
|
|
|
|
t = speedscale + dir[1];
|
|
|
|
|
[renderer] Clean up use of vup/vright/vpn
This moves the common camera setup code out of the individual drivers,
and completely removes vup/vright/vpn from the non-software renderers.
This has highlighted the craziness around AngleVectors with it putting
+X forward, -Y right and +Z up. The main issue with this is it requires
a 90 degree pre-rotation about the Z axis to get the camera pointing in
the right direction, and that's for the native sw renderer (vulkan needs
a 90 degree pre-rotation about X, and gl and glsl need to invert an
axis, too), though at least it's just a matrix swizzle and vector
negation. However, it does mean the camera matrices can't be used
directly.
Also rename vpn to vfwd (still abbreviated, but fwd is much clearer in
meaning (to me, at least) than pn (plane normal, I guess, but which
way?)).
2022-03-14 00:34:24 +00:00
|
|
|
VectorAdd (r_refdef.frame.position, v, point);
|
2003-04-05 07:59:29 +00:00
|
|
|
|
|
|
|
qfglTexCoord2f (s, t);
|
|
|
|
qfglVertex3fv (point);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
skydome_debug (void)
|
|
|
|
{
|
|
|
|
float x, y, a1x, a1y, a2x, a2y;
|
|
|
|
int a, b, h, t, i;
|
|
|
|
vec3_t v[3];
|
|
|
|
|
|
|
|
qfglDisable (GL_TEXTURE_2D);
|
|
|
|
qfglBegin (GL_LINES);
|
|
|
|
for (a = 0; a < 16; a++) {
|
2012-02-17 09:33:07 +00:00
|
|
|
a1x = gl_bubble_costable[a * 2] * domescale[0];
|
|
|
|
a1y = -gl_bubble_sintable[a * 2] * domescale[1];
|
|
|
|
a2x = gl_bubble_costable[(a + 1) * 2] * domescale[0];
|
|
|
|
a2y = -gl_bubble_sintable[(a + 1) * 2] * domescale[1];
|
2003-04-05 07:59:29 +00:00
|
|
|
|
|
|
|
h = 1;
|
|
|
|
t = 0;
|
[renderer] Clean up use of vup/vright/vpn
This moves the common camera setup code out of the individual drivers,
and completely removes vup/vright/vpn from the non-software renderers.
This has highlighted the craziness around AngleVectors with it putting
+X forward, -Y right and +Z up. The main issue with this is it requires
a 90 degree pre-rotation about the Z axis to get the camera pointing in
the right direction, and that's for the native sw renderer (vulkan needs
a 90 degree pre-rotation about X, and gl and glsl need to invert an
axis, too), though at least it's just a matrix swizzle and vector
negation. However, it does mean the camera matrices can't be used
directly.
Also rename vpn to vfwd (still abbreviated, but fwd is much clearer in
meaning (to me, at least) than pn (plane normal, I guess, but which
way?)).
2022-03-14 00:34:24 +00:00
|
|
|
VectorAdd (zenith, r_refdef.frame.position, v[0]);
|
2003-04-05 07:59:29 +00:00
|
|
|
for (b = 1; b <= 8; b++) {
|
2012-02-17 09:33:07 +00:00
|
|
|
x = gl_bubble_costable[b + 8];
|
|
|
|
y = -gl_bubble_sintable[b + 8];
|
2003-04-05 07:59:29 +00:00
|
|
|
|
|
|
|
v[h][0] = a1x * x;
|
|
|
|
v[h][1] = a1y * x;
|
|
|
|
v[h][2] = y * domescale[2];
|
[renderer] Clean up use of vup/vright/vpn
This moves the common camera setup code out of the individual drivers,
and completely removes vup/vright/vpn from the non-software renderers.
This has highlighted the craziness around AngleVectors with it putting
+X forward, -Y right and +Z up. The main issue with this is it requires
a 90 degree pre-rotation about the Z axis to get the camera pointing in
the right direction, and that's for the native sw renderer (vulkan needs
a 90 degree pre-rotation about X, and gl and glsl need to invert an
axis, too), though at least it's just a matrix swizzle and vector
negation. However, it does mean the camera matrices can't be used
directly.
Also rename vpn to vfwd (still abbreviated, but fwd is much clearer in
meaning (to me, at least) than pn (plane normal, I guess, but which
way?)).
2022-03-14 00:34:24 +00:00
|
|
|
VectorAdd (v[h], r_refdef.frame.position, v[h]);
|
2003-04-05 07:59:29 +00:00
|
|
|
for (i = t; i != h; i = (i + 1) % 3) {
|
|
|
|
qfglVertex3fv (v[i]);
|
|
|
|
qfglVertex3fv (v[h]);
|
|
|
|
}
|
|
|
|
h = (h + 1) % 3;
|
|
|
|
if (h == t)
|
|
|
|
t = (t + 1) % 3;
|
|
|
|
|
|
|
|
v[h][0] = a2x * x;
|
|
|
|
v[h][1] = a2y * x;
|
|
|
|
v[h][2] = y * domescale[2];
|
[renderer] Clean up use of vup/vright/vpn
This moves the common camera setup code out of the individual drivers,
and completely removes vup/vright/vpn from the non-software renderers.
This has highlighted the craziness around AngleVectors with it putting
+X forward, -Y right and +Z up. The main issue with this is it requires
a 90 degree pre-rotation about the Z axis to get the camera pointing in
the right direction, and that's for the native sw renderer (vulkan needs
a 90 degree pre-rotation about X, and gl and glsl need to invert an
axis, too), though at least it's just a matrix swizzle and vector
negation. However, it does mean the camera matrices can't be used
directly.
Also rename vpn to vfwd (still abbreviated, but fwd is much clearer in
meaning (to me, at least) than pn (plane normal, I guess, but which
way?)).
2022-03-14 00:34:24 +00:00
|
|
|
VectorAdd (v[h], r_refdef.frame.position, v[h]);
|
2003-04-05 07:59:29 +00:00
|
|
|
for (i = t; i != h; i = (i + 1) % 3) {
|
|
|
|
qfglVertex3fv (v[i]);
|
|
|
|
qfglVertex3fv (v[h]);
|
|
|
|
}
|
|
|
|
h = (h + 1) % 3;
|
|
|
|
if (h == t)
|
|
|
|
t = (t + 1) % 3;
|
|
|
|
}
|
|
|
|
|
|
|
|
h = 1;
|
|
|
|
t = 0;
|
[renderer] Clean up use of vup/vright/vpn
This moves the common camera setup code out of the individual drivers,
and completely removes vup/vright/vpn from the non-software renderers.
This has highlighted the craziness around AngleVectors with it putting
+X forward, -Y right and +Z up. The main issue with this is it requires
a 90 degree pre-rotation about the Z axis to get the camera pointing in
the right direction, and that's for the native sw renderer (vulkan needs
a 90 degree pre-rotation about X, and gl and glsl need to invert an
axis, too), though at least it's just a matrix swizzle and vector
negation. However, it does mean the camera matrices can't be used
directly.
Also rename vpn to vfwd (still abbreviated, but fwd is much clearer in
meaning (to me, at least) than pn (plane normal, I guess, but which
way?)).
2022-03-14 00:34:24 +00:00
|
|
|
VectorAdd (nadir, r_refdef.frame.position, v[0]);
|
2003-04-05 07:59:29 +00:00
|
|
|
for (b = 15; b >= 8; b--) {
|
2012-02-17 09:33:07 +00:00
|
|
|
x = gl_bubble_costable[b + 8];
|
|
|
|
y = -gl_bubble_sintable[b + 8];
|
2003-04-05 07:59:29 +00:00
|
|
|
|
|
|
|
v[h][0] = a2x * x;
|
|
|
|
v[h][1] = a2y * x;
|
|
|
|
v[h][2] = y * domescale[2];
|
[renderer] Clean up use of vup/vright/vpn
This moves the common camera setup code out of the individual drivers,
and completely removes vup/vright/vpn from the non-software renderers.
This has highlighted the craziness around AngleVectors with it putting
+X forward, -Y right and +Z up. The main issue with this is it requires
a 90 degree pre-rotation about the Z axis to get the camera pointing in
the right direction, and that's for the native sw renderer (vulkan needs
a 90 degree pre-rotation about X, and gl and glsl need to invert an
axis, too), though at least it's just a matrix swizzle and vector
negation. However, it does mean the camera matrices can't be used
directly.
Also rename vpn to vfwd (still abbreviated, but fwd is much clearer in
meaning (to me, at least) than pn (plane normal, I guess, but which
way?)).
2022-03-14 00:34:24 +00:00
|
|
|
VectorAdd (v[h], r_refdef.frame.position, v[h]);
|
2003-04-05 07:59:29 +00:00
|
|
|
for (i = t; i != h; i = (i + 1) % 3) {
|
|
|
|
qfglVertex3fv (v[i]);
|
|
|
|
qfglVertex3fv (v[h]);
|
|
|
|
}
|
|
|
|
h = (h + 1) % 3;
|
|
|
|
if (h == t)
|
|
|
|
t = (t + 1) % 3;
|
|
|
|
|
|
|
|
v[h][0] = a1x * x;
|
|
|
|
v[h][1] = a1y * x;
|
|
|
|
v[h][2] = y * domescale[2];
|
[renderer] Clean up use of vup/vright/vpn
This moves the common camera setup code out of the individual drivers,
and completely removes vup/vright/vpn from the non-software renderers.
This has highlighted the craziness around AngleVectors with it putting
+X forward, -Y right and +Z up. The main issue with this is it requires
a 90 degree pre-rotation about the Z axis to get the camera pointing in
the right direction, and that's for the native sw renderer (vulkan needs
a 90 degree pre-rotation about X, and gl and glsl need to invert an
axis, too), though at least it's just a matrix swizzle and vector
negation. However, it does mean the camera matrices can't be used
directly.
Also rename vpn to vfwd (still abbreviated, but fwd is much clearer in
meaning (to me, at least) than pn (plane normal, I guess, but which
way?)).
2022-03-14 00:34:24 +00:00
|
|
|
VectorAdd (v[h], r_refdef.frame.position, v[h]);
|
2003-04-05 07:59:29 +00:00
|
|
|
for (i = t; i != h; i = (i + 1) % 3) {
|
|
|
|
qfglVertex3fv (v[i]);
|
|
|
|
qfglVertex3fv (v[h]);
|
|
|
|
}
|
|
|
|
h = (h + 1) % 3;
|
|
|
|
if (h == t)
|
|
|
|
t = (t + 1) % 3;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
qfglEnd ();
|
|
|
|
qfglEnable (GL_TEXTURE_2D);
|
|
|
|
}
|
2001-05-13 22:57:27 +00:00
|
|
|
|
2003-01-06 18:28:13 +00:00
|
|
|
static void
|
2003-04-05 07:59:29 +00:00
|
|
|
R_DrawSkyLayer (float speedscale)
|
2001-05-11 01:01:27 +00:00
|
|
|
{
|
|
|
|
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++) {
|
2012-02-17 09:33:07 +00:00
|
|
|
a1x = gl_bubble_costable[a * 2] * domescale[0];
|
|
|
|
a1y = -gl_bubble_sintable[a * 2] * domescale[1];
|
|
|
|
a2x = gl_bubble_costable[(a + 1) * 2] * domescale[0];
|
|
|
|
a2y = -gl_bubble_sintable[(a + 1) * 2] * domescale[1];
|
2001-05-11 01:01:27 +00:00
|
|
|
|
2001-06-26 02:26:46 +00:00
|
|
|
qfglBegin (GL_TRIANGLE_STRIP);
|
2003-04-05 07:59:29 +00:00
|
|
|
skydome_vertex (zenith, speedscale);
|
|
|
|
for (b = 1; b <= 8; b++) {
|
2012-02-17 09:33:07 +00:00
|
|
|
x = gl_bubble_costable[b + 8];
|
|
|
|
y = -gl_bubble_sintable[b + 8];
|
2001-05-11 01:01:27 +00:00
|
|
|
|
|
|
|
v[0] = a1x * x;
|
|
|
|
v[1] = a1y * x;
|
|
|
|
v[2] = y * domescale[2];
|
2003-04-05 07:59:29 +00:00
|
|
|
skydome_vertex (v, speedscale);
|
2001-05-11 01:01:27 +00:00
|
|
|
|
|
|
|
v[0] = a2x * x;
|
|
|
|
v[1] = a2y * x;
|
|
|
|
v[2] = y * domescale[2];
|
2003-04-05 07:59:29 +00:00
|
|
|
skydome_vertex (v, speedscale);
|
|
|
|
}
|
|
|
|
qfglEnd ();
|
|
|
|
|
|
|
|
qfglBegin (GL_TRIANGLE_STRIP);
|
|
|
|
skydome_vertex (nadir, speedscale);
|
|
|
|
for (b = 15; b >= 8; b--) {
|
2012-02-17 09:33:07 +00:00
|
|
|
x = gl_bubble_costable[b + 8];
|
|
|
|
y = -gl_bubble_sintable[b + 8];
|
2003-04-05 07:59:29 +00:00
|
|
|
|
|
|
|
v[0] = a2x * x;
|
|
|
|
v[1] = a2y * x;
|
|
|
|
v[2] = y * domescale[2];
|
|
|
|
skydome_vertex (v, speedscale);
|
|
|
|
|
|
|
|
v[0] = a1x * x;
|
|
|
|
v[1] = a1y * x;
|
|
|
|
v[2] = y * domescale[2];
|
|
|
|
skydome_vertex (v, speedscale);
|
2001-05-11 01:01:27 +00:00
|
|
|
}
|
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)
|
|
|
|
{
|
2004-02-24 20:53:09 +00:00
|
|
|
float speedscale; // for top sky and bottom sky
|
2001-09-03 06:12:10 +00:00
|
|
|
|
2001-05-11 01:01:27 +00:00
|
|
|
// base sky
|
2003-01-07 22:12:54 +00:00
|
|
|
qfglDisable (GL_BLEND);
|
2012-02-17 09:33:07 +00:00
|
|
|
qfglBindTexture (GL_TEXTURE_2D, gl_solidskytexture);
|
2012-02-14 08:28:09 +00:00
|
|
|
speedscale = vr_data.realtime / 16.0;
|
2004-02-24 20:53:09 +00:00
|
|
|
speedscale -= floor (speedscale);
|
2001-05-11 01:01:27 +00:00
|
|
|
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) {
|
2012-02-17 09:33:07 +00:00
|
|
|
qfglBindTexture (GL_TEXTURE_2D, gl_alphaskytexture);
|
2012-02-14 08:28:09 +00:00
|
|
|
speedscale = vr_data.realtime / 8.0;
|
2004-02-24 20:53:09 +00:00
|
|
|
speedscale -= floor (speedscale);
|
2001-05-11 01:01:27 +00:00
|
|
|
R_DrawSkyLayer (speedscale);
|
|
|
|
}
|
2003-04-05 07:59:29 +00:00
|
|
|
if (gl_sky_debug->int_val) {
|
|
|
|
skydome_debug ();
|
|
|
|
}
|
2001-05-11 01:01:27 +00:00
|
|
|
}
|
|
|
|
|
2007-03-22 23:20:57 +00:00
|
|
|
void
|
2012-02-22 07:32:34 +00:00
|
|
|
gl_R_DrawSky (void)
|
2001-05-11 01:01:27 +00:00
|
|
|
{
|
2003-01-07 22:12:54 +00:00
|
|
|
qfglDisable (GL_DEPTH_TEST);
|
|
|
|
qfglDepthMask (GL_FALSE);
|
2012-02-17 09:33:07 +00:00
|
|
|
if (gl_skyloaded)
|
2001-05-11 01:01:27 +00:00
|
|
|
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
|
2012-02-22 07:32:34 +00:00
|
|
|
gl_R_InitSky (texture_t *mt)
|
2001-05-11 01:01:27 +00:00
|
|
|
{
|
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;
|
|
|
|
|
2022-03-15 04:29:05 +00:00
|
|
|
if (!gl_solidskytexture) {
|
|
|
|
qfglGenTextures (1, &gl_solidskytexture);
|
|
|
|
}
|
2012-02-17 09:33:07 +00:00
|
|
|
qfglBindTexture (GL_TEXTURE_2D, gl_solidskytexture);
|
2001-06-26 02:26:46 +00:00
|
|
|
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);
|
2012-02-17 09:33:07 +00:00
|
|
|
if (gl_Anisotropy)
|
2005-01-02 14:23:20 +00:00
|
|
|
qfglTexParameterf (GL_TEXTURE_2D, GL_TEXTURE_MAX_ANISOTROPY_EXT,
|
2012-02-17 09:33:07 +00:00
|
|
|
gl_aniso);
|
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];
|
|
|
|
}
|
|
|
|
|
2022-03-15 04:29:05 +00:00
|
|
|
if (!gl_alphaskytexture) {
|
|
|
|
qfglGenTextures (1, &gl_alphaskytexture);
|
|
|
|
}
|
2012-02-17 09:33:07 +00:00
|
|
|
qfglBindTexture (GL_TEXTURE_2D, gl_alphaskytexture);
|
2001-06-26 02:26:46 +00:00
|
|
|
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);
|
2012-02-17 09:33:07 +00:00
|
|
|
if (gl_Anisotropy)
|
2005-01-02 14:23:20 +00:00
|
|
|
qfglTexParameterf (GL_TEXTURE_2D, GL_TEXTURE_MAX_ANISOTROPY_EXT,
|
2012-02-17 09:33:07 +00:00
|
|
|
gl_aniso);
|
2001-05-11 01:01:27 +00:00
|
|
|
}
|