diff --git a/include/glquake.h b/include/glquake.h index dcd783c..0d7f371 100644 --- a/include/glquake.h +++ b/include/glquake.h @@ -259,8 +259,9 @@ void EmitWaterPolys (msurface_t *fa); void EmitSkyPolys (msurface_t *fa); void R_DrawSkyChain (msurface_t *s); void R_LoadSkys (char *); -void R_ClearSkyBox (void); -void R_DrawSkyBox (void); +//void R_ClearSkyBox (void); +//void R_DrawSkyBox (void); +void R_Sky (void); // // gl_draw.c diff --git a/source/gl_rsurf.c b/source/gl_rsurf.c index c2b301e..19893bc 100644 --- a/source/gl_rsurf.c +++ b/source/gl_rsurf.c @@ -468,17 +468,17 @@ void R_DrawSequentialPoly (msurface_t *s) // if (s->flags & SURF_DRAWSKY) { - GL_DisableMultitexture(); - glBindTexture (GL_TEXTURE_2D, solidskytexture); - speedscale = realtime*8; - speedscale -= (int)speedscale & ~127; +// GL_DisableMultitexture(); +// glBindTexture (GL_TEXTURE_2D, solidskytexture); +// speedscale = realtime*8; +// speedscale -= (int)speedscale & ~127; - EmitSkyPolys (s); +// EmitSkyPolys (s); - glBindTexture (GL_TEXTURE_2D, alphaskytexture); - speedscale = realtime*16; - speedscale -= (int)speedscale & ~127; - EmitSkyPolys (s); +// glBindTexture (GL_TEXTURE_2D, alphaskytexture); +// speedscale = realtime*16; +// speedscale -= (int)speedscale & ~127; +// EmitSkyPolys (s); return; } @@ -703,7 +703,7 @@ void R_RenderBrushPoly (msurface_t *fa) if (fa->flags & SURF_DRAWSKY) { // warp texture, no lightmaps - EmitBothSkyLayers (fa); +// EmitBothSkyLayers (fa); return; } @@ -919,7 +919,7 @@ void DrawTextureChains (void) if (skychain) { - R_DrawSkyChain(skychain); +// R_DrawSkyChain(skychain); skychain = NULL; } @@ -934,9 +934,9 @@ void DrawTextureChains (void) s = t->texturechain; if (!s) continue; - if (i == skytexturenum) +/* if (i == skytexturenum) R_DrawSkyChain (s); - else if (i == mirrortexturenum && r_mirroralpha->value != 1.0) + else*/ if (i == mirrortexturenum && r_mirroralpha->value != 1.0) { R_MirrorChain (s); continue; @@ -1211,7 +1211,8 @@ void R_DrawWorld (void) glColor3f (1.0, 1.0, 1.0); memset (lightmap_polys, 0, sizeof(lightmap_polys)); // Be sure to clear the skybox --KB - R_ClearSkyBox (); + R_Sky (); +// R_ClearSkyBox (); R_RecursiveWorldNode (cl.worldmodel->nodes); @@ -1222,10 +1223,10 @@ void R_DrawWorld (void) // Adjust the depth range and draw the skybox, ensuring it's behind // everhting else. This fixes the problem where some things are // drawn as sky when something else should be drawn. --KB - glColor3f (0.5, 0.5, 0.5); - glDepthRange (gldepthmax, gldepthmax); - R_DrawSkyBox (); - glDepthRange (gldepthmin, gldepthmax); +// glColor3f (0.5, 0.5, 0.5); +// glDepthRange (gldepthmax, gldepthmax); +// R_DrawSkyBox (); +// glDepthRange (gldepthmin, gldepthmax); } diff --git a/source/gl_warp.c b/source/gl_warp.c index 3f73b59..28e217d 100644 --- a/source/gl_warp.c +++ b/source/gl_warp.c @@ -246,9 +246,7 @@ void EmitWaterPolys (msurface_t *fa) } } - - - +#if 0 /* ============= EmitSkyPolys @@ -313,6 +311,7 @@ void EmitBothSkyLayers (msurface_t *fa) EmitSkyPolys (fa); } +#endif /* ================================================================= @@ -630,13 +629,10 @@ void R_LoadSkys (char * skyname) continue; } LoadTGA (f); -// LoadPCX (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, pcx_rgb); free (targa_rgba); -// free (pcx_rgb); glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); @@ -646,6 +642,183 @@ void R_LoadSkys (char * skyname) skyname); } +void +R_SkyBoxPolyVec(float s, float t, float x, float y, float z) +{ + // avoid interpolation seams + s = s * (254.0/256.0) + (1.0/256.0); + t = t * (254.0/256.0) + (1.0/256.0); + glTexCoord2f(s, t); + glVertex3f(r_refdef.vieworg[0] + x * 1024, + r_refdef.vieworg[1] + y * 1024, + r_refdef.vieworg[2] + z * 1024); +} + + +void R_SkyBox() +{ + GL_DisableMultitexture(); + glEnable (GL_DEPTH_TEST); + glDepthFunc (GL_ALWAYS); + glDisable (GL_BLEND); + glTexEnvf (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); + glDepthRange ((gldepthmax-gldepthmin)*0.95+gldepthmin, gldepthmax); + glColor3f (0.5, 0.5, 0.5); + + // front + glBindTexture(GL_TEXTURE_2D, SKY_TEX + 3); + 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(); + + // back + glBindTexture(GL_TEXTURE_2D, SKY_TEX + 1); + 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(); + + // right + glBindTexture(GL_TEXTURE_2D, SKY_TEX + 0); + 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(); + + // left + glBindTexture(GL_TEXTURE_2D, SKY_TEX + 2); + 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(); + + // top + glBindTexture(GL_TEXTURE_2D, SKY_TEX + 4); + 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(); + + // bottom + glBindTexture(GL_TEXTURE_2D, SKY_TEX + 5); + 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(); + + glColor3f (1,1,1); + glDepthFunc (GL_LEQUAL); + glEnable (GL_DEPTH_TEST); + glDepthRange(gldepthmin, gldepthmax); +} + + +vec3_t domescale; +void +skydome(float s) +{ + float a, b, x, y, a1x, a1y, a2x, a2y; + vec3_t v; + + for (a = 0; a < 1; a += (1.0 / 32.0)) + { + a1x = cos(a * M_PI * 2); + a1y = -sin(a * M_PI * 2); + a2x = cos((a+(1.0/32.0)) * M_PI * 2); + a2y = -sin((a+(1.0/32.0)) * M_PI * 2); + + glBegin (GL_TRIANGLE_STRIP); + for (b = 0; b <= 1; b += (1.0 / 32.0)) + { + x = cos(b * M_PI * 2); + y = -sin(b * M_PI * 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]); + } + glEnd (); + } +} + + +void +R_SkyDome() +{ + GL_DisableMultitexture(); + glEnable (GL_DEPTH_TEST); + glDepthFunc (GL_ALWAYS); + glDisable (GL_BLEND); + glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); + glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); + glDepthRange((gldepthmax-gldepthmin)*0.95+gldepthmin,gldepthmax); + glColor3f(0.5,0.5,0.5); + + // base sky + glBindTexture(GL_TEXTURE_2D, solidskytexture); + domescale[0] = 512; + domescale[1] = 512; + domescale[2] = 128; + speedscale = realtime*8; + speedscale -= (int)speedscale & ~127; + skydome(speedscale); + glEnable (GL_BLEND); + + // clouds + glBindTexture(GL_TEXTURE_2D, alphaskytexture); + domescale[0] = 512; + domescale[1] = 512; + domescale[2] = 128; + speedscale = realtime*16; + speedscale -= (int)speedscale & ~127; + skydome(speedscale); + + glDisable (GL_BLEND); + glColor3f (1,1,1); + glDepthFunc (GL_LEQUAL); + glEnable (GL_DEPTH_TEST); + glDepthRange(gldepthmin, gldepthmax); +} + +void +R_Sky ( void ) +{ + if (skyloaded) + R_SkyBox(); + else + R_SkyDome(); +} + + + +#if 0 vec3_t skyclip[6] = { {1,1,0}, @@ -991,6 +1164,7 @@ void R_DrawSkyBox (void) glEnd (); } } +#endif //===============================================================