+ 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();
+ glDepthMask(1);
+ glEnable (GL_DEPTH_TEST);
+ glColor3f (1,1,1);
+}
+
+float skysphereouter[33*33*5];
+float skysphereinner[33*33*5];
+int skysphereindices[32*32*6];
+void skyspherecalc(float *sphere, float dx, float dy, float dz)
+{
+ float a, b, x, ax, ay, v[3], length;
+ int i, j, *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);
+ v[0] = ax*x * dx;
+ v[1] = ay*x * dy;
+ v[2] = -sin(b * M_PI * 2) * dz;
+ length = 3.0f / sqrt(v[0]*v[0]+v[1]*v[1]+(v[2]*v[2]*9));
+ *sphere++ = v[0] * length;
+ *sphere++ = v[1] * length;
+ *sphere++ = v[0];
+ *sphere++ = v[1];
+ *sphere++ = v[2];
+ }
+ }
+ index = skysphereindices;
+ for (j = 0;j < 32;j++)
+ {
+ for (i = 0;i < 32;i++)
+ {
+ *index++ = j * 33 + i;
+ *index++ = j * 33 + i + 1;
+ *index++ = (j + 1) * 33 + i;
+
+ *index++ = j * 33 + i + 1;
+ *index++ = (j + 1) * 33 + i + 1;
+ *index++ = (j + 1) * 33 + i;
+ }
+ i++;
+ }
+}
+
+void skysphere(float *source, float s)
+{
+ float vert[33*33][4], tex[33*33][2], *v, *t;
+ int i;
+ v = &vert[0][0];
+ t = &tex[0][0];
+ for (i = 0;i < (33*33);i++)
+ {
+ *t++ = *source++ + s;
+ *t++ = *source++ + s;
+ *v++ = *source++ + r_origin[0];
+ *v++ = *source++ + r_origin[1];
+ *v++ = *source++ + r_origin[2];
+ *v++ = 0;
+ }
+ glTexCoordPointer(2, GL_FLOAT, sizeof(float) * 2, tex);
+ glVertexPointer(3, GL_FLOAT, sizeof(float) * 4, vert);
+ glEnableClientState(GL_TEXTURE_COORD_ARRAY);
+ glEnableClientState(GL_VERTEX_ARRAY);
+ GL_LockArray(0, 32*32*6);
+ glDrawElements(GL_TRIANGLES, 32*32*6, GL_UNSIGNED_INT, &skysphereindices[0]);
+ GL_UnlockArray();
+ glDisableClientState(GL_VERTEX_ARRAY);
+ glDisableClientState(GL_TEXTURE_COORD_ARRAY);
+}
+
+void R_SkySphere(void)
+{
+ float speedscale;
+ static qboolean skysphereinitialized = false;
+ if (!skysphereinitialized)
+ {
+ skysphereinitialized = true;
+ skyspherecalc(skysphereouter, 1024, 1024, 1024 / 3);
+ skyspherecalc(skysphereinner, 1024, 1024, 1024 / 3);
+ }
+ glDisable(GL_DEPTH_TEST);
+ glDepthMask(0);
+ 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);
+ if (r_mergesky.value)
+ {
+ glBindTexture(GL_TEXTURE_2D, R_GetTexture(mergeskytexture)); // both layers in one texture
+ speedscale = cl.time*8.0/128.0;
+ speedscale -= (int)speedscale;
+ skysphere(skysphereouter, speedscale);