#include "quakedef.h"
-int skytexturenum;
-
-rtexture_t *solidskytexture;
-rtexture_t *alphaskytexture;
-float speedscale; // for top sky and bottom sky
-
msurface_t *warpface;
void BoundPoly (int numverts, float *verts, vec3_t mins, vec3_t maxs)
SubdividePolygon (numverts, verts[0]);
}
-
-//=========================================================
-
-
-
-rtexture_t *skyboxside[6];
-
-char skyname[256];
-
-// LordHavoc: moved LoadTGA and LoadPCX to gl_draw.c
-
-/*
-==================
-R_LoadSkyBox
-==================
-*/
-char *suf[6] = {"rt", "bk", "lf", "ft", "up", "dn"};
-void R_LoadSkyBox (void)
-{
- int i;
- char name[1024];
- byte* image_rgba;
-
- if (strlen(skyname) >= 1000)
- {
- Con_Printf ("sky name too long (%i, max is 1000)\n", strlen(skyname));
- return;
- }
- for (i=0 ; i<6 ; i++)
- {
- sprintf (name, "env/%s%s", skyname, suf[i]);
- if (!(image_rgba = loadimagepixels(name, false, 0, 0)))
- {
- sprintf (name, "gfx/env/%s%s", skyname, suf[i]);
- if (!(image_rgba = loadimagepixels(name, false, 0, 0)))
- {
- Con_Printf ("Couldn't load %s\n", name);
- continue;
- }
- }
- skyboxside[i] = R_LoadTexture(va("skyboxside%d", i), image_width, image_height, image_rgba, TEXF_RGBA | TEXF_PRECACHE);
- qfree(image_rgba);
- }
-}
-
-void R_SetSkyBox (char *sky)
-{
- strcpy(skyname, sky);
- R_LoadSkyBox ();
-}
-
-// LordHavoc: added LoadSky console command
-void LoadSky_f (void)
-{
- switch (Cmd_Argc())
- {
- case 1:
- if (skyname[0])
- Con_Printf("current sky: %s\n", skyname);
- else
- Con_Printf("no skybox has been set\n", skyname);
- break;
- case 2:
- R_SetSkyBox(Cmd_Argv(1));
- Con_Printf("skybox set to %s\n", skyname);
- break;
- default:
- Con_Printf("usage: loadsky skyname\n");
- break;
- }
-}
-
-#define R_SkyBoxPolyVec(s,t,x,y,z) \
- glTexCoord2f((s) * (254.0f/256.0f) + (1.0f/256.0f), (t) * (254.0f/256.0f) + (1.0f/256.0f));\
- glVertex3f((x) * 1024.0 + r_origin[0], (y) * 1024.0 + r_origin[1], (z) * 1024.0 + r_origin[2]);
-
-void R_SkyBox(void)
-{
- glDisable (GL_BLEND);
- glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
- if (lighthalf)
- glColor3f(0.5,0.5,0.5);
- else
- glColor3f(1,1,1);
- glBindTexture(GL_TEXTURE_2D, R_GetTexture(skyboxside[3])); // front
- glBegin(GL_QUADS);
- R_SkyBoxPolyVec(1, 0, 1, -1, 1);
- R_SkyBoxPolyVec(1, 1, 1, -1, -1);
- R_SkyBoxPolyVec(0, 1, 1, 1, -1);
- R_SkyBoxPolyVec(0, 0, 1, 1, 1);
- glEnd();
- glBindTexture(GL_TEXTURE_2D, R_GetTexture(skyboxside[1])); // back
- glBegin(GL_QUADS);
- R_SkyBoxPolyVec(1, 0, -1, 1, 1);
- R_SkyBoxPolyVec(1, 1, -1, 1, -1);
- R_SkyBoxPolyVec(0, 1, -1, -1, -1);
- R_SkyBoxPolyVec(0, 0, -1, -1, 1);
- glEnd();
- glBindTexture(GL_TEXTURE_2D, R_GetTexture(skyboxside[0])); // right
- glBegin(GL_QUADS);
- R_SkyBoxPolyVec(1, 0, 1, 1, 1);
- R_SkyBoxPolyVec(1, 1, 1, 1, -1);
- R_SkyBoxPolyVec(0, 1, -1, 1, -1);
- R_SkyBoxPolyVec(0, 0, -1, 1, 1);
- glEnd();
- glBindTexture(GL_TEXTURE_2D, R_GetTexture(skyboxside[2])); // left
- glBegin(GL_QUADS);
- R_SkyBoxPolyVec(1, 0, -1, -1, 1);
- R_SkyBoxPolyVec(1, 1, -1, -1, -1);
- R_SkyBoxPolyVec(0, 1, 1, -1, -1);
- R_SkyBoxPolyVec(0, 0, 1, -1, 1);
- glEnd();
- glBindTexture(GL_TEXTURE_2D, R_GetTexture(skyboxside[4])); // up
- glBegin(GL_QUADS);
- R_SkyBoxPolyVec(1, 0, 1, -1, 1);
- R_SkyBoxPolyVec(1, 1, 1, 1, 1);
- R_SkyBoxPolyVec(0, 1, -1, 1, 1);
- R_SkyBoxPolyVec(0, 0, -1, -1, 1);
- glEnd();
- glBindTexture(GL_TEXTURE_2D, R_GetTexture(skyboxside[5])); // down
- glBegin(GL_QUADS);
- R_SkyBoxPolyVec(1, 0, 1, 1, -1);
- R_SkyBoxPolyVec(1, 1, 1, -1, -1);
- R_SkyBoxPolyVec(0, 1, -1, -1, -1);
- R_SkyBoxPolyVec(0, 0, -1, 1, -1);
- glEnd();
-}
-
-/*
-float skydomeouter[33*33*3];
-float skydomeinner[33*33*3];
-unsigned short skydomeindices[32*66];
-qboolean skydomeinitialized = 0;
-void skydomecalc(float *dome, float dx, float dy, float dz)
-{
- float a, b, x, ax, ay;
- int i;
- unsigned short *index;
- for (a = 0;a <= 1;a += (1.0 / 32.0))
- {
- ax = cos(a * M_PI * 2);
- ay = -sin(a * M_PI * 2);
- for (b = 0;b <= 1;b += (1.0 / 32.0))
- {
- x = cos(b * M_PI * 2);
- *dome++ = ax*x * dx;
- *dome++ = ay*x * dy;
- *dome++ = -sin(b * M_PI * 2) * dz;
- }
- }
- index = skydomeindices;
- for (i = 0;i < (32*33);i++)
- {
- *index++ = i;
- *index++ = i + 33;
- }
-}
-
-void skydome(float *source, float s, float texscale)
-{
- vec_t vert[33*33][3], tex[33*33][2], *v, *t;
- int i, j;
- unsigned short *index;
- v = &vert[0][0];t = &tex[0][0];
- for (i = 0;i < (33*33);i++)
- {
- *t++ = source[0] * texscale + s;
- *t++ = source[1] * texscale + s;
- *v++ = *source++ + r_origin[0];
- *v++ = *source++ + r_origin[1];
- *v++ = *source++ + r_origin[2];
- }
- glTexCoordPointer(2, GL_FLOAT, 0, tex);
- glVertexPointer(3, GL_FLOAT, 0, vert);
- glEnableClientState(GL_TEXTURE_COORD_ARRAY);
- glEnableClientState(GL_VERTEX_ARRAY);
-// glInterleavedArrays(GL_T2F_V3F, 0, vert);
- for (i = 0;i < (32*66);i+=66)
- glDrawElements(GL_TRIANGLE_STRIP, 66, GL_UNSIGNED_SHORT, &skydomeindices[i]);
- glDisableClientState(GL_VERTEX_ARRAY);
- glDisableClientState(GL_TEXTURE_COORD_ARRAY);
-}
-
-void R_SkyDome(void)
-{
- glDisable (GL_BLEND);
- glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
- glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
- if (lighthalf)
- glColor3f(0.5,0.5,0.5);
- else
- glColor3f(1,1,1);
- glBindTexture(GL_TEXTURE_2D, solidskytexture); // upper clouds
- if (!skydomeinitialized)
- {
- skydomeinitialized = true;
- skydomecalc(skydomeouter, 1024, 1024, 256);
- skydomecalc(skydomeinner, 512, 512, 128);
- }
- speedscale = cl.time*8.0/256.0;
- speedscale -= (int)speedscale;
- skydome(skydomeouter, speedscale, 1.0 / 256.0);
- glEnable (GL_BLEND);
- glBindTexture(GL_TEXTURE_2D, alphaskytexture); // lower clouds
- speedscale = cl.time*8.0/128.0;
- speedscale -= (int)speedscale;
- skydome(skydomeinner, speedscale, 1.0 / 128.0);
- glDisable (GL_BLEND);
-}
-*/
-
-void R_Sky(void)
-{
- if (!r_render.value)
- return;
- if (!skyname[0])
- return;
- glDisable(GL_DEPTH_TEST);
- glDepthMask(0);
-// if (skyname[0])
- R_SkyBox();
-// else // classic quake sky
-// R_SkyDome();
- glDepthMask(1);
- glEnable (GL_DEPTH_TEST);
- glColor3f (1,1,1);
-}
-
-//===============================================================
-
-/*
-=============
-R_InitSky
-
-A sky texture is 256*128, with the right side being a masked overlay
-==============
-*/
-void R_InitSky (byte *src, int bytesperpixel)
-{
- int i, j, p;
- unsigned trans[128*128];
- unsigned transpix;
- int r, g, b;
- unsigned *rgba;
-
- if (bytesperpixel == 4)
- {
- for (i = 0;i < 128;i++)
- for (j = 0;j < 128;j++)
- trans[(i*128) + j] = src[i*256+j+128];
- }
- else
- {
- // 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;
- }
-
- solidskytexture = R_LoadTexture ("sky_solidtexture", 128, 128, (byte *) trans, TEXF_RGBA | TEXF_PRECACHE);
-
- if (bytesperpixel == 4)
- {
- for (i = 0;i < 128;i++)
- for (j = 0;j < 128;j++)
- trans[(i*128) + j] = src[i*256+j];
- }
- else
- {
- 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];
- }
- }
-
- alphaskytexture = R_LoadTexture ("sky_alphatexture", 128, 128, (byte *) trans, TEXF_ALPHA | TEXF_RGBA | TEXF_PRECACHE);
-}
-