]> de.git.xonotic.org Git - xonotic/darkplaces.git/blob - gl_rmisc.c
removed cruft
[xonotic/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 ==================
28 R_InitTextures
29 ==================
30 */
31 void    R_InitTextures (void)
32 {
33         int             x,y, m;
34         byte    *dest;
35
36 // create a simple checkerboard texture for the default
37         r_notexture_mip = Hunk_AllocName (sizeof(texture_t) + 16*16+8*8+4*4+2*2, "notexture");
38         
39         r_notexture_mip->width = r_notexture_mip->height = 16;
40         r_notexture_mip->offsets[0] = sizeof(texture_t);
41         r_notexture_mip->offsets[1] = r_notexture_mip->offsets[0] + 16*16;
42         r_notexture_mip->offsets[2] = r_notexture_mip->offsets[1] + 8*8;
43         r_notexture_mip->offsets[3] = r_notexture_mip->offsets[2] + 4*4;
44         r_notexture_mip->transparent = FALSE;
45         
46         for (m=0 ; m<4 ; m++)
47         {
48                 dest = (byte *)r_notexture_mip + r_notexture_mip->offsets[m];
49                 for (y=0 ; y< (16>>m) ; y++)
50                         for (x=0 ; x< (16>>m) ; x++)
51                         {
52                                 if (  (y< (8>>m) ) ^ (x< (8>>m) ) )
53                                         *dest++ = 0;
54                                 else
55                                         *dest++ = 0xff;
56                         }
57         }       
58 }
59
60 /*
61 ===============
62 R_Envmap_f
63
64 Grab six views for environment mapping tests
65 ===============
66 */
67 void R_Envmap_f (void)
68 {
69         byte    buffer[256*256*4];
70
71         glDrawBuffer  (GL_FRONT);
72         glReadBuffer  (GL_FRONT);
73         envmap = true;
74
75         r_refdef.vrect.x = 0;
76         r_refdef.vrect.y = 0;
77         r_refdef.vrect.width = 256;
78         r_refdef.vrect.height = 256;
79
80         r_refdef.viewangles[0] = 0;
81         r_refdef.viewangles[1] = 0;
82         r_refdef.viewangles[2] = 0;
83         GL_BeginRendering (&glx, &gly, &glwidth, &glheight);
84         R_RenderView ();
85         glReadPixels (0, 0, 256, 256, GL_RGBA, GL_UNSIGNED_BYTE, buffer);
86         COM_WriteFile ("env0.rgb", buffer, sizeof(buffer));             
87
88         r_refdef.viewangles[1] = 90;
89         GL_BeginRendering (&glx, &gly, &glwidth, &glheight);
90         R_RenderView ();
91         glReadPixels (0, 0, 256, 256, GL_RGBA, GL_UNSIGNED_BYTE, buffer);
92         COM_WriteFile ("env1.rgb", buffer, sizeof(buffer));             
93
94         r_refdef.viewangles[1] = 180;
95         GL_BeginRendering (&glx, &gly, &glwidth, &glheight);
96         R_RenderView ();
97         glReadPixels (0, 0, 256, 256, GL_RGBA, GL_UNSIGNED_BYTE, buffer);
98         COM_WriteFile ("env2.rgb", buffer, sizeof(buffer));             
99
100         r_refdef.viewangles[1] = 270;
101         GL_BeginRendering (&glx, &gly, &glwidth, &glheight);
102         R_RenderView ();
103         glReadPixels (0, 0, 256, 256, GL_RGBA, GL_UNSIGNED_BYTE, buffer);
104         COM_WriteFile ("env3.rgb", buffer, sizeof(buffer));             
105
106         r_refdef.viewangles[0] = -90;
107         r_refdef.viewangles[1] = 0;
108         GL_BeginRendering (&glx, &gly, &glwidth, &glheight);
109         R_RenderView ();
110         glReadPixels (0, 0, 256, 256, GL_RGBA, GL_UNSIGNED_BYTE, buffer);
111         COM_WriteFile ("env4.rgb", buffer, sizeof(buffer));             
112
113         r_refdef.viewangles[0] = 90;
114         r_refdef.viewangles[1] = 0;
115         GL_BeginRendering (&glx, &gly, &glwidth, &glheight);
116         R_RenderView ();
117         glReadPixels (0, 0, 256, 256, GL_RGBA, GL_UNSIGNED_BYTE, buffer);
118         COM_WriteFile ("env5.rgb", buffer, sizeof(buffer));             
119
120         envmap = false;
121         glDrawBuffer  (GL_BACK);
122         glReadBuffer  (GL_BACK);
123         GL_EndRendering ();
124 }
125
126 void R_InitParticles (void);
127
128 void gl_misc_start()
129 {
130 }
131
132 void gl_misc_shutdown()
133 {
134 }
135
136 /*
137 ===============
138 R_Init
139 ===============
140 */
141 void GL_Misc_Init (void)
142 {       
143         Cmd_AddCommand ("timerefresh", R_TimeRefresh_f);        
144         Cmd_AddCommand ("envmap", R_Envmap_f);  
145         Cmd_AddCommand ("pointfile", R_ReadPointFile_f);        
146
147         Cvar_RegisterVariable (&r_drawentities);
148         Cvar_RegisterVariable (&r_drawviewmodel);
149         Cvar_RegisterVariable (&r_shadows);
150         Cvar_RegisterVariable (&r_wateralpha);
151         Cvar_RegisterVariable (&r_dynamic);
152         Cvar_RegisterVariable (&r_novis);
153         Cvar_RegisterVariable (&r_speeds);
154         Cvar_RegisterVariable (&r_waterripple); // LordHavoc: added waterripple
155
156         R_RegisterModule("GL_Misc", gl_misc_start, gl_misc_shutdown);
157 }
158
159 //qboolean VID_Is8bit(void);
160 //void GL_Upload8_EXT (byte *data, int width, int height,  qboolean mipmap, qboolean alpha);
161
162 void R_ClearParticles (void);
163 void GL_BuildLightmaps (void);
164
165 /*
166 ===============
167 R_NewMap
168 ===============
169 */
170 void SHOWLMP_clear();
171 void R_NewMap (void)
172 {
173         int             i;
174         
175         for (i=0 ; i<256 ; i++)
176                 d_lightstylevalue[i] = 264;             // normal light value
177
178         memset (&r_worldentity, 0, sizeof(r_worldentity));
179         r_worldentity.model = cl.worldmodel;
180         currententity = &r_worldentity;
181
182 // clear out efrags in case the level hasn't been reloaded
183 // FIXME: is this one short?
184         for (i=0 ; i<cl.worldmodel->numleafs ; i++)
185                 cl.worldmodel->leafs[i].efrags = NULL;
186                         
187         r_viewleaf = NULL;
188         R_ClearParticles ();
189
190         GL_BuildLightmaps ();
191
192         // identify sky texture
193         skytexturenum = -1;
194         for (i=0 ; i<cl.worldmodel->numtextures ; i++)
195         {
196                 if (!cl.worldmodel->textures[i])
197                         continue;
198                 if (!strncmp(cl.worldmodel->textures[i]->name,"sky",3) )
199                         skytexturenum = i;
200                 cl.worldmodel->textures[i]->texturechain = NULL;
201         }
202         SHOWLMP_clear();
203 }
204
205
206 /*
207 ====================
208 R_TimeRefresh_f
209
210 For program optimization
211 ====================
212 */
213 qboolean intimerefresh = 0;
214 void R_TimeRefresh_f (void)
215 {
216         int                     i;
217         float           start, stop, time;
218
219         intimerefresh = 1;
220         start = Sys_FloatTime ();
221         for (i=0 ; i<128 ; i++)
222         {
223                 r_refdef.viewangles[1] = i/128.0*360.0;
224                 SCR_UpdateScreen();
225         }
226
227         stop = Sys_FloatTime ();
228         intimerefresh = 0;
229         time = stop-start;
230         Con_Printf ("%f seconds (%f fps)\n", time, 128/time);
231 }
232
233