]> icculus.org git repositories - divverent/darkplaces.git/blob - gl_rmain.c
you can now (try to) play in maps you don't have, and models you don't have are shown...
[divverent/darkplaces.git] / gl_rmain.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_main.c
21
22 #include "quakedef.h"
23
24 // used for dlight push checking and other things
25 int r_framecount;
26
27 mplane_t frustum[4];
28
29 int c_alias_polys, c_light_polys, c_faces, c_nodes, c_leafs, c_models, c_bmodels, c_sprites, c_particles, c_dlights;
30
31 // true during envmap command capture
32 qboolean envmap;
33
34 float r_farclip;
35
36 // view origin
37 vec3_t r_origin;
38 vec3_t vpn;
39 vec3_t vright;
40 vec3_t vup;
41
42 //
43 // screen size info
44 //
45 refdef_t r_refdef;
46
47 // 8.8 fraction of base light value
48 unsigned short d_lightstylevalue[256];
49
50 cvar_t r_drawentities = {0, "r_drawentities","1"};
51 cvar_t r_drawviewmodel = {0, "r_drawviewmodel","1"};
52 cvar_t r_speeds = {0, "r_speeds","0"};
53 cvar_t r_fullbright = {0, "r_fullbright","0"};
54 cvar_t r_wateralpha = {CVAR_SAVE, "r_wateralpha","1"};
55 cvar_t r_dynamic = {CVAR_SAVE, "r_dynamic","1"};
56 cvar_t r_fullbrights = {CVAR_SAVE, "r_fullbrights", "1"};
57
58 cvar_t gl_fogenable = {0, "gl_fogenable", "0"};
59 cvar_t gl_fogdensity = {0, "gl_fogdensity", "0.25"};
60 cvar_t gl_fogred = {0, "gl_fogred","0.3"};
61 cvar_t gl_foggreen = {0, "gl_foggreen","0.3"};
62 cvar_t gl_fogblue = {0, "gl_fogblue","0.3"};
63 cvar_t gl_fogstart = {0, "gl_fogstart", "0"};
64 cvar_t gl_fogend = {0, "gl_fogend","0"};
65
66 cvar_t r_textureunits = {0, "r_textureunits", "32"};
67
68 void R_ModulateColors(float *in, float *out, int verts, float r, float g, float b)
69 {
70         int i;
71         for (i = 0;i < verts;i++)
72         {
73                 out[0] = in[0] * r;
74                 out[1] = in[1] * g;
75                 out[2] = in[2] * b;
76                 out[3] = in[3];
77                 in += 4;
78                 out += 4;
79         }
80 }
81
82 void R_FillColors(float *out, int verts, float r, float g, float b, float a)
83 {
84         int i;
85         for (i = 0;i < verts;i++)
86         {
87                 out[0] = r;
88                 out[1] = g;
89                 out[2] = b;
90                 out[3] = a;
91                 out += 4;
92         }
93 }
94
95 /*
96 ====================
97 R_TimeRefresh_f
98
99 For program optimization
100 ====================
101 */
102 qboolean intimerefresh = 0;
103 static void R_TimeRefresh_f (void)
104 {
105         int i;
106         float start, stop, time;
107
108         intimerefresh = 1;
109         start = Sys_DoubleTime ();
110         for (i = 0;i < 128;i++)
111         {
112                 r_refdef.viewangles[0] = 0;
113                 r_refdef.viewangles[1] = i/128.0*360.0;
114                 r_refdef.viewangles[2] = 0;
115                 CL_UpdateScreen();
116         }
117
118         stop = Sys_DoubleTime ();
119         intimerefresh = 0;
120         time = stop-start;
121         Con_Printf ("%f seconds (%f fps)\n", time, 128/time);
122 }
123
124 extern cvar_t r_drawportals;
125
126 vec3_t fogcolor;
127 vec_t fogdensity;
128 float fog_density, fog_red, fog_green, fog_blue;
129 qboolean fogenabled;
130 qboolean oldgl_fogenable;
131 void R_SetupFog(void)
132 {
133         if (gamemode == GAME_NEHAHRA)
134         {
135                 if (gl_fogenable.integer)
136                 {
137                         oldgl_fogenable = true;
138                         fog_density = gl_fogdensity.value;
139                         fog_red = gl_fogred.value;
140                         fog_green = gl_foggreen.value;
141                         fog_blue = gl_fogblue.value;
142                 }
143                 else if (oldgl_fogenable)
144                 {
145                         oldgl_fogenable = false;
146                         fog_density = 0;
147                         fog_red = 0;
148                         fog_green = 0;
149                         fog_blue = 0;
150                 }
151         }
152         if (fog_density)
153         {
154                 fogcolor[0] = fog_red   = bound(0.0f, fog_red  , 1.0f);
155                 fogcolor[1] = fog_green = bound(0.0f, fog_green, 1.0f);
156                 fogcolor[2] = fog_blue  = bound(0.0f, fog_blue , 1.0f);
157         }
158         if (fog_density)
159         {
160                 fogenabled = true;
161                 fogdensity = -4000.0f / (fog_density * fog_density);
162                 // fog color was already set
163         }
164         else
165                 fogenabled = false;
166 }
167
168 // FIXME: move this to client?
169 void FOG_clear(void)
170 {
171         if (gamemode == GAME_NEHAHRA)
172         {
173                 Cvar_Set("gl_fogenable", "0");
174                 Cvar_Set("gl_fogdensity", "0.2");
175                 Cvar_Set("gl_fogred", "0.3");
176                 Cvar_Set("gl_foggreen", "0.3");
177                 Cvar_Set("gl_fogblue", "0.3");
178         }
179         fog_density = fog_red = fog_green = fog_blue = 0.0f;
180 }
181
182 // FIXME: move this to client?
183 void FOG_registercvars(void)
184 {
185         if (gamemode == GAME_NEHAHRA)
186         {
187                 Cvar_RegisterVariable (&gl_fogenable);
188                 Cvar_RegisterVariable (&gl_fogdensity);
189                 Cvar_RegisterVariable (&gl_fogred);
190                 Cvar_RegisterVariable (&gl_foggreen);
191                 Cvar_RegisterVariable (&gl_fogblue);
192                 Cvar_RegisterVariable (&gl_fogstart);
193                 Cvar_RegisterVariable (&gl_fogend);
194         }
195 }
196
197 void gl_main_start(void)
198 {
199 }
200
201 void gl_main_shutdown(void)
202 {
203 }
204
205 extern void CL_ParseEntityLump(char *entitystring);
206 void gl_main_newmap(void)
207 {
208         if (cl.worldmodel && cl.worldmodel->entities)
209                 CL_ParseEntityLump(cl.worldmodel->entities);
210         r_framecount = 1;
211 }
212
213 void GL_Main_Init(void)
214 {
215 // FIXME: move this to client?
216         FOG_registercvars();
217         Cmd_AddCommand ("timerefresh", R_TimeRefresh_f);
218         Cvar_RegisterVariable (&r_drawentities);
219         Cvar_RegisterVariable (&r_drawviewmodel);
220         Cvar_RegisterVariable (&r_speeds);
221         Cvar_RegisterVariable (&r_fullbrights);
222         Cvar_RegisterVariable (&r_wateralpha);
223         Cvar_RegisterVariable (&r_dynamic);
224         Cvar_RegisterVariable (&r_fullbright);
225         Cvar_RegisterVariable (&r_textureunits);
226         if (gamemode == GAME_NEHAHRA)
227                 Cvar_SetValue("r_fullbrights", 0);
228         R_RegisterModule("GL_Main", gl_main_start, gl_main_shutdown, gl_main_newmap);
229 }
230
231 vec3_t r_farclip_origin;
232 vec3_t r_farclip_direction;
233 vec_t r_farclip_directiondist;
234 vec_t r_farclip_meshfarclip;
235 int r_farclip_directionbit0;
236 int r_farclip_directionbit1;
237 int r_farclip_directionbit2;
238
239 // start a farclip measuring session
240 void R_FarClip_Start(vec3_t origin, vec3_t direction, vec_t startfarclip)
241 {
242         VectorCopy(origin, r_farclip_origin);
243         VectorCopy(direction, r_farclip_direction);
244         r_farclip_directiondist = DotProduct(r_farclip_origin, r_farclip_direction);
245         r_farclip_directionbit0 = r_farclip_direction[0] < 0;
246         r_farclip_directionbit1 = r_farclip_direction[1] < 0;
247         r_farclip_directionbit2 = r_farclip_direction[2] < 0;
248         r_farclip_meshfarclip = r_farclip_directiondist + startfarclip;
249 }
250
251 // enlarge farclip to accomodate box
252 void R_FarClip_Box(vec3_t mins, vec3_t maxs)
253 {
254         float d;
255         d = (r_farclip_directionbit0 ? mins[0] : maxs[0]) * r_farclip_direction[0]
256           + (r_farclip_directionbit1 ? mins[1] : maxs[1]) * r_farclip_direction[1]
257           + (r_farclip_directionbit2 ? mins[2] : maxs[2]) * r_farclip_direction[2];
258         if (r_farclip_meshfarclip < d)
259                 r_farclip_meshfarclip = d;
260 }
261
262 // return farclip value
263 float R_FarClip_Finish(void)
264 {
265         return r_farclip_meshfarclip - r_farclip_directiondist;
266 }
267
268 /*
269 ===============
270 R_NewMap
271 ===============
272 */
273 void R_NewMap (void)
274 {
275         R_Modules_NewMap();
276 }
277
278 extern void R_Textures_Init(void);
279 extern void Mod_RenderInit(void);
280 extern void GL_Draw_Init(void);
281 extern void GL_Main_Init(void);
282 extern void GL_Models_Init(void);
283 extern void R_Sky_Init(void);
284 extern void GL_Surf_Init(void);
285 extern void R_Crosshairs_Init(void);
286 extern void R_Light_Init(void);
287 extern void R_Particles_Init(void);
288 extern void R_Explosion_Init(void);
289 extern void ui_init(void);
290 extern void gl_backend_init(void);
291
292 void Render_Init(void)
293 {
294         R_Modules_Shutdown();
295         R_Textures_Init();
296         Mod_RenderInit();
297         gl_backend_init();
298         R_MeshQueue_Init();
299         GL_Draw_Init();
300         GL_Main_Init();
301         GL_Models_Init();
302         R_Sky_Init();
303         GL_Surf_Init();
304         R_Crosshairs_Init();
305         R_Light_Init();
306         R_Particles_Init();
307         R_Explosion_Init();
308         ui_init();
309         R_Modules_Start();
310 }
311
312 /*
313 ===============
314 GL_Init
315 ===============
316 */
317 extern char *ENGINE_EXTENSIONS;
318 void GL_Init (void)
319 {
320         VID_CheckExtensions();
321
322         // LordHavoc: report supported extensions
323         Con_Printf ("\nengine extensions: %s\n", ENGINE_EXTENSIONS);
324
325         qglCullFace(GL_FRONT);
326         qglEnable(GL_TEXTURE_2D);
327 }
328
329
330 //==================================================================================
331
332 static void R_MarkEntities (void)
333 {
334         int i;
335         vec3_t v;
336         entity_render_t *ent;
337
338         ent = &cl_entities[0].render;
339         Matrix4x4_CreateIdentity(&ent->matrix);
340         Matrix4x4_CreateIdentity(&ent->inversematrix);
341
342         if (cl.worldmodel)
343                 R_FarClip_Box(cl.worldmodel->normalmins, cl.worldmodel->normalmaxs);
344
345         if (!r_drawentities.integer)
346                 return;
347
348         for (i = 0;i < r_refdef.numentities;i++)
349         {
350                 ent = r_refdef.entities[i];
351                 Mod_CheckLoaded(ent->model);
352
353                 // move view-relative models to where they should be
354                 if (ent->flags & RENDER_VIEWMODEL)
355                 {
356                         // remove flag so it will not be repeated incase RelinkEntities is not called again for a while
357                         ent->flags -= RENDER_VIEWMODEL;
358                         // transform origin
359                         VectorCopy(ent->origin, v);
360                         ent->origin[0] = v[0] * vpn[0] + v[1] * vright[0] + v[2] * vup[0] + r_origin[0];
361                         ent->origin[1] = v[0] * vpn[1] + v[1] * vright[1] + v[2] * vup[1] + r_origin[1];
362                         ent->origin[2] = v[0] * vpn[2] + v[1] * vright[2] + v[2] * vup[2] + r_origin[2];
363                         // adjust angles
364                         VectorAdd(ent->angles, r_refdef.viewangles, ent->angles);
365                 }
366
367                 if (R_CullBox(ent->mins, ent->maxs))
368                         continue;
369
370                 ent->visframe = r_framecount;
371                 VectorCopy(ent->angles, v);
372                 if (!ent->model || ent->model->type != mod_brush)
373                         v[0] = -v[0];
374                 Matrix4x4_CreateFromQuakeEntity(&ent->matrix, ent->origin[0], ent->origin[1], ent->origin[2], v[0], v[1], v[2], ent->scale);
375                 Matrix4x4_Invert_Simple(&ent->inversematrix, &ent->matrix);
376                 R_LerpAnimation(ent);
377                 R_UpdateEntLights(ent);
378                 R_FarClip_Box(ent->mins, ent->maxs);
379         }
380 }
381
382 // only used if skyrendermasked, and normally returns false
383 int R_DrawBrushModelsSky (void)
384 {
385         int i, sky;
386         entity_render_t *ent;
387
388         if (!r_drawentities.integer)
389                 return false;
390
391         sky = false;
392         for (i = 0;i < r_refdef.numentities;i++)
393         {
394                 ent = r_refdef.entities[i];
395                 if (ent->visframe == r_framecount && ent->model && ent->model->DrawSky)
396                 {
397                         ent->model->DrawSky(ent);
398                         sky = true;
399                 }
400         }
401         return sky;
402 }
403
404 void R_DrawNoModel(entity_render_t *ent);
405 void R_DrawModels (void)
406 {
407         int i;
408         entity_render_t *ent;
409
410         if (!r_drawentities.integer)
411                 return;
412
413         for (i = 0;i < r_refdef.numentities;i++)
414         {
415                 ent = r_refdef.entities[i];
416                 if (ent->visframe == r_framecount)
417                 {
418                         if (ent->model)
419                         {
420                                 if (ent->model->Draw)
421                                         ent->model->Draw(ent);
422                         }
423                         else
424                                 R_DrawNoModel(ent);
425                 }
426         }
427 }
428
429 /*
430 =============
431 R_DrawViewModel
432 =============
433 */
434 void R_DrawViewModel (void)
435 {
436         entity_render_t *ent;
437
438         // FIXME: move these checks to client
439         if (!r_drawviewmodel.integer || chase_active.integer || envmap || !r_drawentities.integer || cl.items & IT_INVISIBILITY || cl.stats[STAT_HEALTH] <= 0 || !cl.viewent.render.model)
440                 return;
441
442         ent = &cl.viewent.render;
443         Mod_CheckLoaded(ent->model);
444         R_LerpAnimation(ent);
445         Matrix4x4_CreateFromQuakeEntity(&ent->matrix, ent->origin[0], ent->origin[1], ent->origin[2], -ent->angles[0], ent->angles[1], ent->angles[2], ent->scale);
446         Matrix4x4_Invert_Simple(&ent->inversematrix, &ent->matrix);
447         R_UpdateEntLights(ent);
448         ent->model->Draw(ent);
449 }
450
451 static void R_SetFrustum (void)
452 {
453         int i;
454
455         // LordHavoc: note to all quake engine coders, the special case for 90
456         // degrees assumed a square view (wrong), so I removed it, Quake2 has it
457         // disabled as well.
458         // rotate VPN right by FOV_X/2 degrees
459         RotatePointAroundVector( frustum[0].normal, vup, vpn, -(90-r_refdef.fov_x / 2 ) );
460         // rotate VPN left by FOV_X/2 degrees
461         RotatePointAroundVector( frustum[1].normal, vup, vpn, 90-r_refdef.fov_x / 2 );
462         // rotate VPN up by FOV_X/2 degrees
463         RotatePointAroundVector( frustum[2].normal, vright, vpn, 90-r_refdef.fov_y / 2 );
464         // rotate VPN down by FOV_X/2 degrees
465         RotatePointAroundVector( frustum[3].normal, vright, vpn, -( 90 - r_refdef.fov_y / 2 ) );
466
467         for (i = 0;i < 4;i++)
468         {
469                 frustum[i].type = PLANE_ANYZ;
470                 frustum[i].dist = DotProduct (r_origin, frustum[i].normal);
471                 PlaneClassify(&frustum[i]);
472         }
473 }
474
475 /*
476 ===============
477 R_SetupFrame
478 ===============
479 */
480 static void R_SetupFrame (void)
481 {
482 // don't allow cheats in multiplayer
483         if (cl.maxclients > 1)
484         {
485                 if (r_fullbright.integer != 0)
486                         Cvar_Set ("r_fullbright", "0");
487                 if (r_ambient.value != 0)
488                         Cvar_Set ("r_ambient", "0");
489         }
490
491         r_framecount++;
492
493 // build the transformation matrix for the given view angles
494         VectorCopy (r_refdef.vieworg, r_origin);
495
496         AngleVectors (r_refdef.viewangles, vpn, vright, vup);
497
498         R_AnimateLight ();
499 }
500
501
502 static void R_BlendView(void)
503 {
504         rmeshbufferinfo_t m;
505         float r;
506
507         if (r_refdef.viewblend[3] < 0.01f)
508                 return;
509
510         memset(&m, 0, sizeof(m));
511         m.blendfunc1 = GL_SRC_ALPHA;
512         m.blendfunc2 = GL_ONE_MINUS_SRC_ALPHA;
513         m.depthdisable = true; // magic
514         m.numtriangles = 1;
515         m.numverts = 3;
516         Matrix4x4_CreateIdentity(&m.matrix);
517         if (R_Mesh_Draw_GetBuffer(&m, false))
518         {
519                 m.index[0] = 0;
520                 m.index[1] = 1;
521                 m.index[2] = 2;
522                 m.color[0] = m.color[4] = m.color[8] = r_refdef.viewblend[0];
523                 m.color[1] = m.color[5] = m.color[9] = r_refdef.viewblend[1];
524                 m.color[2] = m.color[6] = m.color[10] = r_refdef.viewblend[2];
525                 m.color[3] = m.color[7] = m.color[11] = r_refdef.viewblend[3];
526                 r = 64000;
527                 m.vertex[0] = r_origin[0] + vpn[0] * 1.5 - vright[0] * r - vup[0] * r;
528                 m.vertex[1] = r_origin[1] + vpn[1] * 1.5 - vright[1] * r - vup[1] * r;
529                 m.vertex[2] = r_origin[2] + vpn[2] * 1.5 - vright[2] * r - vup[2] * r;
530                 r *= 3;
531                 m.vertex[4] = m.vertex[0] + vup[0] * r;
532                 m.vertex[5] = m.vertex[1] + vup[1] * r;
533                 m.vertex[6] = m.vertex[2] + vup[2] * r;
534                 m.vertex[8] = m.vertex[0] + vright[0] * r;
535                 m.vertex[9] = m.vertex[1] + vright[1] * r;
536                 m.vertex[10] = m.vertex[2] + vright[2] * r;
537                 R_Mesh_Render();
538         }
539 }
540
541 /*
542 ================
543 R_RenderView
544
545 r_refdef must be set before the first call
546 ================
547 */
548 void R_RenderView (void)
549 {
550         entity_render_t *world;
551         if (!r_refdef.entities/* || !cl.worldmodel*/)
552                 return; //Host_Error ("R_RenderView: NULL worldmodel");
553
554         world = &cl_entities[0].render;
555
556         // FIXME: move to client
557         R_MoveExplosions();
558         R_TimeReport("mexplosion");
559
560         R_Textures_Frame();
561         R_SetupFrame();
562         R_SetFrustum();
563         R_SetupFog();
564         R_SkyStartFrame();
565         R_BuildLightList();
566         R_TimeReport("setup");
567
568         R_FarClip_Start(r_origin, vpn, 768.0f);
569         R_MarkEntities();
570         r_farclip = R_FarClip_Finish() + 256.0f;
571         R_TimeReport("markentity");
572
573         R_Mesh_Start(r_farclip);
574         R_MeshQueue_BeginScene();
575
576         if (R_DrawBrushModelsSky())
577                 R_TimeReport("bmodelsky");
578
579         if (world->model)
580         {
581                 R_DrawWorld(world);
582                 R_TimeReport("worldnode");
583
584                 R_SurfMarkLights(world);
585                 R_TimeReport("marklights");
586
587                 R_PrepareSurfaces(world);
588                 R_TimeReport("surfprep");
589
590                 R_DrawSurfaces(world, SHADERSTAGE_SKY);
591                 R_DrawSurfaces(world, SHADERSTAGE_NORMAL);
592                 R_TimeReport("surfdraw");
593
594                 if (r_drawportals.integer)
595                 {
596                         R_DrawPortals(world);
597                         R_TimeReport("portals");
598                 }
599         }
600
601         // don't let sound skip if going slow
602         if (!intimerefresh && !r_speeds.integer)
603                 S_ExtraUpdate ();
604
605         R_DrawViewModel();
606         R_TimeReport("viewmodel");
607
608         R_DrawModels();
609         R_TimeReport("models");
610
611         R_DrawParticles();
612         R_TimeReport("particles");
613
614         R_DrawExplosions();
615         R_TimeReport("explosions");
616
617         R_MeshQueue_RenderTransparent();
618         R_TimeReport("addtrans");
619
620         R_DrawCoronas();
621         R_TimeReport("coronas");
622
623         R_DrawCrosshair();
624         R_TimeReport("crosshair");
625
626         R_BlendView();
627         R_TimeReport("blendview");
628
629         R_MeshQueue_Render();
630         R_MeshQueue_EndScene();
631         R_Mesh_Finish();
632         R_TimeReport("meshfinish");
633 }
634
635 void R_DrawBBoxMesh(vec3_t mins, vec3_t maxs, float cr, float cg, float cb, float ca)
636 {
637         int i;
638         float *v, *c, f1, f2, diff[3];
639         rmeshbufferinfo_t m;
640         m.numtriangles = 12;
641         m.numverts = 8;
642         m.blendfunc1 = GL_SRC_ALPHA;
643         m.blendfunc2 = GL_ONE_MINUS_SRC_ALPHA;
644         Matrix4x4_CreateIdentity(&m.matrix);
645         if (R_Mesh_Draw_GetBuffer(&m, false))
646         {
647                 m.vertex[ 0] = mins[0];m.vertex[ 1] = mins[1];m.vertex[ 2] = mins[2];
648                 m.vertex[ 4] = maxs[0];m.vertex[ 5] = mins[1];m.vertex[ 6] = mins[2];
649                 m.vertex[ 8] = mins[0];m.vertex[ 9] = maxs[1];m.vertex[10] = mins[2];
650                 m.vertex[12] = maxs[0];m.vertex[13] = maxs[1];m.vertex[14] = mins[2];
651                 m.vertex[16] = mins[0];m.vertex[17] = mins[1];m.vertex[18] = maxs[2];
652                 m.vertex[20] = maxs[0];m.vertex[21] = mins[1];m.vertex[22] = maxs[2];
653                 m.vertex[24] = mins[0];m.vertex[25] = maxs[1];m.vertex[26] = maxs[2];
654                 m.vertex[28] = maxs[0];m.vertex[29] = maxs[1];m.vertex[30] = maxs[2];
655                 m.color[ 0] = m.color[ 4] = m.color[ 8] = m.color[12] = m.color[16] = m.color[20] = m.color[24] = m.color[28] = cr * m.colorscale;
656                 m.color[ 1] = m.color[ 5] = m.color[ 9] = m.color[13] = m.color[17] = m.color[21] = m.color[25] = m.color[29] = cg * m.colorscale;
657                 m.color[ 2] = m.color[ 6] = m.color[10] = m.color[14] = m.color[18] = m.color[22] = m.color[26] = m.color[30] = cb * m.colorscale;
658                 m.color[ 3] = m.color[ 7] = m.color[11] = m.color[15] = m.color[19] = m.color[23] = m.color[27] = m.color[31] = ca;
659                 if (fogenabled)
660                 {
661                         for (i = 0, v = m.vertex, c = m.color;i < m.numverts;i++, v += 4, c += 4)
662                         {
663                                 VectorSubtract(v, r_origin, diff);
664                                 f2 = exp(fogdensity/DotProduct(diff, diff));
665                                 f1 = 1 - f2;
666                                 f2 *= m.colorscale;
667                                 c[0] = c[0] * f1 + fogcolor[0] * f2;
668                                 c[1] = c[1] * f1 + fogcolor[1] * f2;
669                                 c[2] = c[2] * f1 + fogcolor[2] * f2;
670                         }
671                 }
672                 R_Mesh_Render();
673         }
674 }
675
676 void R_DrawNoModelCallback(const void *calldata1, int calldata2)
677 {
678         const entity_render_t *ent = calldata1;
679         int i;
680         float f1, f2, *c, diff[3];
681         rmeshbufferinfo_t m;
682         memset(&m, 0, sizeof(m));
683         if (ent->flags & EF_ADDITIVE)
684         {
685                 m.blendfunc1 = GL_SRC_ALPHA;
686                 m.blendfunc2 = GL_ONE;
687         }
688         else if (ent->alpha < 1)
689         {
690                 m.blendfunc1 = GL_SRC_ALPHA;
691                 m.blendfunc2 = GL_ONE_MINUS_SRC_ALPHA;
692         }
693         else
694         {
695                 m.blendfunc1 = GL_ONE;
696                 m.blendfunc2 = GL_ZERO;
697         }
698         m.numtriangles = 8;
699         m.numverts = 6;
700         m.matrix = ent->matrix;
701         if (R_Mesh_Draw_GetBuffer(&m, false))
702         {
703                 m.index[ 0] = 5;m.index[ 1] = 2;m.index[ 2] = 0;
704                 m.index[ 3] = 5;m.index[ 4] = 1;m.index[ 5] = 2;
705                 m.index[ 6] = 5;m.index[ 7] = 0;m.index[ 8] = 3;
706                 m.index[ 9] = 5;m.index[10] = 3;m.index[11] = 1;
707                 m.index[12] = 0;m.index[13] = 2;m.index[14] = 4;
708                 m.index[15] = 2;m.index[16] = 1;m.index[17] = 4;
709                 m.index[18] = 3;m.index[19] = 0;m.index[20] = 4;
710                 m.index[21] = 1;m.index[22] = 3;m.index[23] = 4;
711                 m.vertex[ 0] = -16;m.vertex[ 1] =   0;m.vertex[ 2] =   0;
712                 m.vertex[ 4] =  16;m.vertex[ 5] =   0;m.vertex[ 6] =   0;
713                 m.vertex[ 8] =   0;m.vertex[ 9] = -16;m.vertex[10] =   0;
714                 m.vertex[12] =   0;m.vertex[13] =  16;m.vertex[14] =   0;
715                 m.vertex[16] =   0;m.vertex[17] =   0;m.vertex[18] = -16;
716                 m.vertex[20] =   0;m.vertex[21] =   0;m.vertex[22] =  16;
717                 m.color[ 0] = 0.00f;m.color[ 1] = 0.00f;m.color[ 2] = 0.50f;m.color[ 3] = ent->alpha;
718                 m.color[ 4] = 0.00f;m.color[ 5] = 0.00f;m.color[ 6] = 0.50f;m.color[ 7] = ent->alpha;
719                 m.color[ 8] = 0.00f;m.color[ 9] = 0.50f;m.color[10] = 0.00f;m.color[11] = ent->alpha;
720                 m.color[12] = 0.00f;m.color[13] = 0.50f;m.color[14] = 0.00f;m.color[15] = ent->alpha;
721                 m.color[16] = 0.50f;m.color[17] = 0.00f;m.color[18] = 0.00f;m.color[19] = ent->alpha;
722                 m.color[20] = 0.50f;m.color[21] = 0.00f;m.color[22] = 0.00f;m.color[23] = ent->alpha;
723                 if (fogenabled)
724                 {
725                         VectorSubtract(ent->origin, r_origin, diff);
726                         f2 = exp(fogdensity/DotProduct(diff, diff));
727                         f1 = 1 - f2;
728                         for (i = 0, c = m.color;i < m.numverts;i++, c += 4)
729                         {
730                                 c[0] = (c[0] * f1 + fogcolor[0] * f2) * m.colorscale;
731                                 c[1] = (c[1] * f1 + fogcolor[1] * f2) * m.colorscale;
732                                 c[2] = (c[2] * f1 + fogcolor[2] * f2) * m.colorscale;
733                         }
734                 }
735                 else
736                 {
737                         for (i = 0, c = m.color;i < m.numverts;i++, c += 4)
738                         {
739                                 c[0] *= m.colorscale;
740                                 c[1] *= m.colorscale;
741                                 c[2] *= m.colorscale;
742                         }
743                 }
744                 R_Mesh_Render();
745         }
746 }
747
748 void R_DrawNoModel(entity_render_t *ent)
749 {
750         //if ((ent->effects & EF_ADDITIVE) || (ent->alpha < 1))
751                 R_MeshQueue_AddTransparent(ent->origin, R_DrawNoModelCallback, ent, 0);
752         //else
753         //      R_DrawNoModelCallback(ent, 0);
754 }
755