+/*
+===============
+R_Envmap_f
+
+Grab six views for environment mapping tests
+===============
+*/
+struct
+{
+ float angles[3];
+ char *name;
+ qboolean flipx, flipy, flipdiagonaly;
+}
+envmapinfo[12] =
+{
+ {{ 0, 0, 0}, "rt", true, false, false},
+ {{ 0, 90, 0}, "ft", true, false, false},
+ {{ 0, 180, 0}, "lf", true, false, false},
+ {{ 0, 270, 0}, "bk", true, false, false},
+ {{-90, 180, 0}, "up", false, true, false},
+ {{ 90, 180, 0}, "dn", false, true, false},
+
+ {{ 0, 0, 0}, "px", true, true, true},
+ {{ 0, 90, 0}, "py", false, true, false},
+ {{ 0, 180, 0}, "nx", false, false, true},
+ {{ 0, 270, 0}, "ny", true, false, false},
+ {{-90, 180, 0}, "pz", false, false, true},
+ {{ 90, 180, 0}, "nz", false, false, true}
+};
+
+static void R_Envmap_f (void)
+{
+ int j, size;
+ char filename[256], basename[256];
+ qbyte *buffer1;
+ qbyte *buffer2;
+ qbyte *buffer3;
+
+ if (Cmd_Argc() != 3)
+ {
+ Con_Print("envmap <basename> <size>: save out 6 cubic environment map images, usable with loadsky, note that size must one of 128, 256, 512, or 1024 and can't be bigger than your current resolution\n");
+ return;
+ }
+
+ strlcpy (basename, Cmd_Argv(1), sizeof (basename));
+ size = atoi(Cmd_Argv(2));
+ if (size != 128 && size != 256 && size != 512 && size != 1024)
+ {
+ Con_Print("envmap: size must be one of 128, 256, 512, or 1024\n");
+ return;
+ }
+ if (size > vid.realwidth || size > vid.realheight)
+ {
+ Con_Print("envmap: your resolution is not big enough to render that size\n");
+ return;
+ }
+
+ envmap = true;
+
+ r_refdef.x = 0;
+ r_refdef.y = 0;
+ r_refdef.width = size;
+ r_refdef.height = size;
+
+ r_refdef.fov_x = 90;
+ r_refdef.fov_y = 90;
+
+ buffer1 = Mem_Alloc(tempmempool, size * size * 3);
+ buffer2 = Mem_Alloc(tempmempool, size * size * 3);
+ buffer3 = Mem_Alloc(tempmempool, size * size * 3 + 18);
+
+ for (j = 0;j < 12;j++)
+ {
+ sprintf(filename, "env/%s%s.tga", basename, envmapinfo[j].name);
+ Matrix4x4_CreateFromQuakeEntity(&r_refdef.viewentitymatrix, r_vieworigin[0], r_vieworigin[1], r_vieworigin[2], envmapinfo[j].angles[0], envmapinfo[j].angles[1], envmapinfo[j].angles[2], 1);
+ R_ClearScreen();
+ R_Mesh_Start();
+ R_RenderView();
+ R_Mesh_Finish();
+ SCR_ScreenShot(filename, buffer1, buffer2, buffer3, vid.realx, vid.realy + vid.realheight - (r_refdef.y + r_refdef.height), size, size, envmapinfo[j].flipx, envmapinfo[j].flipy, envmapinfo[j].flipdiagonaly, false);
+ }
+
+ Mem_Free (buffer1);
+ Mem_Free (buffer2);
+ Mem_Free (buffer3);
+
+ envmap = false;
+}