]> icculus.org git repositories - divverent/darkplaces.git/blob - gl_rmisc.c
fix for cvar tab completion crash
[divverent/darkplaces.git] / gl_rmisc.c
1 /*
2 Copyright (C) 1996-1997 Id Software, Inc.
3
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.
8
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.  
12
13 See the GNU General Public License for more details.
14
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.
18
19 */
20 // r_misc.c
21
22 #include "quakedef.h"
23
24
25 /*
26 ===============
27 R_Envmap_f
28
29 Grab six views for environment mapping tests
30 ===============
31 */
32 void R_Envmap_f (void)
33 {
34         byte    buffer[256*256*4];
35
36         if (!r_render.value)
37                 return;
38
39         glDrawBuffer  (GL_FRONT);
40         glReadBuffer  (GL_FRONT);
41         envmap = true;
42
43         r_refdef.vrect.x = 0;
44         r_refdef.vrect.y = 0;
45         r_refdef.vrect.width = 256;
46         r_refdef.vrect.height = 256;
47
48         r_refdef.viewangles[0] = 0;
49         r_refdef.viewangles[1] = 0;
50         r_refdef.viewangles[2] = 0;
51         R_RenderView ();
52         glReadPixels (0, 0, 256, 256, GL_RGBA, GL_UNSIGNED_BYTE, buffer);
53         COM_WriteFile ("env0.rgb", buffer, sizeof(buffer));             
54
55         r_refdef.viewangles[1] = 90;
56         R_RenderView ();
57         glReadPixels (0, 0, 256, 256, GL_RGBA, GL_UNSIGNED_BYTE, buffer);
58         COM_WriteFile ("env1.rgb", buffer, sizeof(buffer));             
59
60         r_refdef.viewangles[1] = 180;
61         R_RenderView ();
62         glReadPixels (0, 0, 256, 256, GL_RGBA, GL_UNSIGNED_BYTE, buffer);
63         COM_WriteFile ("env2.rgb", buffer, sizeof(buffer));             
64
65         r_refdef.viewangles[1] = 270;
66         GL_BeginRendering (&glx, &gly, &glwidth, &glheight);
67         R_RenderView ();
68         glReadPixels (0, 0, 256, 256, GL_RGBA, GL_UNSIGNED_BYTE, buffer);
69         COM_WriteFile ("env3.rgb", buffer, sizeof(buffer));             
70
71         r_refdef.viewangles[0] = -90;
72         r_refdef.viewangles[1] = 0;
73         R_RenderView ();
74         glReadPixels (0, 0, 256, 256, GL_RGBA, GL_UNSIGNED_BYTE, buffer);
75         COM_WriteFile ("env4.rgb", buffer, sizeof(buffer));             
76
77         r_refdef.viewangles[0] = 90;
78         r_refdef.viewangles[1] = 0;
79         R_RenderView ();
80         glReadPixels (0, 0, 256, 256, GL_RGBA, GL_UNSIGNED_BYTE, buffer);
81         COM_WriteFile ("env5.rgb", buffer, sizeof(buffer));             
82
83         envmap = false;
84         glDrawBuffer  (GL_BACK);
85         glReadBuffer  (GL_BACK);
86         GL_EndRendering ();
87 }
88
89 void R_InitParticles (void);
90
91 void gl_misc_start(void)
92 {
93 }
94
95 void gl_misc_shutdown(void)
96 {
97 }
98
99 void gl_misc_newmap(void)
100 {
101 }
102
103 /*
104 ===============
105 R_Init
106 ===============
107 */
108 void GL_Misc_Init (void)
109 {       
110         Cmd_AddCommand ("envmap", R_Envmap_f);  
111         Cmd_AddCommand ("timerefresh", R_TimeRefresh_f);        
112
113         R_RegisterModule("GL_Misc", gl_misc_start, gl_misc_shutdown, gl_misc_newmap);
114 }
115
116 extern void R_ClearParticles (void);
117 extern void GL_BuildLightmaps (void);
118
119 /*
120 ===============
121 R_NewMap
122 ===============
123 */
124 void R_NewMap (void)
125 {
126         int             i;
127         
128         for (i=0 ; i<256 ; i++)
129                 d_lightstylevalue[i] = 264;             // normal light value
130
131         r_viewleaf = NULL;
132         R_Modules_NewMap();
133
134         GL_BuildLightmaps ();
135
136         SHOWLMP_clear();
137 }
138
139
140 /*
141 ====================
142 R_TimeRefresh_f
143
144 For program optimization
145 ====================
146 */
147 qboolean intimerefresh = 0;
148 void R_TimeRefresh_f (void)
149 {
150         int                     i;
151         float           start, stop, time;
152
153         intimerefresh = 1;
154         start = Sys_DoubleTime ();
155         for (i = 0;i < 128;i++)
156         {
157                 r_refdef.viewangles[0] = 0;
158                 r_refdef.viewangles[1] = i/128.0*360.0;
159                 r_refdef.viewangles[2] = 0;
160                 SCR_UpdateScreen();
161         }
162
163         stop = Sys_DoubleTime ();
164         intimerefresh = 0;
165         time = stop-start;
166         Con_Printf ("%f seconds (%f fps)\n", time, 128/time);
167 }
168
169