2 Copyright (C) 1996-1997 Id Software, Inc.
4 This program is free software; you can redistribute it and/or
5 modify it under the terms of the GNU General Public License
6 as published by the Free Software Foundation; either version 2
7 of the License, or (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
13 See the GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
29 Grab six views for environment mapping tests
32 float CalcFov (float fov_x, float width, float height);
47 void R_Envmap_f (void)
52 byte *buffer, gamma[256];
56 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");
63 strcpy(basename, Cmd_Argv(1));
64 size = atoi(Cmd_Argv(2));
65 if (size != 128 && size != 256 && size != 512 && size != 1024)
67 Con_Printf("envmap: size must be one of 128, 256, 512, or 1024\n");
70 if (size > vid.realwidth || size > vid.realheight)
72 Con_Printf("envmap: your resolution is not big enough to render that size\n");
76 buffer = malloc(size*size*3);
79 Con_Printf("envmap: unable to allocate memory for image\n");
83 BuildGammaTable8((lighthalf && hardwaregammasupported) ? 2.0f : 1.0f, 1, 1, 0, gamma);
85 // glDrawBuffer (GL_FRONT);
86 // glReadBuffer (GL_FRONT);
87 glDrawBuffer (GL_BACK);
88 glReadBuffer (GL_BACK);
93 r_refdef.width = size;
94 r_refdef.height = size;
101 VectorCopy(envmapinfo[i].angles, r_refdef.viewangles);
102 glClearColor(0,0,0,0);
103 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // LordHavoc: clear the screen (around the view as well)
105 glReadPixels (0, 0, size, size, GL_RGB, GL_UNSIGNED_BYTE, buffer);
106 sprintf(filename, "env/%s%s.tga", basename, envmapinfo[i].name);
107 Image_GammaRemapRGB(buffer, buffer, size * size, gamma, gamma, gamma);
108 Image_WriteTGARGB_preflipped(filename, size, size, buffer);
112 glDrawBuffer (GL_BACK);
113 glReadBuffer (GL_BACK);
117 // cause refdef to be fixed
118 // vid.recalc_refdef = 1;
121 static void gl_misc_start(void)
125 static void gl_misc_shutdown(void)
129 static void gl_misc_newmap(void)
138 static void R_TimeRefresh_f (void);
139 void GL_Misc_Init (void)
141 Cmd_AddCommand ("envmap", R_Envmap_f);
142 Cmd_AddCommand ("timerefresh", R_TimeRefresh_f);
144 R_RegisterModule("GL_Misc", gl_misc_start, gl_misc_shutdown, gl_misc_newmap);
147 extern void GL_BuildLightmaps (void);
158 for (i=0 ; i<256 ; i++)
159 d_lightstylevalue[i] = 264; // normal light value
164 GL_BuildLightmaps ();
174 For program optimization
177 qboolean intimerefresh = 0;
178 static void R_TimeRefresh_f (void)
181 float start, stop, time;
184 start = Sys_DoubleTime ();
185 glDrawBuffer (GL_FRONT);
186 for (i = 0;i < 128;i++)
188 r_refdef.viewangles[0] = 0;
189 r_refdef.viewangles[1] = i/128.0*360.0;
190 r_refdef.viewangles[2] = 0;
193 glDrawBuffer (GL_BACK);
195 stop = Sys_DoubleTime ();
198 Con_Printf ("%f seconds (%f fps)\n", time, 128/time);