+ buffer = Mem_Alloc(tempmempool, vid.realwidth*vid.realheight*3);
+ glReadPixels (vid.realx, vid.realy, vid.realwidth, vid.realheight, GL_RGB, GL_UNSIGNED_BYTE, buffer);
+ CHECKGLERROR
+
+ // apply hardware gamma to the image
+ BuildGammaTable8((lighthalf && hardwaregammasupported) ? 2.0f : 1.0f, 1, 1, 0, gamma);
+ Image_GammaRemapRGB(buffer, buffer, vid.realwidth*vid.realheight, gamma, gamma, gamma);
+
+ Image_WriteTGARGB_preflipped(filename, vid.realwidth, vid.realheight, buffer);
+
+ Mem_Free(buffer);
+ Con_Printf ("Wrote %s\n", filename);
+}
+
+/*
+===============
+R_Envmap_f
+
+Grab six views for environment mapping tests
+===============
+*/
+float CalcFov (float fov_x, float width, float height);
+struct
+{
+ float angles[3];
+ char *name;
+}
+envmapinfo[6] =
+{
+ {{ 0, 0, 0}, "ft"},
+ {{ 0, 90, 0}, "rt"},
+ {{ 0, 180, 0}, "bk"},
+ {{ 0, 270, 0}, "lf"},
+ {{-90, 90, 0}, "up"},
+ {{ 90, 90, 0}, "dn"}
+};
+static void R_Envmap_f (void)
+{
+ int i, size;
+ char filename[256];
+ char basename[256];
+ byte *buffer, gamma[256];
+
+ if (Cmd_Argc() != 3)
+ {
+ Con_Printf ("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;
+ }
+
+ if (!r_render.integer)
+ return;
+
+ strcpy(basename, Cmd_Argv(1));
+ size = atoi(Cmd_Argv(2));
+ if (size != 128 && size != 256 && size != 512 && size != 1024)
+ {
+ Con_Printf("envmap: size must be one of 128, 256, 512, or 1024\n");
+ return;
+ }
+ if (size > vid.realwidth || size > vid.realheight)
+ {
+ Con_Printf("envmap: your resolution is not big enough to render that size\n");
+ return;
+ }
+
+ buffer = Mem_Alloc(tempmempool, size*size*3);
+ if (buffer == NULL)
+ {
+ Con_Printf("envmap: unable to allocate memory for image\n");
+ return;
+ }
+
+ BuildGammaTable8((lighthalf && hardwaregammasupported) ? 2.0f : 1.0f, 1, 1, 0, gamma);
+
+// glDrawBuffer (GL_FRONT);
+// glReadBuffer (GL_FRONT);
+ glDrawBuffer (GL_BACK);
+ glReadBuffer (GL_BACK);
+ envmap = true;