R_SetSkyBox
==================
*/
-int R_SetSkyBox(const char *sky)
+void R_UnloadSkyBox(void)
{
int i;
- char name[1024];
- qbyte *image_rgba;
-
- if (strcmp(sky, skyname) == 0) // no change
- return true;
-
- skyboxside[0] = skyboxside[1] = skyboxside[2] = skyboxside[3] = skyboxside[4] = skyboxside[5] = NULL;
- skyavailable_box = false;
- skyname[0] = 0;
-
- if (!sky[0])
- return true;
-
- if (strlen(sky) > 1000)
+ for (i = 0;i < 6;i++)
{
- Con_Printf ("sky name too long (%i, max is 1000)\n", strlen(sky));
- return false;
+ if (skyboxside[i])
+ R_FreeTexture(skyboxside[i]);
+ skyboxside[i] = NULL;;
}
+}
+void R_LoadSkyBox(void)
+{
+ int i;
+ char name[1024];
+ qbyte *image_rgba;
+ R_UnloadSkyBox();
+ if (!skyname[0])
+ return;
for (i = 0;i < 6;i++)
{
- sprintf (name, "env/%s%s", sky, suf[i]);
- if (!(image_rgba = loadimagepixels(name, false, 0, 0)))
+ if (snprintf(name, sizeof(name), "env/%s%s", skyname, suf[i]) >= (int)sizeof(name) || !(image_rgba = loadimagepixels(name, false, 0, 0)))
{
- sprintf (name, "gfx/env/%s%s", sky, suf[i]);
- if (!(image_rgba = loadimagepixels(name, false, 0, 0)))
+ if (snprintf(name, sizeof(name), "gfx/env/%s%s", skyname, suf[i]) >= (int)sizeof(name) || !(image_rgba = loadimagepixels(name, false, 0, 0)))
{
- Con_Printf ("Couldn't load env/%s%s or gfx/env/%s%s\n", sky, suf[i], sky, suf[i]);
+ Con_Printf ("Couldn't load env/%s%s or gfx/env/%s%s\n", skyname, suf[i], skyname, suf[i]);
continue;
}
}
skyboxside[i] = R_LoadTexture2D(skytexturepool, va("skyboxside%d", i), image_width, image_height, image_rgba, TEXTYPE_RGBA, TEXF_CLAMP | TEXF_PRECACHE, NULL);
Mem_Free(image_rgba);
}
+}
+
+int R_SetSkyBox(const char *sky)
+{
+ if (strcmp(sky, skyname) == 0) // no change
+ return true;
+
+ if (strlen(sky) > 1000)
+ {
+ Con_Printf ("sky name too long (%i, max is 1000)\n", strlen(sky));
+ return false;
+ }
+
+ skyavailable_box = false;
+ strcpy(skyname, sky);
+
+ R_UnloadSkyBox();
+ R_LoadSkyBox();
+
+ if (!skyname[0])
+ return true;
if (skyboxside[0] || skyboxside[1] || skyboxside[2] || skyboxside[3] || skyboxside[4] || skyboxside[5])
{
skyavailable_box = true;
- strcpy(skyname, sky);
return true;
}
return false;
int skyboxelements[6*2*3] =
{
- // skyside[0]
- 8, 9, 10,
- 8, 10, 11,
+ // skyside[3]
+ 0, 1, 2,
+ 0, 2, 3,
// skyside[1]
4, 5, 6,
4, 6, 7,
+ // skyside[0]
+ 8, 9, 10,
+ 8, 10, 11,
// skyside[2]
12, 13, 14,
12, 14, 15,
- // skyside[3]
- 0, 1, 2,
- 0, 2, 3,
// skyside[4]
16, 17, 18,
16, 18, 19,
{
int i;
rmeshstate_t m;
- GL_Color(r_colorscale, r_colorscale, r_colorscale, 1);
+ GL_Color(1, 1, 1, 1);
memset(&m, 0, sizeof(m));
GL_BlendFunc(GL_ONE, GL_ZERO);
GL_DepthMask(true);
{
m.tex[0] = R_GetTexture(skyboxside[i]);
R_Mesh_State_Texture(&m);
- R_Mesh_Draw(4, 2, skyboxelements + i * 6);
+ R_Mesh_Draw(6*4, 2, skyboxelements + i * 6);
}
}
Matrix4x4_CreateIdentity(&identitymatrix);
GL_VertexPointer(skysphere_vertex3f);
- GL_Color(r_colorscale, r_colorscale, r_colorscale, 1);
+ GL_Color(1, 1, 1, 1);
GL_BlendFunc(GL_ONE, GL_ZERO);
GL_DepthMask(true);
GL_DepthTest(false); // don't modify or read zbuffer
m.tex[0] = R_GetTexture(solidskytexture);
m.pointer_texcoord[0] = skysphere_texcoord2f;
R_Mesh_TextureMatrix(0, &scroll1matrix);
- if (r_colorscale == 1 && r_textureunits.integer >= 2)
+ if (r_textureunits.integer >= 2)
{
// one pass using GL_DECAL or GL_INTERPOLATE_ARB for alpha layer
// LordHavoc: note that color is not set here because it does not
matrix4x4_t skymatrix;
if (skyrendermasked)
{
- Matrix4x4_CreateTranslate(&skymatrix, r_origin[0], r_origin[1], r_origin[2]);
+ Matrix4x4_CreateTranslate(&skymatrix, r_vieworigin[0], r_vieworigin[1], r_vieworigin[2]);
R_Mesh_Matrix(&skymatrix);
if (skyrendersphere)
{
skytexturepool = R_AllocTexturePool();
solidskytexture = NULL;
alphaskytexture = NULL;
+ R_LoadSkyBox();
}
static void r_sky_shutdown(void)
{
+ R_UnloadSkyBox();
R_FreeTexturePool(&skytexturepool);
solidskytexture = NULL;
alphaskytexture = NULL;
{
Cmd_AddCommand ("loadsky", &LoadSky_f);
Cvar_RegisterVariable (&r_sky);
+ R_ResetSkyBox();
+ R_ResetQuakeSky();
R_RegisterModule("R_Sky", r_sky_start, r_sky_shutdown, r_sky_newmap);
}