mirror of
https://git.code.sf.net/p/quake/newtree
synced 2024-11-10 06:42:26 +00:00
re-indent
This commit is contained in:
parent
c60c3892e5
commit
2070b1a5a1
1 changed files with 148 additions and 157 deletions
305
source/gl_sky.c
305
source/gl_sky.c
|
@ -36,20 +36,20 @@
|
|||
#include "glquake.h"
|
||||
#include "tga.h"
|
||||
|
||||
extern double realtime;
|
||||
extern model_t *loadmodel;
|
||||
extern double realtime;
|
||||
extern model_t *loadmodel;
|
||||
|
||||
extern int skytexturenum;
|
||||
extern int skytexturenum;
|
||||
extern qboolean lighthalf;
|
||||
|
||||
int solidskytexture;
|
||||
int alphaskytexture;
|
||||
float speedscale; // for top sky and bottom sky
|
||||
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;
|
||||
qboolean skyloaded = false;
|
||||
|
||||
msurface_t *warpface;
|
||||
msurface_t *warpface;
|
||||
|
||||
|
||||
/*
|
||||
|
@ -67,25 +67,25 @@ msurface_t *warpface;
|
|||
R_LoadSkys
|
||||
==================
|
||||
*/
|
||||
char *suf[6] = {"rt", "bk", "lf", "ft", "up", "dn"};
|
||||
void R_LoadSkys (char * skyname)
|
||||
char *suf[6] = { "rt", "bk", "lf", "ft", "up", "dn" };
|
||||
void
|
||||
R_LoadSkys (char *skyname)
|
||||
{
|
||||
int i;
|
||||
QFile *f;
|
||||
char name[64];
|
||||
int i;
|
||||
QFile *f;
|
||||
char name[64];
|
||||
|
||||
if (stricmp (skyname, "none") == 0)
|
||||
{
|
||||
if (stricmp (skyname, "none") == 0) {
|
||||
skyloaded = false;
|
||||
return;
|
||||
}
|
||||
|
||||
skyloaded = true;
|
||||
for (i=0 ; i<6 ; i++) {
|
||||
byte *targa_rgba;
|
||||
for (i = 0; i < 6; i++) {
|
||||
byte *targa_rgba;
|
||||
|
||||
glBindTexture (GL_TEXTURE_2D, SKY_TEX + i);
|
||||
snprintf (name, sizeof(name),"env/%s%s.tga", skyname, suf[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);
|
||||
|
@ -94,75 +94,74 @@ void R_LoadSkys (char * skyname)
|
|||
}
|
||||
targa_rgba = LoadTGA (f);
|
||||
|
||||
glTexImage2D (GL_TEXTURE_2D, 0, gl_solid_format, 256, 256, 0, GL_RGBA, GL_UNSIGNED_BYTE, targa_rgba);
|
||||
glTexImage2D (GL_TEXTURE_2D, 0, gl_solid_format, 256, 256, 0, GL_RGBA,
|
||||
GL_UNSIGNED_BYTE, targa_rgba);
|
||||
|
||||
free (targa_rgba);
|
||||
|
||||
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
||||
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
||||
glTexParameterf (GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
||||
glTexParameterf (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
||||
}
|
||||
if (!skyloaded)
|
||||
Con_Printf ("Unable to load skybox %s, using normal sky\n",
|
||||
skyname);
|
||||
Con_Printf ("Unable to load skybox %s, using normal sky\n", skyname);
|
||||
}
|
||||
|
||||
void
|
||||
R_SkyBoxPolyVec(vec5_t v)
|
||||
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);
|
||||
// s = s * (254.0/256.0) + (1.0/256.0);
|
||||
// t = t * (254.0/256.0) + (1.0/256.0);
|
||||
glTexCoord2fv (v);
|
||||
glVertex3f (r_refdef.vieworg[0] + v[2],
|
||||
r_refdef.vieworg[1] + v[3],
|
||||
r_refdef.vieworg[2] + v[4]);
|
||||
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] = {
|
||||
vec5_t skyvec[6][4] = {
|
||||
{
|
||||
// right
|
||||
{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}
|
||||
},
|
||||
// right
|
||||
{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
|
||||
{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
|
||||
{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
|
||||
{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
|
||||
{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
|
||||
{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
|
||||
{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
|
||||
{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
|
||||
{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
|
||||
{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
|
||||
{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
|
||||
|
@ -170,71 +169,64 @@ vec5_t skyvec[6][4] = {
|
|||
void
|
||||
R_DrawSkyBox (void)
|
||||
{
|
||||
int i, j;
|
||||
int i, j;
|
||||
|
||||
glDisable (GL_DEPTH_TEST);
|
||||
glDepthRange (gldepthmax, gldepthmax);
|
||||
for (i = 0; i < 6; i++)
|
||||
{
|
||||
glBindTexture(GL_TEXTURE_2D, SKY_TEX + i);
|
||||
glBegin(GL_QUADS);
|
||||
for (i = 0; i < 6; i++) {
|
||||
glBindTexture (GL_TEXTURE_2D, SKY_TEX + i);
|
||||
glBegin (GL_QUADS);
|
||||
for (j = 0; j < 4; j++)
|
||||
R_SkyBoxPolyVec(skyvec[i][j]);
|
||||
glEnd();
|
||||
R_SkyBoxPolyVec (skyvec[i][j]);
|
||||
glEnd ();
|
||||
}
|
||||
|
||||
glEnable (GL_DEPTH_TEST);
|
||||
glDepthRange(gldepthmin, gldepthmax);
|
||||
glDepthRange (gldepthmin, gldepthmax);
|
||||
}
|
||||
|
||||
|
||||
vec3_t domescale;
|
||||
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];
|
||||
a1y = -bubble_sintable[a*2];
|
||||
a2x = bubble_costable[(a+1)*2];
|
||||
a2y = -bubble_sintable[(a+1)*2];
|
||||
int a, b;
|
||||
float x, y, a1x, a1y, a2x, a2y;
|
||||
vec3_t v;
|
||||
|
||||
for (a = 0; a < 16; a++) {
|
||||
a1x = bubble_costable[a * 2];
|
||||
a1y = -bubble_sintable[a * 2];
|
||||
a2x = bubble_costable[(a + 1) * 2];
|
||||
a2y = -bubble_sintable[(a + 1) * 2];
|
||||
|
||||
glBegin (GL_TRIANGLE_STRIP);
|
||||
glTexCoord2f(0.5 + s * (1.0 / 128.0), 0.5 + s * (1.0 / 128.0));
|
||||
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];
|
||||
glTexCoord2f (0.5 + s * (1.0 / 128.0), 0.5 + s * (1.0 / 128.0));
|
||||
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 * domescale[0];
|
||||
v[1] = a1y*x * domescale[1];
|
||||
v[2] = y * domescale[2];
|
||||
glTexCoord2f((v[0] + s) * (1.0 / 128.0),
|
||||
(v[1] + s) * (1.0 / 128.0));
|
||||
glVertex3f(v[0] + r_refdef.vieworg[0],
|
||||
v[1] + r_refdef.vieworg[1],
|
||||
v[2] + r_refdef.vieworg[2]);
|
||||
v[0] = a1x * x * domescale[0];
|
||||
v[1] = a1y * x * domescale[1];
|
||||
v[2] = y * domescale[2];
|
||||
glTexCoord2f ((v[0] + s) * (1.0 / 128.0),
|
||||
(v[1] + s) * (1.0 / 128.0));
|
||||
glVertex3f (v[0] + r_refdef.vieworg[0],
|
||||
v[1] + r_refdef.vieworg[1], v[2] + r_refdef.vieworg[2]);
|
||||
|
||||
v[0] = a2x*x * domescale[0];
|
||||
v[1] = a2y*x * domescale[1];
|
||||
v[2] = y * domescale[2];
|
||||
glTexCoord2f((v[0] + s) * (1.0 / 128.0),
|
||||
(v[1] + s) * (1.0 / 128.0));
|
||||
glVertex3f(v[0] + r_refdef.vieworg[0],
|
||||
v[1] + r_refdef.vieworg[1],
|
||||
v[2] + r_refdef.vieworg[2]);
|
||||
v[0] = a2x * x * domescale[0];
|
||||
v[1] = a2y * x * domescale[1];
|
||||
v[2] = y * domescale[2];
|
||||
glTexCoord2f ((v[0] + s) * (1.0 / 128.0),
|
||||
(v[1] + s) * (1.0 / 128.0));
|
||||
glVertex3f (v[0] + r_refdef.vieworg[0],
|
||||
v[1] + r_refdef.vieworg[1], v[2] + r_refdef.vieworg[2]);
|
||||
}
|
||||
glTexCoord2f(0.5 + s * (1.0 / 128.0), 0.5 + s * (1.0 / 128.0));
|
||||
glVertex3f(r_refdef.vieworg[0],
|
||||
r_refdef.vieworg[1],
|
||||
r_refdef.vieworg[2]-domescale[2]);
|
||||
glTexCoord2f (0.5 + s * (1.0 / 128.0), 0.5 + s * (1.0 / 128.0));
|
||||
glVertex3f (r_refdef.vieworg[0],
|
||||
r_refdef.vieworg[1], r_refdef.vieworg[2] - domescale[2]);
|
||||
glEnd ();
|
||||
}
|
||||
}
|
||||
|
@ -253,8 +245,8 @@ R_DrawSkyDome (void)
|
|||
domescale[0] = 512;
|
||||
domescale[1] = 512;
|
||||
domescale[2] = 128;
|
||||
speedscale = realtime*8;
|
||||
speedscale -= (int)speedscale & ~127;
|
||||
speedscale = realtime * 8;
|
||||
speedscale -= (int) speedscale & ~127;
|
||||
R_DrawSkyLayer (speedscale);
|
||||
glEnable (GL_BLEND);
|
||||
|
||||
|
@ -264,8 +256,8 @@ R_DrawSkyDome (void)
|
|||
domescale[0] = 512;
|
||||
domescale[1] = 512;
|
||||
domescale[2] = 128;
|
||||
speedscale = realtime*16;
|
||||
speedscale -= (int)speedscale & ~127;
|
||||
speedscale = realtime * 16;
|
||||
speedscale -= (int) speedscale & ~127;
|
||||
R_DrawSkyLayer (speedscale);
|
||||
}
|
||||
|
||||
|
@ -273,13 +265,13 @@ R_DrawSkyDome (void)
|
|||
glDepthRange (gldepthmin, gldepthmax);
|
||||
}
|
||||
|
||||
void
|
||||
R_DrawSky ( void )
|
||||
void
|
||||
R_DrawSky (void)
|
||||
{
|
||||
if (skyloaded)
|
||||
R_DrawSkyBox();
|
||||
R_DrawSkyBox ();
|
||||
else
|
||||
R_DrawSkyDome();
|
||||
R_DrawSkyDome ();
|
||||
}
|
||||
|
||||
|
||||
|
@ -287,66 +279,65 @@ R_DrawSky ( void )
|
|||
//===============================================================
|
||||
|
||||
/*
|
||||
=============
|
||||
R_InitSky
|
||||
R_InitSky
|
||||
|
||||
A sky texture is 256*128, with the right side being a masked overlay
|
||||
==============
|
||||
A sky texture is 256*128, with the right side being a masked overlay
|
||||
*/
|
||||
void R_InitSky (texture_t *mt)
|
||||
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;
|
||||
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];
|
||||
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];
|
||||
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];
|
||||
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;
|
||||
((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++;
|
||||
glBindTexture (GL_TEXTURE_2D, solidskytexture );
|
||||
glTexImage2D (GL_TEXTURE_2D, 0, gl_solid_format, 128, 128, 0, GL_RGBA, GL_UNSIGNED_BYTE, trans);
|
||||
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
||||
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
||||
glBindTexture (GL_TEXTURE_2D, solidskytexture);
|
||||
glTexImage2D (GL_TEXTURE_2D, 0, gl_solid_format, 128, 128, 0, GL_RGBA,
|
||||
GL_UNSIGNED_BYTE, trans);
|
||||
glTexParameterf (GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
||||
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];
|
||||
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;
|
||||
trans[(i * 128) + j] = transpix;
|
||||
else
|
||||
trans[(i*128) + j] = d_8to24table[p];
|
||||
trans[(i * 128) + j] = d_8to24table[p];
|
||||
}
|
||||
|
||||
if (!alphaskytexture)
|
||||
alphaskytexture = texture_extension_number++;
|
||||
glBindTexture (GL_TEXTURE_2D, alphaskytexture);
|
||||
glTexImage2D (GL_TEXTURE_2D, 0, gl_alpha_format, 128, 128, 0, GL_RGBA, GL_UNSIGNED_BYTE, trans);
|
||||
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
||||
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
||||
glTexImage2D (GL_TEXTURE_2D, 0, gl_alpha_format, 128, 128, 0, GL_RGBA,
|
||||
GL_UNSIGNED_BYTE, trans);
|
||||
glTexParameterf (GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
||||
glTexParameterf (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue