]> icculus.org git repositories - divverent/darkplaces.git/blob - gl_rmisc.c
minor redesign of console loading/drawing, cruft removal, change to Draw_GenericPic...
[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 ==================
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         if (!r_render.value)
72                 return;
73
74         glDrawBuffer  (GL_FRONT);
75         glReadBuffer  (GL_FRONT);
76         envmap = true;
77
78         r_refdef.vrect.x = 0;
79         r_refdef.vrect.y = 0;
80         r_refdef.vrect.width = 256;
81         r_refdef.vrect.height = 256;
82
83         r_refdef.viewangles[0] = 0;
84         r_refdef.viewangles[1] = 0;
85         r_refdef.viewangles[2] = 0;
86         GL_BeginRendering (&glx, &gly, &glwidth, &glheight);
87         R_RenderView ();
88         glReadPixels (0, 0, 256, 256, GL_RGBA, GL_UNSIGNED_BYTE, buffer);
89         COM_WriteFile ("env0.rgb", buffer, sizeof(buffer));             
90
91         r_refdef.viewangles[1] = 90;
92         GL_BeginRendering (&glx, &gly, &glwidth, &glheight);
93         R_RenderView ();
94         glReadPixels (0, 0, 256, 256, GL_RGBA, GL_UNSIGNED_BYTE, buffer);
95         COM_WriteFile ("env1.rgb", buffer, sizeof(buffer));             
96
97         r_refdef.viewangles[1] = 180;
98         GL_BeginRendering (&glx, &gly, &glwidth, &glheight);
99         R_RenderView ();
100         glReadPixels (0, 0, 256, 256, GL_RGBA, GL_UNSIGNED_BYTE, buffer);
101         COM_WriteFile ("env2.rgb", buffer, sizeof(buffer));             
102
103         r_refdef.viewangles[1] = 270;
104         GL_BeginRendering (&glx, &gly, &glwidth, &glheight);
105         R_RenderView ();
106         glReadPixels (0, 0, 256, 256, GL_RGBA, GL_UNSIGNED_BYTE, buffer);
107         COM_WriteFile ("env3.rgb", buffer, sizeof(buffer));             
108
109         r_refdef.viewangles[0] = -90;
110         r_refdef.viewangles[1] = 0;
111         GL_BeginRendering (&glx, &gly, &glwidth, &glheight);
112         R_RenderView ();
113         glReadPixels (0, 0, 256, 256, GL_RGBA, GL_UNSIGNED_BYTE, buffer);
114         COM_WriteFile ("env4.rgb", buffer, sizeof(buffer));             
115
116         r_refdef.viewangles[0] = 90;
117         r_refdef.viewangles[1] = 0;
118         GL_BeginRendering (&glx, &gly, &glwidth, &glheight);
119         R_RenderView ();
120         glReadPixels (0, 0, 256, 256, GL_RGBA, GL_UNSIGNED_BYTE, buffer);
121         COM_WriteFile ("env5.rgb", buffer, sizeof(buffer));             
122
123         envmap = false;
124         glDrawBuffer  (GL_BACK);
125         glReadBuffer  (GL_BACK);
126         GL_EndRendering ();
127 }
128
129 void R_InitParticles (void);
130
131 void gl_misc_start()
132 {
133 }
134
135 void gl_misc_shutdown()
136 {
137 }
138
139 /*
140 ===============
141 R_Init
142 ===============
143 */
144 void GL_Misc_Init (void)
145 {       
146         Cmd_AddCommand ("timerefresh", R_TimeRefresh_f);        
147         Cmd_AddCommand ("envmap", R_Envmap_f);  
148         Cmd_AddCommand ("pointfile", R_ReadPointFile_f);        
149
150         Cvar_RegisterVariable (&r_drawentities);
151         Cvar_RegisterVariable (&r_drawviewmodel);
152         Cvar_RegisterVariable (&r_shadows);
153         Cvar_RegisterVariable (&r_wateralpha);
154         Cvar_RegisterVariable (&r_dynamic);
155         Cvar_RegisterVariable (&r_novis);
156         Cvar_RegisterVariable (&r_speeds);
157         Cvar_RegisterVariable (&r_waterripple); // LordHavoc: added waterripple
158
159         R_RegisterModule("GL_Misc", gl_misc_start, gl_misc_shutdown);
160 }
161
162 //qboolean VID_Is8bit(void);
163 //void GL_Upload8_EXT (byte *data, int width, int height,  qboolean mipmap, qboolean alpha);
164
165 void R_ClearParticles (void);
166 void GL_BuildLightmaps (void);
167
168 /*
169 ===============
170 R_NewMap
171 ===============
172 */
173 void SHOWLMP_clear();
174 void R_NewMap (void)
175 {
176         int             i;
177         
178         for (i=0 ; i<256 ; i++)
179                 d_lightstylevalue[i] = 264;             // normal light value
180
181         memset (&r_worldentity, 0, sizeof(r_worldentity));
182         r_worldentity.model = cl.worldmodel;
183         currententity = &r_worldentity;
184
185 // clear out efrags in case the level hasn't been reloaded
186 // FIXME: is this one short?
187         for (i=0 ; i<cl.worldmodel->numleafs ; i++)
188                 cl.worldmodel->leafs[i].efrags = NULL;
189                         
190         r_viewleaf = NULL;
191         R_ClearParticles ();
192
193         GL_BuildLightmaps ();
194
195         // identify sky texture
196         skytexturenum = -1;
197         for (i=0 ; i<cl.worldmodel->numtextures ; i++)
198         {
199                 if (!cl.worldmodel->textures[i])
200                         continue;
201                 if (!strncmp(cl.worldmodel->textures[i]->name,"sky",3) )
202                         skytexturenum = i;
203                 cl.worldmodel->textures[i]->texturechain = NULL;
204         }
205         SHOWLMP_clear();
206 }
207
208
209 /*
210 ====================
211 R_TimeRefresh_f
212
213 For program optimization
214 ====================
215 */
216 qboolean intimerefresh = 0;
217 void R_TimeRefresh_f (void)
218 {
219         int                     i;
220         float           start, stop, time;
221
222         intimerefresh = 1;
223         start = Sys_FloatTime ();
224         for (i=0 ; i<128 ; i++)
225         {
226                 r_refdef.viewangles[1] = i/128.0*360.0;
227                 SCR_UpdateScreen();
228         }
229
230         stop = Sys_FloatTime ();
231         intimerefresh = 0;
232         time = stop-start;
233         Con_Printf ("%f seconds (%f fps)\n", time, 128/time);
234 }
235
236