6 #include "cl_collision.h"
10 // we have to include snd_main.h here only to get access to snd_renderbuffer->format.speed when writing the AVI headers
13 cvar_t scr_viewsize = {CVAR_SAVE, "viewsize","100", "how large the view should be, 110 disables inventory bar, 120 disables status bar"};
14 cvar_t scr_fov = {CVAR_SAVE, "fov","90", "field of vision, 1-170 degrees, default 90, some players use 110-130"};
15 cvar_t scr_conalpha = {CVAR_SAVE, "scr_conalpha", "1", "opacity of console background"};
16 cvar_t scr_conbrightness = {CVAR_SAVE, "scr_conbrightness", "1", "brightness of console background (0 = black, 1 = image)"};
17 cvar_t scr_conforcewhiledisconnected = {0, "scr_conforcewhiledisconnected", "1", "forces fullscreen console while disconnected"};
18 cvar_t scr_menuforcewhiledisconnected = {0, "scr_menuforcewhiledisconnected", "0", "forces menu while disconnected"};
19 cvar_t scr_centertime = {0, "scr_centertime","2", "how long centerprint messages show"};
20 cvar_t scr_showram = {CVAR_SAVE, "showram","1", "show ram icon if low on surface cache memory (not used)"};
21 cvar_t scr_showturtle = {CVAR_SAVE, "showturtle","0", "show turtle icon when framerate is too low"};
22 cvar_t scr_showpause = {CVAR_SAVE, "showpause","1", "show pause icon when game is paused"};
23 cvar_t scr_showbrand = {0, "showbrand","0", "shows gfx/brand.tga in a corner of the screen (different values select different positions, including centered)"};
24 cvar_t scr_printspeed = {0, "scr_printspeed","0", "speed of intermission printing (episode end texts), a value of 0 disables the slow printing"};
25 cvar_t vid_conwidth = {CVAR_SAVE, "vid_conwidth", "640", "virtual width of 2D graphics system"};
26 cvar_t vid_conheight = {CVAR_SAVE, "vid_conheight", "480", "virtual height of 2D graphics system"};
27 cvar_t vid_pixelheight = {CVAR_SAVE, "vid_pixelheight", "1", "adjusts vertical field of vision to account for non-square pixels (1280x1024 on a CRT monitor for example)"};
28 cvar_t scr_screenshot_jpeg = {CVAR_SAVE, "scr_screenshot_jpeg","1", "save jpeg instead of targa"};
29 cvar_t scr_screenshot_jpeg_quality = {CVAR_SAVE, "scr_screenshot_jpeg_quality","0.9", "image quality of saved jpeg"};
30 cvar_t scr_screenshot_gammaboost = {CVAR_SAVE, "scr_screenshot_gammaboost","1", "gamma correction on saved screenshots and videos, 1.0 saves unmodified images"};
31 // scr_screenshot_name is defined in fs.c
32 cvar_t cl_capturevideo = {0, "cl_capturevideo", "0", "enables saving of video to a .avi file using uncompressed I420 colorspace and PCM audio, note that scr_screenshot_gammaboost affects the brightness of the output)"};
33 cvar_t cl_capturevideo_width = {0, "cl_capturevideo_width", "0", "scales all frames to this resolution before saving the video"};
34 cvar_t cl_capturevideo_height = {0, "cl_capturevideo_height", "0", "scales all frames to this resolution before saving the video"};
35 cvar_t cl_capturevideo_realtime = {0, "cl_capturevideo_realtime", "0", "causes video saving to operate in realtime (mostly useful while playing, not while capturing demos), this can produce a much lower quality video due to poor sound/video sync and will abort saving if your machine stalls for over a minute"};
36 cvar_t cl_capturevideo_fps = {0, "cl_capturevideo_fps", "30", "how many frames per second to save (29.97 for NTSC, 30 for typical PC video, 15 can be useful)"};
37 cvar_t cl_capturevideo_number = {CVAR_SAVE, "cl_capturevideo_number", "1", "number to append to video filename, incremented each time a capture begins"};
38 cvar_t r_letterbox = {0, "r_letterbox", "0", "reduces vertical height of view to simulate a letterboxed movie effect (can be used by mods for cutscenes)"};
39 cvar_t r_stereo_separation = {0, "r_stereo_separation", "4", "separation distance of eyes in the world (negative values are only useful for cross-eyed viewing)"};
40 cvar_t r_stereo_sidebyside = {0, "r_stereo_sidebyside", "0", "side by side views for those who can't afford glasses but can afford eye strain (note: use a negative r_stereo_separation if you want cross-eyed viewing)"};
41 cvar_t r_stereo_redblue = {0, "r_stereo_redblue", "0", "red/blue anaglyph stereo glasses (note: most of these glasses are actually red/cyan, try that one too)"};
42 cvar_t r_stereo_redcyan = {0, "r_stereo_redcyan", "0", "red/cyan anaglyph stereo glasses, the kind given away at drive-in movies like Creature From The Black Lagoon In 3D"};
43 cvar_t r_stereo_redgreen = {0, "r_stereo_redgreen", "0", "red/green anaglyph stereo glasses (for those who don't mind yellow)"};
44 cvar_t r_stereo_angle = {0, "r_stereo_angle", "0", "separation angle of eyes (makes the views look different directions, as an example, 90 gives a 90 degree separation where the views are 45 degrees left and 45 degrees right)"};
45 cvar_t scr_zoomwindow = {CVAR_SAVE, "scr_zoomwindow", "0", "displays a zoomed in overlay window"};
46 cvar_t scr_zoomwindow_viewsizex = {CVAR_SAVE, "scr_zoomwindow_viewsizex", "20", "horizontal viewsize of zoom window"};
47 cvar_t scr_zoomwindow_viewsizey = {CVAR_SAVE, "scr_zoomwindow_viewsizey", "20", "vertical viewsize of zoom window"};
48 cvar_t scr_zoomwindow_fov = {CVAR_SAVE, "scr_zoomwindow_fov", "20", "fov of zoom window"};
49 cvar_t scr_stipple = {0, "scr_stipple", "0", "interlacing-like stippling of the display"};
50 cvar_t scr_refresh = {0, "scr_refresh", "1", "allows you to completely shut off rendering for benchmarking purposes"};
51 cvar_t shownetgraph = {CVAR_SAVE, "shownetgraph", "0", "shows a graph of packet sizes and other information, 0 = off, 1 = show client netgraph, 2 = show client and server netgraphs (when hosting a server)"};
53 #define AVI_MASTER_INDEX_SIZE 640 // GB ought to be enough for anyone
55 int jpeg_supported = false;
57 qboolean scr_initialized; // ready to draw
59 float scr_con_current;
60 int scr_con_margin_bottom;
62 extern int con_vislines;
64 static void SCR_ScreenShot_f (void);
65 static void R_Envmap_f (void);
68 void R_ClearScreen(qboolean fogcolor);
71 ===============================================================================
75 ===============================================================================
78 char scr_centerstring[MAX_INPUTLINE];
79 float scr_centertime_start; // for slow victory printing
80 float scr_centertime_off;
89 Called for important messages that should stay in the center of the screen
93 void SCR_CenterPrint(const char *str)
95 strlcpy (scr_centerstring, str, sizeof (scr_centerstring));
96 scr_centertime_off = scr_centertime.value;
97 scr_centertime_start = cl.time;
99 // count the number of lines for centering
100 scr_center_lines = 1;
110 void SCR_DrawCenterString (void)
117 if(cl.intermission == 2) // in finale,
118 if(sb_showscores) // make TAB hide the finale message (sb_showscores overrides finale in sbar.c)
121 if(scr_centertime.value <= 0 && !cl.intermission)
124 // the finale prints the characters one at a time, except if printspeed is an absurdly high value
125 if (cl.intermission && scr_printspeed.value > 0 && scr_printspeed.value < 1000000)
126 remaining = (int)(scr_printspeed.value * (cl.time - scr_centertime_start));
130 scr_erase_center = 0;
131 start = scr_centerstring;
136 if (scr_center_lines <= 4)
137 y = (int)(vid_conheight.integer*0.35);
144 // scan the number of characters on the line, not counting color codes
145 char *newline = strchr(start, '\n');
146 int l = newline ? (newline - start) : (int)strlen(start);
147 float width = DrawQ_TextWidth_Font(start, l, false, FONT_CENTERPRINT) * 8;
149 x = (vid_conwidth.integer - width)/2;
154 DrawQ_String_Font(x, y, start, l, 8, 8, 1, 1, 1, 1, 0, &color, false, FONT_CENTERPRINT);
163 start = newline + 1; // skip the \n
167 void SCR_CheckDrawCenterString (void)
169 if (scr_center_lines > scr_erase_lines)
170 scr_erase_lines = scr_center_lines;
172 if (cl.time > cl.oldtime)
173 scr_centertime_off -= cl.time - cl.oldtime;
175 // don't draw if this is a normal stats-screen intermission,
176 // only if it is not an intermission, or a finale intermission
177 if (cl.intermission == 1)
179 if (scr_centertime_off <= 0 && !cl.intermission)
181 if (key_dest != key_game)
184 SCR_DrawCenterString ();
187 void SCR_DrawNetGraph_DrawGraph (int graphx, int graphy, int barwidth, int barheight, int bardivide, const char *label, float textsize, int packetcounter, int numparameters, const int **parameters, const float parametercolors[][4])
189 int j, k, x, y, index, offset, height;
190 // draw the bar graph itself
191 // advance the packet counter because it is the latest packet column being
192 // built up and should come last
193 packetcounter = (packetcounter + 1) % NETGRAPH_PACKETS;
194 for (j = 0;j < NETGRAPH_PACKETS;j++)
196 x = graphx + j * barwidth;
197 y = graphy + barheight;
198 index = (packetcounter + j) % NETGRAPH_PACKETS;
199 if (parameters[0][index] == NETGRAPH_LOSTPACKET)
200 DrawQ_Fill(x, y - barheight, barwidth, barheight, 1, 0, 0, 1, 0);
201 else if (parameters[0][index] == NETGRAPH_CHOKEDPACKET)
202 DrawQ_Fill(x, y - min(2, barheight), barwidth, min(2, barheight), 1, 1, 0, 1, 0);
206 for (k = 0;k < numparameters;k++)
208 height = (parameters[k][index] + bardivide - 1) / bardivide;
209 height = min(height, barheight - offset);
212 DrawQ_Fill(x, y - offset, barwidth, height, parametercolors[k][0], parametercolors[k][1], parametercolors[k][2], parametercolors[k][3], 0);
218 const float netgraphcolors[3][4] =
225 void SCR_DrawNetGraph_DrawConnection_Client (netconn_t *conn, int graphx, int graphy, int barwidth, int barheight, int bardivide, const char *labelincoming, int separator, const char *labeloutgoing, float textsize)
228 const int *parameters[3];
230 DrawQ_Fill(graphx , graphy, barwidth * NETGRAPH_PACKETS, barheight + textsize, 0, 0, 0, 0.5, 0);
231 DrawQ_Fill(graphx + barwidth * NETGRAPH_PACKETS + separator, graphy, barwidth * NETGRAPH_PACKETS, barheight + textsize, 0, 0, 0, 0.5, 0);
232 // draw the bar graphs
234 parameters[0] = conn->incoming_unreliablesize;
235 parameters[1] = conn->incoming_reliablesize;
236 parameters[2] = conn->incoming_acksize;
237 SCR_DrawNetGraph_DrawGraph(graphx, graphy, barwidth, barheight, bardivide, labelincoming, textsize, conn->incoming_packetcounter, numparameters, parameters, netgraphcolors);
238 parameters[0] = conn->outgoing_unreliablesize;
239 parameters[1] = conn->outgoing_reliablesize;
240 parameters[2] = conn->outgoing_acksize;
241 SCR_DrawNetGraph_DrawGraph(graphx + barwidth * NETGRAPH_PACKETS + separator, graphy, barwidth, barheight, bardivide, labeloutgoing, textsize, conn->outgoing_packetcounter, numparameters, parameters, netgraphcolors);
243 DrawQ_String(graphx , graphy + barheight, labelincoming, 0, textsize, textsize, 1, 1, 1, 1, 0, NULL, false);
244 DrawQ_String(graphx + barwidth * NETGRAPH_PACKETS + separator, graphy + barheight, labeloutgoing, 0, textsize, textsize, 1, 1, 1, 1, 0, NULL, false);
247 void SCR_DrawNetGraph_DrawConnection_Server (netconn_t *conn, int graphx, int graphy, int barwidth, int barheight, int bardivide, const char *labeloutgoing, int separator, const char *labelincoming, float textsize)
250 const int *parameters[3];
252 DrawQ_Fill(graphx , graphy, barwidth * NETGRAPH_PACKETS, barheight + textsize, 0, 0, 0, 0.5, 0);
253 DrawQ_Fill(graphx + barwidth * NETGRAPH_PACKETS + separator, graphy, barwidth * NETGRAPH_PACKETS, barheight + textsize, 0, 0, 0, 0.5, 0);
254 // draw the bar graphs
256 parameters[0] = conn->outgoing_unreliablesize;
257 parameters[1] = conn->outgoing_reliablesize;
258 parameters[2] = conn->outgoing_acksize;
259 SCR_DrawNetGraph_DrawGraph(graphx , graphy, barwidth, barheight, bardivide, labeloutgoing, textsize, conn->outgoing_packetcounter, numparameters, parameters, netgraphcolors);
260 parameters[0] = conn->incoming_unreliablesize;
261 parameters[1] = conn->incoming_reliablesize;
262 parameters[2] = conn->incoming_acksize;
263 SCR_DrawNetGraph_DrawGraph(graphx + barwidth * NETGRAPH_PACKETS + separator, graphy, barwidth, barheight, bardivide, labelincoming, textsize, conn->incoming_packetcounter, numparameters, parameters, netgraphcolors);
265 DrawQ_String(graphx , graphy + barheight, labeloutgoing, 0, textsize, textsize, 1, 1, 1, 1, 0, NULL, false);
266 DrawQ_String(graphx + barwidth * NETGRAPH_PACKETS + separator, graphy + barheight, labelincoming, 0, textsize, textsize, 1, 1, 1, 1, 0, NULL, false);
274 void SCR_DrawNetGraph (void)
276 int i, separator1, separator2, barwidth, barheight, bardivide, netgraph_x, netgraph_y, textsize, index, netgraphsperrow;
278 if (cls.state != ca_connected)
282 if (!shownetgraph.integer)
292 netgraphsperrow = (vid_conwidth.integer + separator2) / (barwidth * NETGRAPH_PACKETS * 2 + separator1 + separator2);
293 netgraphsperrow = max(netgraphsperrow, 1);
296 netgraph_x = (vid_conwidth.integer + separator2) - (1 + (index % netgraphsperrow)) * (barwidth * NETGRAPH_PACKETS * 2 + separator1 + separator2);
297 netgraph_y = (vid_conheight.integer - 48 + separator2) - (1 + (index / netgraphsperrow)) * (barheight + textsize + separator2);
298 SCR_DrawNetGraph_DrawConnection_Client(cls.netcon, netgraph_x, netgraph_y, barwidth, barheight, bardivide, "incoming", separator1, "outgoing", textsize);
301 if (sv.active && shownetgraph.integer >= 2)
303 for (i = 0;i < svs.maxclients;i++)
305 if (!svs.clients[i].netconnection)
307 netgraph_x = (vid_conwidth.integer + separator2) - (1 + (index % netgraphsperrow)) * (barwidth * NETGRAPH_PACKETS * 2 + separator1 + separator2);
308 netgraph_y = (vid_conheight.integer - 48 + separator2) - (1 + (index / netgraphsperrow)) * (barheight + textsize + separator2);
309 SCR_DrawNetGraph_DrawConnection_Server(svs.clients[i].netconnection, netgraph_x, netgraph_y, barwidth, barheight, bardivide, va("%s", svs.clients[i].name), separator1, "", textsize);
320 void SCR_DrawTurtle (void)
324 if (cls.state != ca_connected)
327 if (!scr_showturtle.integer)
330 if (cl.realframetime < 0.1)
340 DrawQ_Pic (0, 0, Draw_CachePic ("gfx/turtle"), 0, 0, 1, 1, 1, 1, 0);
348 void SCR_DrawNet (void)
350 if (cls.state != ca_connected)
352 if (realtime - cl.last_received_message < 0.3)
354 if (cls.demoplayback)
357 DrawQ_Pic (64, 0, Draw_CachePic ("gfx/net"), 0, 0, 1, 1, 1, 1, 0);
365 void SCR_DrawPause (void)
369 if (cls.state != ca_connected)
372 if (!scr_showpause.integer) // turn off for screenshots
378 pic = Draw_CachePic ("gfx/pause");
379 DrawQ_Pic ((vid_conwidth.integer - pic->width)/2, (vid_conheight.integer - pic->height)/2, pic, 0, 0, 1, 1, 1, 1, 0);
387 void SCR_DrawBrand (void)
392 if (!scr_showbrand.value)
395 pic = Draw_CachePic ("gfx/brand");
397 switch ((int)scr_showbrand.value)
399 case 1: // bottom left
401 y = vid_conheight.integer - pic->height;
403 case 2: // bottom centre
404 x = (vid_conwidth.integer - pic->width) / 2;
405 y = vid_conheight.integer - pic->height;
407 case 3: // bottom right
408 x = vid_conwidth.integer - pic->width;
409 y = vid_conheight.integer - pic->height;
411 case 4: // centre right
412 x = vid_conwidth.integer - pic->width;
413 y = (vid_conheight.integer - pic->height) / 2;
416 x = vid_conwidth.integer - pic->width;
419 case 6: // top centre
420 x = (vid_conwidth.integer - pic->width) / 2;
427 case 8: // centre left
429 y = (vid_conheight.integer - pic->height) / 2;
435 DrawQ_Pic (x, y, pic, 0, 0, 1, 1, 1, 1, 0);
443 static int SCR_DrawQWDownload(int offset)
445 // sync with SCR_DownloadHeight
451 if (!cls.qw_downloadname[0])
453 cls.qw_downloadspeedrate = 0;
454 cls.qw_downloadspeedtime = realtime;
455 cls.qw_downloadspeedcount = 0;
458 if (realtime >= cls.qw_downloadspeedtime + 1)
460 cls.qw_downloadspeedrate = cls.qw_downloadspeedcount;
461 cls.qw_downloadspeedtime = realtime;
462 cls.qw_downloadspeedcount = 0;
464 if (cls.protocol == PROTOCOL_QUAKEWORLD)
465 dpsnprintf(temp, sizeof(temp), "Downloading %s %3i%% (%i) at %i bytes/s\n", cls.qw_downloadname, cls.qw_downloadpercent, cls.qw_downloadmemorycursize, cls.qw_downloadspeedrate);
467 dpsnprintf(temp, sizeof(temp), "Downloading %s %3i%% (%i/%i) at %i bytes/s\n", cls.qw_downloadname, cls.qw_downloadpercent, cls.qw_downloadmemorycursize, cls.qw_downloadmemorymaxsize, cls.qw_downloadspeedrate);
468 len = (int)strlen(temp);
469 x = (vid_conwidth.integer - DrawQ_TextWidth_Font(temp, len, 0, FONT_INFOBAR) * size) / 2;
470 y = vid_conheight.integer - size - offset;
471 DrawQ_Fill(0, y, vid_conwidth.integer, size, 0, 0, 0, cls.signon == SIGNONS ? 0.5 : 1, 0);
472 DrawQ_String_Font(x, y, temp, len, size, size, 1, 1, 1, 1, 0, NULL, true, FONT_INFOBAR);
481 static int SCR_DrawCurlDownload(int offset)
483 // sync with SCR_DownloadHeight
489 Curl_downloadinfo_t *downinfo;
493 downinfo = Curl_GetDownloadInfo(&nDownloads, &addinfo);
497 y = vid_conheight.integer - size * nDownloads - offset;
501 len = (int)strlen(addinfo);
502 x = (vid_conwidth.integer - DrawQ_TextWidth_Font(addinfo, len, false, FONT_INFOBAR) * size) / 2;
503 DrawQ_Fill(0, y - size, vid_conwidth.integer, size, 1, 1, 1, cls.signon == SIGNONS ? 0.8 : 1, 0);
504 DrawQ_String_Font(x, y - size, addinfo, len, size, size, 0, 0, 0, 1, 0, NULL, true, FONT_INFOBAR);
507 for(i = 0; i != nDownloads; ++i)
509 if(downinfo[i].queued)
510 dpsnprintf(temp, sizeof(temp), "Still in queue: %s\n", downinfo[i].filename);
511 else if(downinfo[i].progress <= 0)
512 dpsnprintf(temp, sizeof(temp), "Downloading %s ... ???.?%% @ %.1f KiB/s\n", downinfo[i].filename, downinfo[i].speed / 1024.0);
514 dpsnprintf(temp, sizeof(temp), "Downloading %s ... %5.1f%% @ %.1f KiB/s\n", downinfo[i].filename, 100.0 * downinfo[i].progress, downinfo[i].speed / 1024.0);
515 len = (int)strlen(temp);
516 x = (vid_conwidth.integer - DrawQ_TextWidth_Font(temp, len, false, FONT_INFOBAR) * size) / 2;
517 DrawQ_Fill(0, y + i * size, vid_conwidth.integer, size, 0, 0, 0, cls.signon == SIGNONS ? 0.5 : 1, 0);
518 DrawQ_String_Font(x, y + i * size, temp, len, size, size, 1, 1, 1, 1, 0, NULL, true, FONT_INFOBAR);
523 return 8 * (nDownloads + (addinfo ? 1 : 0));
531 static void SCR_DrawDownload()
534 offset += SCR_DrawQWDownload(offset);
535 offset += SCR_DrawCurlDownload(offset);
536 if(offset != scr_con_margin_bottom)
537 Con_DPrintf("broken console margin calculation: %d != %d\n", offset, scr_con_margin_bottom);
540 static int SCR_DownloadHeight()
543 Curl_downloadinfo_t *downinfo;
547 if(cls.qw_downloadname[0])
550 downinfo = Curl_GetDownloadInfo(&nDownloads, &addinfo);
553 offset += 8 * (nDownloads + (addinfo ? 1 : 0));
560 //=============================================================================
564 SCR_SetUpToDrawConsole
567 void SCR_SetUpToDrawConsole (void)
569 // lines of console to display
571 static int framecounter = 0;
575 if (scr_menuforcewhiledisconnected.integer && key_dest == key_game && cls.state == ca_disconnected)
577 if (framecounter >= 2)
585 if (scr_conforcewhiledisconnected.integer && key_dest == key_game && cls.signon != SIGNONS)
586 key_consoleactive |= KEY_CONSOLEACTIVE_FORCED;
588 key_consoleactive &= ~KEY_CONSOLEACTIVE_FORCED;
590 // decide on the height of the console
591 if (key_consoleactive & KEY_CONSOLEACTIVE_USER)
592 conlines = vid_conheight.integer/2; // half screen
594 conlines = 0; // none visible
596 scr_con_current = conlines;
604 void SCR_DrawConsole (void)
606 scr_con_margin_bottom = SCR_DownloadHeight();
607 if (key_consoleactive & KEY_CONSOLEACTIVE_FORCED)
610 Con_DrawConsole (vid_conheight.integer - scr_con_margin_bottom);
612 else if (scr_con_current)
613 Con_DrawConsole (min((int)scr_con_current, vid_conheight.integer - scr_con_margin_bottom));
620 SCR_BeginLoadingPlaque
624 void SCR_BeginLoadingPlaque (void)
626 // save console log up to this point to log_file if it was set by configs
630 SCR_UpdateLoadingScreen(false);
633 //=============================================================================
635 char r_speeds_timestring[4096];
636 int speedstringcount, r_timereport_active;
637 double r_timereport_temp = 0, r_timereport_current = 0, r_timereport_start = 0;
638 int r_speeds_longestitem = 0;
640 void R_TimeReport(char *desc)
646 if (r_speeds.integer < 2 || !r_timereport_active)
650 if (r_speeds.integer == 2)
653 r_timereport_temp = r_timereport_current;
654 r_timereport_current = Sys_DoubleTime();
655 t = (int) ((r_timereport_current - r_timereport_temp) * 1000000.0 + 0.5);
657 length = dpsnprintf(tempbuf, sizeof(tempbuf), "%8i %s", t, desc);
658 length = min(length, (int)sizeof(tempbuf) - 1);
659 if (r_speeds_longestitem < length)
660 r_speeds_longestitem = length;
661 for (;length < r_speeds_longestitem;length++)
662 tempbuf[length] = ' ';
665 if (speedstringcount + length > (vid_conwidth.integer / 8))
667 strlcat(r_speeds_timestring, "\n", sizeof(r_speeds_timestring));
668 speedstringcount = 0;
670 strlcat(r_speeds_timestring, tempbuf, sizeof(r_speeds_timestring));
671 speedstringcount += length;
674 void R_TimeReport_BeginFrame(void)
676 speedstringcount = 0;
677 r_speeds_timestring[0] = 0;
678 r_timereport_active = false;
679 memset(&r_refdef.stats, 0, sizeof(r_refdef.stats));
681 if (r_speeds.integer >= 2 && cls.signon == SIGNONS && cls.state == ca_connected)
683 r_timereport_active = true;
684 r_timereport_start = r_timereport_current = Sys_DoubleTime();
688 void R_TimeReport_EndFrame(void)
692 char string[1024+4096];
695 if (r_speeds.integer && cls.signon == SIGNONS && cls.state == ca_connected)
697 // put the location name in the r_speeds display as it greatly helps
698 // when creating loc files
699 loc = CL_Locs_FindNearest(cl.movement_origin);
700 dpsnprintf(string, sizeof(string),
702 "%3i renders org:'%+8.2f %+8.2f %+8.2f' dir:'%+2.3f %+2.3f %+2.3f'\n"
703 "%7i surfaces%7i triangles %5i entities (%7i surfaces%7i triangles)\n"
704 "%5i leafs%5i portals%6i/%6i particles%6i/%6i decals %3i%% quality\n"
705 "%7i lightmap updates (%7i pixels)\n"
706 "%4i lights%4i clears%4i scissored%7i light%7i shadow%7i dynamic\n"
707 "rendered%6i meshes%8i triangles bloompixels%8i copied%8i drawn\n"
709 , loc ? "Location: " : "", loc ? loc->name : ""
710 , r_refdef.stats.renders, r_refdef.view.origin[0], r_refdef.view.origin[1], r_refdef.view.origin[2], r_refdef.view.forward[0], r_refdef.view.forward[1], r_refdef.view.forward[2]
711 , r_refdef.stats.world_surfaces, r_refdef.stats.world_triangles, r_refdef.stats.entities, r_refdef.stats.entities_surfaces, r_refdef.stats.entities_triangles
712 , r_refdef.stats.world_leafs, r_refdef.stats.world_portals, r_refdef.stats.particles, cl.num_particles, r_refdef.stats.decals, cl.num_decals, (int)(100 * r_refdef.view.quality)
713 , r_refdef.stats.lightmapupdates, r_refdef.stats.lightmapupdatepixels
714 , r_refdef.stats.lights, r_refdef.stats.lights_clears, r_refdef.stats.lights_scissored, r_refdef.stats.lights_lighttriangles, r_refdef.stats.lights_shadowtriangles, r_refdef.stats.lights_dynamicshadowtriangles
715 , r_refdef.stats.meshes, r_refdef.stats.meshes_elements / 3, r_refdef.stats.bloom_copypixels, r_refdef.stats.bloom_drawpixels
716 , r_speeds_timestring);
718 memset(&r_refdef.stats, 0, sizeof(r_refdef.stats));
720 speedstringcount = 0;
721 r_speeds_timestring[0] = 0;
722 r_timereport_active = false;
724 if (r_speeds.integer >= 2)
726 r_timereport_active = true;
727 r_timereport_start = r_timereport_current = Sys_DoubleTime();
733 if (string[strlen(string)-1] == '\n')
734 string[strlen(string)-1] = 0;
736 for (i = 0;string[i];i++)
737 if (string[i] == '\n')
739 y = vid_conheight.integer - sb_lines - lines * 8;
741 DrawQ_Fill(0, y, vid_conwidth.integer, lines * 8, 0, 0, 0, 0.5, 0);
745 while (string[i] && string[i] != '\n')
748 DrawQ_String(0, y, string + j, i - j, 8, 8, 1, 1, 1, 1, 0, NULL, true);
749 if (string[i] == '\n')
763 void SCR_SizeUp_f (void)
765 Cvar_SetValue ("viewsize",scr_viewsize.value+10);
776 void SCR_SizeDown_f (void)
778 Cvar_SetValue ("viewsize",scr_viewsize.value-10);
781 void SCR_CaptureVideo_EndVideo(void);
782 void CL_Screen_Shutdown(void)
784 SCR_CaptureVideo_EndVideo();
787 void CL_Screen_Init(void)
789 Cvar_RegisterVariable (&scr_fov);
790 Cvar_RegisterVariable (&scr_viewsize);
791 Cvar_RegisterVariable (&scr_conalpha);
792 Cvar_RegisterVariable (&scr_conbrightness);
793 Cvar_RegisterVariable (&scr_conforcewhiledisconnected);
794 Cvar_RegisterVariable (&scr_menuforcewhiledisconnected);
795 Cvar_RegisterVariable (&scr_showram);
796 Cvar_RegisterVariable (&scr_showturtle);
797 Cvar_RegisterVariable (&scr_showpause);
798 Cvar_RegisterVariable (&scr_showbrand);
799 Cvar_RegisterVariable (&scr_centertime);
800 Cvar_RegisterVariable (&scr_printspeed);
801 Cvar_RegisterVariable (&vid_conwidth);
802 Cvar_RegisterVariable (&vid_conheight);
803 Cvar_RegisterVariable (&vid_pixelheight);
804 Cvar_RegisterVariable (&scr_screenshot_jpeg);
805 Cvar_RegisterVariable (&scr_screenshot_jpeg_quality);
806 Cvar_RegisterVariable (&scr_screenshot_gammaboost);
807 Cvar_RegisterVariable (&cl_capturevideo);
808 Cvar_RegisterVariable (&cl_capturevideo_width);
809 Cvar_RegisterVariable (&cl_capturevideo_height);
810 Cvar_RegisterVariable (&cl_capturevideo_realtime);
811 Cvar_RegisterVariable (&cl_capturevideo_fps);
812 Cvar_RegisterVariable (&cl_capturevideo_number);
813 Cvar_RegisterVariable (&r_letterbox);
814 Cvar_RegisterVariable(&r_stereo_separation);
815 Cvar_RegisterVariable(&r_stereo_sidebyside);
816 Cvar_RegisterVariable(&r_stereo_redblue);
817 Cvar_RegisterVariable(&r_stereo_redcyan);
818 Cvar_RegisterVariable(&r_stereo_redgreen);
819 Cvar_RegisterVariable(&r_stereo_angle);
820 Cvar_RegisterVariable(&scr_zoomwindow);
821 Cvar_RegisterVariable(&scr_zoomwindow_viewsizex);
822 Cvar_RegisterVariable(&scr_zoomwindow_viewsizey);
823 Cvar_RegisterVariable(&scr_zoomwindow_fov);
824 Cvar_RegisterVariable(&scr_stipple);
825 Cvar_RegisterVariable(&scr_refresh);
826 Cvar_RegisterVariable(&shownetgraph);
828 Cmd_AddCommand ("sizeup",SCR_SizeUp_f, "increase view size (increases viewsize cvar)");
829 Cmd_AddCommand ("sizedown",SCR_SizeDown_f, "decrease view size (decreases viewsize cvar)");
830 Cmd_AddCommand ("screenshot",SCR_ScreenShot_f, "takes a screenshot of the next rendered frame");
831 Cmd_AddCommand ("envmap", R_Envmap_f, "render a cubemap (skybox) of the current scene");
833 scr_initialized = true;
841 void SCR_ScreenShot_f (void)
843 static int shotnumber;
844 static char oldname[MAX_QPATH];
845 char base[MAX_QPATH];
846 char filename[MAX_QPATH];
847 unsigned char *buffer1;
848 unsigned char *buffer2;
849 unsigned char *buffer3;
850 qboolean jpeg = (scr_screenshot_jpeg.integer != 0);
852 dpsnprintf (base, sizeof(base), "screenshots/%s", scr_screenshot_name.string);
854 if (strcmp (oldname, scr_screenshot_name.string))
856 dpsnprintf(oldname, sizeof(oldname), "%s", scr_screenshot_name.string);
860 // find a file name to save it to
861 for (;shotnumber < 1000000;shotnumber++)
862 if (!FS_SysFileExists(va("%s/%s%06d.tga", fs_gamedir, base, shotnumber)) && !FS_SysFileExists(va("%s/%s%06d.jpg", fs_gamedir, base, shotnumber)))
864 if (shotnumber >= 1000000)
866 Con_Print("SCR_ScreenShot_f: Couldn't create the image file\n");
870 dpsnprintf(filename, sizeof(filename), "%s%06d.%s", base, shotnumber, jpeg ? "jpg" : "tga");
872 buffer1 = (unsigned char *)Mem_Alloc(tempmempool, vid.width * vid.height * 3);
873 buffer2 = (unsigned char *)Mem_Alloc(tempmempool, vid.width * vid.height * 3);
874 buffer3 = (unsigned char *)Mem_Alloc(tempmempool, vid.width * vid.height * 3 + 18);
876 if (SCR_ScreenShot (filename, buffer1, buffer2, buffer3, 0, 0, vid.width, vid.height, false, false, false, jpeg, true))
877 Con_Printf("Wrote %s\n", filename);
879 Con_Printf("unable to write %s\n", filename);
888 static void SCR_CaptureVideo_RIFF_Start(void)
890 memset(&cls.capturevideo.riffbuffer, 0, sizeof(sizebuf_t));
891 cls.capturevideo.riffbuffer.maxsize = sizeof(cls.capturevideo.riffbufferdata);
892 cls.capturevideo.riffbuffer.data = cls.capturevideo.riffbufferdata;
895 static void SCR_CaptureVideo_RIFF_Flush(void)
897 if (cls.capturevideo.riffbuffer.cursize > 0)
899 if (!FS_Write(cls.capturevideo.videofile, cls.capturevideo.riffbuffer.data, cls.capturevideo.riffbuffer.cursize))
900 cls.capturevideo.error = true;
901 cls.capturevideo.riffbuffer.cursize = 0;
902 cls.capturevideo.riffbuffer.overflowed = false;
906 static void SCR_CaptureVideo_RIFF_WriteBytes(const unsigned char *data, size_t size)
908 SCR_CaptureVideo_RIFF_Flush();
909 if (!FS_Write(cls.capturevideo.videofile, data, size))
910 cls.capturevideo.error = true;
913 static void SCR_CaptureVideo_RIFF_Write32(int n)
915 if (cls.capturevideo.riffbuffer.cursize + 4 > cls.capturevideo.riffbuffer.maxsize)
916 SCR_CaptureVideo_RIFF_Flush();
917 MSG_WriteLong(&cls.capturevideo.riffbuffer, n);
920 static void SCR_CaptureVideo_RIFF_Write16(int n)
922 if (cls.capturevideo.riffbuffer.cursize + 2 > cls.capturevideo.riffbuffer.maxsize)
923 SCR_CaptureVideo_RIFF_Flush();
924 MSG_WriteShort(&cls.capturevideo.riffbuffer, n);
927 static void SCR_CaptureVideo_RIFF_WriteFourCC(const char *chunkfourcc)
929 if (cls.capturevideo.riffbuffer.cursize + (int)strlen(chunkfourcc) > cls.capturevideo.riffbuffer.maxsize)
930 SCR_CaptureVideo_RIFF_Flush();
931 MSG_WriteUnterminatedString(&cls.capturevideo.riffbuffer, chunkfourcc);
934 static void SCR_CaptureVideo_RIFF_WriteTerminatedString(const char *string)
936 if (cls.capturevideo.riffbuffer.cursize + (int)strlen(string) > cls.capturevideo.riffbuffer.maxsize)
937 SCR_CaptureVideo_RIFF_Flush();
938 MSG_WriteString(&cls.capturevideo.riffbuffer, string);
941 static fs_offset_t SCR_CaptureVideo_RIFF_GetPosition(void)
943 SCR_CaptureVideo_RIFF_Flush();
944 return FS_Tell(cls.capturevideo.videofile);
947 static void SCR_CaptureVideo_RIFF_Push(const char *chunkfourcc, const char *listtypefourcc)
949 SCR_CaptureVideo_RIFF_WriteFourCC(chunkfourcc);
950 SCR_CaptureVideo_RIFF_Write32(0);
951 SCR_CaptureVideo_RIFF_Flush();
952 cls.capturevideo.riffstackstartoffset[cls.capturevideo.riffstacklevel++] = SCR_CaptureVideo_RIFF_GetPosition();
954 SCR_CaptureVideo_RIFF_WriteFourCC(listtypefourcc);
957 static void SCR_CaptureVideo_RIFF_Pop(void)
961 unsigned char sizebytes[4];
962 // write out the chunk size and then return to the current file position
963 cls.capturevideo.riffstacklevel--;
964 offset = SCR_CaptureVideo_RIFF_GetPosition();
965 x = (int)(offset - (cls.capturevideo.riffstackstartoffset[cls.capturevideo.riffstacklevel]));
966 sizebytes[0] = (x) & 0xff;sizebytes[1] = (x >> 8) & 0xff;sizebytes[2] = (x >> 16) & 0xff;sizebytes[3] = (x >> 24) & 0xff;
967 FS_Seek(cls.capturevideo.videofile, -(x + 4), SEEK_END);
968 FS_Write(cls.capturevideo.videofile, sizebytes, 4);
969 FS_Seek(cls.capturevideo.videofile, 0, SEEK_END);
973 FS_Write(cls.capturevideo.videofile, &c, 1);
977 static void GrowBuf(sizebuf_t *buf, int extralen)
979 if(buf->cursize + extralen > buf->maxsize)
981 int oldsize = buf->maxsize;
982 unsigned char *olddata;
984 buf->maxsize = max(buf->maxsize * 2, 4096);
985 buf->data = Mem_Alloc(tempmempool, buf->maxsize);
988 memcpy(buf->data, olddata, oldsize);
994 static void SCR_CaptureVideo_RIFF_IndexEntry(const char *chunkfourcc, int chunksize, int flags)
996 if (cls.capturevideo.riffstacklevel != 2)
997 Sys_Error("SCR_Capturevideo_RIFF_IndexEntry: RIFF stack level is %i (should be 2)\n", cls.capturevideo.riffstacklevel);
998 GrowBuf(&cls.capturevideo.riffindexbuffer, 16);
999 SCR_CaptureVideo_RIFF_Flush();
1000 MSG_WriteUnterminatedString(&cls.capturevideo.riffindexbuffer, chunkfourcc);
1001 MSG_WriteLong(&cls.capturevideo.riffindexbuffer, flags);
1002 MSG_WriteLong(&cls.capturevideo.riffindexbuffer, (int)FS_Tell(cls.capturevideo.videofile) - cls.capturevideo.riffstackstartoffset[1]);
1003 MSG_WriteLong(&cls.capturevideo.riffindexbuffer, chunksize);
1006 static void SCR_CaptureVideo_RIFF_MakeIxChunk(const char *fcc, const char *dwChunkId, fs_offset_t masteridx_counter, int *masteridx_count, fs_offset_t masteridx_start)
1010 fs_offset_t ix = SCR_CaptureVideo_RIFF_GetPosition();
1013 if(*masteridx_count >= AVI_MASTER_INDEX_SIZE)
1016 nMatching = 0; // go through index and enumerate them
1017 for(i = 0; i < cls.capturevideo.riffindexbuffer.cursize; i += 16)
1018 if(!memcmp(cls.capturevideo.riffindexbuffer.data + i, dwChunkId, 4))
1021 SCR_CaptureVideo_RIFF_Push(fcc, NULL);
1022 SCR_CaptureVideo_RIFF_Write16(2); // wLongsPerEntry
1023 SCR_CaptureVideo_RIFF_Write16(0x0100); // bIndexType=1, bIndexSubType=0
1024 SCR_CaptureVideo_RIFF_Write32(nMatching); // nEntriesInUse
1025 SCR_CaptureVideo_RIFF_WriteFourCC(dwChunkId); // dwChunkId
1026 SCR_CaptureVideo_RIFF_Write32(cls.capturevideo.videofile_ix_movistart & (fs_offset_t) 0xFFFFFFFFu);
1027 SCR_CaptureVideo_RIFF_Write32(((fs_offset_t) cls.capturevideo.videofile_ix_movistart) >> 32);
1028 SCR_CaptureVideo_RIFF_Write32(0); // dwReserved
1030 for(i = 0; i < cls.capturevideo.riffindexbuffer.cursize; i += 16)
1031 if(!memcmp(cls.capturevideo.riffindexbuffer.data + i, dwChunkId, 4))
1033 unsigned int *p = (unsigned int *) (cls.capturevideo.riffindexbuffer.data + i);
1034 unsigned int flags = p[1];
1035 unsigned int rpos = p[2];
1036 unsigned int size = p[3];
1037 size &= ~0x80000000;
1038 if(!(flags & 0x10)) // no keyframe?
1040 SCR_CaptureVideo_RIFF_Write32(rpos + 8);
1041 SCR_CaptureVideo_RIFF_Write32(size);
1044 SCR_CaptureVideo_RIFF_Pop();
1045 pos = SCR_CaptureVideo_RIFF_GetPosition();
1046 SCR_CaptureVideo_RIFF_Flush();
1048 FS_Seek(cls.capturevideo.videofile, masteridx_start + 16 * *masteridx_count, SEEK_SET);
1049 SCR_CaptureVideo_RIFF_Write32(ix & (fs_offset_t) 0xFFFFFFFFu);
1050 SCR_CaptureVideo_RIFF_Write32(((fs_offset_t) ix) >> 32);
1051 SCR_CaptureVideo_RIFF_Write32(pos - ix);
1052 SCR_CaptureVideo_RIFF_Write32(nMatching);
1053 SCR_CaptureVideo_RIFF_Flush();
1055 FS_Seek(cls.capturevideo.videofile, masteridx_counter, SEEK_SET);
1056 SCR_CaptureVideo_RIFF_Write32(++*masteridx_count);
1057 SCR_CaptureVideo_RIFF_Flush();
1059 FS_Seek(cls.capturevideo.videofile, 0, SEEK_END);
1062 static void SCR_CaptureVideo_RIFF_Finish(qboolean final)
1064 // close the "movi" list
1065 SCR_CaptureVideo_RIFF_Pop();
1066 if(cls.capturevideo.videofile_ix_master_video_inuse_offset)
1067 SCR_CaptureVideo_RIFF_MakeIxChunk("ix00", "00dc", cls.capturevideo.videofile_ix_master_video_inuse_offset, &cls.capturevideo.videofile_ix_master_video_inuse, cls.capturevideo.videofile_ix_master_video_start_offset);
1068 if(cls.capturevideo.videofile_ix_master_audio_inuse_offset)
1069 SCR_CaptureVideo_RIFF_MakeIxChunk("ix01", "01wb", cls.capturevideo.videofile_ix_master_audio_inuse_offset, &cls.capturevideo.videofile_ix_master_audio_inuse, cls.capturevideo.videofile_ix_master_audio_start_offset);
1070 // write the idx1 chunk that we've been building while saving the frames (for old style players)
1071 if(final && cls.capturevideo.videofile_firstchunkframes_offset)
1072 // TODO replace index creating by OpenDML ix##/##ix/indx chunk so it works for more than one AVI part too
1074 SCR_CaptureVideo_RIFF_Push("idx1", NULL);
1075 SCR_CaptureVideo_RIFF_WriteBytes(cls.capturevideo.riffindexbuffer.data, cls.capturevideo.riffindexbuffer.cursize);
1076 SCR_CaptureVideo_RIFF_Pop();
1078 cls.capturevideo.riffindexbuffer.cursize = 0;
1079 // pop the RIFF chunk itself
1080 while (cls.capturevideo.riffstacklevel > 0)
1081 SCR_CaptureVideo_RIFF_Pop();
1082 SCR_CaptureVideo_RIFF_Flush();
1083 if(cls.capturevideo.videofile_firstchunkframes_offset)
1085 Con_DPrintf("Finishing first chunk (%d frames)\n", cls.capturevideo.frame);
1086 FS_Seek(cls.capturevideo.videofile, cls.capturevideo.videofile_firstchunkframes_offset, SEEK_SET);
1087 SCR_CaptureVideo_RIFF_Write32(cls.capturevideo.frame);
1088 SCR_CaptureVideo_RIFF_Flush();
1089 FS_Seek(cls.capturevideo.videofile, 0, SEEK_END);
1090 cls.capturevideo.videofile_firstchunkframes_offset = 0;
1093 Con_DPrintf("Finishing another chunk (%d frames)\n", cls.capturevideo.frame);
1096 static void SCR_CaptureVideo_RIFF_OverflowCheck(int framesize)
1098 fs_offset_t cursize, curfilesize;
1099 if (cls.capturevideo.riffstacklevel != 2)
1100 Sys_Error("SCR_CaptureVideo_RIFF_OverflowCheck: chunk stack leakage!\n");
1101 // check where we are in the file
1102 SCR_CaptureVideo_RIFF_Flush();
1103 cursize = SCR_CaptureVideo_RIFF_GetPosition() - cls.capturevideo.riffstackstartoffset[0];
1104 curfilesize = SCR_CaptureVideo_RIFF_GetPosition();
1106 // if this would overflow the windows limit of 1GB per RIFF chunk, we need
1107 // to close the current RIFF chunk and open another for future frames
1108 if (8 + cursize + framesize + cls.capturevideo.riffindexbuffer.cursize + 8 + cls.capturevideo.riffindexbuffer.cursize + 64 > 1<<30) // note that the Ix buffer takes less space... I just don't dare to / 2 here now... sorry, maybe later
1110 SCR_CaptureVideo_RIFF_Finish(false);
1111 // begin a new 1GB extended section of the AVI
1112 SCR_CaptureVideo_RIFF_Push("RIFF", "AVIX");
1113 SCR_CaptureVideo_RIFF_Push("LIST", "movi");
1114 cls.capturevideo.videofile_ix_movistart = cls.capturevideo.riffstackstartoffset[1];
1118 static void FindFraction(double val, int *num, int *denom, int denomMax)
1123 bestdiff = fabs(val);
1127 for(i = 1; i <= denomMax; ++i)
1129 int inum = floor(0.5 + val * i);
1130 double diff = fabs(val - inum / (double)i);
1140 void SCR_CaptureVideo_BeginVideo(void)
1142 double gamma, g, aspect;
1143 int width = cl_capturevideo_width.integer, height = cl_capturevideo_height.integer;
1146 if (cls.capturevideo.active)
1148 memset(&cls.capturevideo, 0, sizeof(cls.capturevideo));
1149 // soundrate is figured out on the first SoundFrame
1151 if(width == 0 && height != 0)
1152 width = (int) (height * (double)vid.width / ((double)vid.height * vid_pixelheight.value)); // keep aspect
1153 if(width != 0 && height == 0)
1154 height = (int) (width * ((double)vid.height * vid_pixelheight.value) / (double)vid.width); // keep aspect
1156 if(width < 2 || width > vid.width) // can't scale up
1158 if(height < 2 || height > vid.height) // can't scale up
1159 height = vid.height;
1161 aspect = vid.width / (vid.height * vid_pixelheight.value);
1163 // ensure it's all even; if not, scale down a little
1169 cls.capturevideo.width = width;
1170 cls.capturevideo.height = height;
1171 cls.capturevideo.active = true;
1172 cls.capturevideo.starttime = realtime;
1173 cls.capturevideo.framerate = bound(1, cl_capturevideo_fps.value, 1000);
1174 cls.capturevideo.soundrate = S_GetSoundRate();
1175 cls.capturevideo.frame = 0;
1176 cls.capturevideo.soundsampleframe = 0;
1177 cls.capturevideo.realtime = cl_capturevideo_realtime.integer != 0;
1178 cls.capturevideo.screenbuffer = (unsigned char *)Mem_Alloc(tempmempool, vid.width * vid.height * 4);
1179 cls.capturevideo.outbuffer = (unsigned char *)Mem_Alloc(tempmempool, width * height * (4+4) + 18);
1180 gamma = 1.0/scr_screenshot_gammaboost.value;
1181 dpsnprintf(cls.capturevideo.basename, sizeof(cls.capturevideo.basename), "video/dpvideo%03i", cl_capturevideo_number.integer);
1182 Cvar_SetValueQuick(&cl_capturevideo_number, cl_capturevideo_number.integer + 1);
1185 for (i = 0;i < 256;i++)
1187 unsigned char j = (unsigned char)bound(0, 255*pow(i/255.0, gamma), 255);
1188 cls.capturevideo.rgbgammatable[0][i] = j;
1189 cls.capturevideo.rgbgammatable[1][i] = j;
1190 cls.capturevideo.rgbgammatable[2][i] = j;
1194 R = Y + 1.4075 * (Cr - 128);
1195 G = Y + -0.3455 * (Cb - 128) + -0.7169 * (Cr - 128);
1196 B = Y + 1.7790 * (Cb - 128);
1197 Y = R * .299 + G * .587 + B * .114;
1198 Cb = R * -.169 + G * -.332 + B * .500 + 128.;
1199 Cr = R * .500 + G * -.419 + B * -.0813 + 128.;
1201 for (i = 0;i < 256;i++)
1203 g = 255*pow(i/255.0, gamma);
1204 // Y weights from RGB
1205 cls.capturevideo.rgbtoyuvscaletable[0][0][i] = (short)(g * 0.299);
1206 cls.capturevideo.rgbtoyuvscaletable[0][1][i] = (short)(g * 0.587);
1207 cls.capturevideo.rgbtoyuvscaletable[0][2][i] = (short)(g * 0.114);
1208 // Cb weights from RGB
1209 cls.capturevideo.rgbtoyuvscaletable[1][0][i] = (short)(g * -0.169);
1210 cls.capturevideo.rgbtoyuvscaletable[1][1][i] = (short)(g * -0.332);
1211 cls.capturevideo.rgbtoyuvscaletable[1][2][i] = (short)(g * 0.500);
1212 // Cr weights from RGB
1213 cls.capturevideo.rgbtoyuvscaletable[2][0][i] = (short)(g * 0.500);
1214 cls.capturevideo.rgbtoyuvscaletable[2][1][i] = (short)(g * -0.419);
1215 cls.capturevideo.rgbtoyuvscaletable[2][2][i] = (short)(g * -0.0813);
1216 // range reduction of YCbCr to valid signal range
1217 cls.capturevideo.yuvnormalizetable[0][i] = 16 + i * (236-16) / 256;
1218 cls.capturevideo.yuvnormalizetable[1][i] = 16 + i * (240-16) / 256;
1219 cls.capturevideo.yuvnormalizetable[2][i] = 16 + i * (240-16) / 256;
1222 //if (cl_capturevideo_)
1227 cls.capturevideo.format = CAPTUREVIDEOFORMAT_AVI_I420;
1228 cls.capturevideo.videofile = FS_Open (va("%s.avi", cls.capturevideo.basename), "wb", false, true);
1229 SCR_CaptureVideo_RIFF_Start();
1230 // enclosing RIFF chunk (there can be multiple of these in >1GB files, the later ones are "AVIX" instead of "AVI " and have no header/stream info)
1231 SCR_CaptureVideo_RIFF_Push("RIFF", "AVI ");
1233 SCR_CaptureVideo_RIFF_Push("LIST", "hdrl");
1234 SCR_CaptureVideo_RIFF_Push("avih", NULL);
1235 SCR_CaptureVideo_RIFF_Write32((int)(1000000.0 / cls.capturevideo.framerate)); // microseconds per frame
1236 SCR_CaptureVideo_RIFF_Write32(0); // max bytes per second
1237 SCR_CaptureVideo_RIFF_Write32(0); // padding granularity
1238 SCR_CaptureVideo_RIFF_Write32(0x910); // flags (AVIF_HASINDEX | AVIF_ISINTERLEAVED | AVIF_TRUSTCKTYPE)
1239 cls.capturevideo.videofile_firstchunkframes_offset = SCR_CaptureVideo_RIFF_GetPosition();
1240 SCR_CaptureVideo_RIFF_Write32(0); // total frames
1241 SCR_CaptureVideo_RIFF_Write32(0); // initial frames
1242 if (cls.capturevideo.soundrate)
1243 SCR_CaptureVideo_RIFF_Write32(2); // number of streams
1245 SCR_CaptureVideo_RIFF_Write32(1); // number of streams
1246 SCR_CaptureVideo_RIFF_Write32(0); // suggested buffer size
1247 SCR_CaptureVideo_RIFF_Write32(width); // width
1248 SCR_CaptureVideo_RIFF_Write32(height); // height
1249 SCR_CaptureVideo_RIFF_Write32(0); // reserved[0]
1250 SCR_CaptureVideo_RIFF_Write32(0); // reserved[1]
1251 SCR_CaptureVideo_RIFF_Write32(0); // reserved[2]
1252 SCR_CaptureVideo_RIFF_Write32(0); // reserved[3]
1253 SCR_CaptureVideo_RIFF_Pop();
1254 // video stream info
1255 SCR_CaptureVideo_RIFF_Push("LIST", "strl");
1256 SCR_CaptureVideo_RIFF_Push("strh", "vids");
1257 SCR_CaptureVideo_RIFF_WriteFourCC("I420"); // stream fourcc (I420 colorspace, uncompressed)
1258 SCR_CaptureVideo_RIFF_Write32(0); // flags
1259 SCR_CaptureVideo_RIFF_Write16(0); // priority
1260 SCR_CaptureVideo_RIFF_Write16(0); // language
1261 SCR_CaptureVideo_RIFF_Write32(0); // initial frames
1262 // find an ideal divisor for the framerate
1263 FindFraction(cls.capturevideo.framerate, &n, &d, 1000);
1264 SCR_CaptureVideo_RIFF_Write32(d); // samples/second divisor
1265 SCR_CaptureVideo_RIFF_Write32(n); // samples/second multiplied by divisor
1266 SCR_CaptureVideo_RIFF_Write32(0); // start
1267 cls.capturevideo.videofile_totalframes_offset1 = SCR_CaptureVideo_RIFF_GetPosition();
1268 SCR_CaptureVideo_RIFF_Write32(0); // length
1269 SCR_CaptureVideo_RIFF_Write32(width*height+(width/2)*(height/2)*2); // suggested buffer size
1270 SCR_CaptureVideo_RIFF_Write32(0); // quality
1271 SCR_CaptureVideo_RIFF_Write32(0); // sample size
1272 SCR_CaptureVideo_RIFF_Write16(0); // frame left
1273 SCR_CaptureVideo_RIFF_Write16(0); // frame top
1274 SCR_CaptureVideo_RIFF_Write16(width); // frame right
1275 SCR_CaptureVideo_RIFF_Write16(height); // frame bottom
1276 SCR_CaptureVideo_RIFF_Pop();
1277 // video stream format
1278 SCR_CaptureVideo_RIFF_Push("strf", NULL);
1279 SCR_CaptureVideo_RIFF_Write32(40); // BITMAPINFO struct size
1280 SCR_CaptureVideo_RIFF_Write32(width); // width
1281 SCR_CaptureVideo_RIFF_Write32(height); // height
1282 SCR_CaptureVideo_RIFF_Write16(3); // planes
1283 SCR_CaptureVideo_RIFF_Write16(12); // bitcount
1284 SCR_CaptureVideo_RIFF_WriteFourCC("I420"); // compression
1285 SCR_CaptureVideo_RIFF_Write32(width*height+(width/2)*(height/2)*2); // size of image
1286 SCR_CaptureVideo_RIFF_Write32(0); // x pixels per meter
1287 SCR_CaptureVideo_RIFF_Write32(0); // y pixels per meter
1288 SCR_CaptureVideo_RIFF_Write32(0); // color used
1289 SCR_CaptureVideo_RIFF_Write32(0); // color important
1290 SCR_CaptureVideo_RIFF_Pop();
1292 SCR_CaptureVideo_RIFF_Push("indx", NULL);
1293 SCR_CaptureVideo_RIFF_Write16(4); // wLongsPerEntry
1294 SCR_CaptureVideo_RIFF_Write16(0); // bIndexSubType=0, bIndexType=0
1295 cls.capturevideo.videofile_ix_master_video_inuse_offset = SCR_CaptureVideo_RIFF_GetPosition();
1296 SCR_CaptureVideo_RIFF_Write32(0); // nEntriesInUse
1297 SCR_CaptureVideo_RIFF_WriteFourCC("00dc"); // dwChunkId
1298 SCR_CaptureVideo_RIFF_Write32(0); // dwReserved1
1299 SCR_CaptureVideo_RIFF_Write32(0); // dwReserved2
1300 SCR_CaptureVideo_RIFF_Write32(0); // dwReserved3
1301 cls.capturevideo.videofile_ix_master_video_start_offset = SCR_CaptureVideo_RIFF_GetPosition();
1302 for(i = 0; i < AVI_MASTER_INDEX_SIZE * 4; ++i)
1303 SCR_CaptureVideo_RIFF_Write32(0); // fill up later
1304 SCR_CaptureVideo_RIFF_Pop();
1305 // extended format (aspect!)
1306 SCR_CaptureVideo_RIFF_Push("vprp", NULL);
1307 SCR_CaptureVideo_RIFF_Write32(0); // VideoFormatToken
1308 SCR_CaptureVideo_RIFF_Write32(0); // VideoStandard
1309 SCR_CaptureVideo_RIFF_Write32((int)cls.capturevideo.framerate); // dwVerticalRefreshRate (bogus)
1310 SCR_CaptureVideo_RIFF_Write32(width); // dwHTotalInT
1311 SCR_CaptureVideo_RIFF_Write32(height); // dwVTotalInLines
1312 FindFraction(aspect, &n, &d, 1000);
1313 SCR_CaptureVideo_RIFF_Write32((n << 16) | d); // dwFrameAspectRatio // TODO a word
1314 SCR_CaptureVideo_RIFF_Write32(width); // dwFrameWidthInPixels
1315 SCR_CaptureVideo_RIFF_Write32(height); // dwFrameHeightInLines
1316 SCR_CaptureVideo_RIFF_Write32(1); // nFieldPerFrame
1317 SCR_CaptureVideo_RIFF_Write32(width); // CompressedBMWidth
1318 SCR_CaptureVideo_RIFF_Write32(height); // CompressedBMHeight
1319 SCR_CaptureVideo_RIFF_Write32(width); // ValidBMHeight
1320 SCR_CaptureVideo_RIFF_Write32(height); // ValidBMWidth
1321 SCR_CaptureVideo_RIFF_Write32(0); // ValidBMXOffset
1322 SCR_CaptureVideo_RIFF_Write32(0); // ValidBMYOffset
1323 SCR_CaptureVideo_RIFF_Write32(0); // ValidBMXOffsetInT
1324 SCR_CaptureVideo_RIFF_Write32(0); // ValidBMYValidStartLine
1325 SCR_CaptureVideo_RIFF_Pop();
1326 SCR_CaptureVideo_RIFF_Pop();
1327 if (cls.capturevideo.soundrate)
1329 // audio stream info
1330 SCR_CaptureVideo_RIFF_Push("LIST", "strl");
1331 SCR_CaptureVideo_RIFF_Push("strh", "auds");
1332 SCR_CaptureVideo_RIFF_Write32(1); // stream fourcc (PCM audio, uncompressed)
1333 SCR_CaptureVideo_RIFF_Write32(0); // flags
1334 SCR_CaptureVideo_RIFF_Write16(0); // priority
1335 SCR_CaptureVideo_RIFF_Write16(0); // language
1336 SCR_CaptureVideo_RIFF_Write32(0); // initial frames
1337 SCR_CaptureVideo_RIFF_Write32(1); // samples/second divisor
1338 SCR_CaptureVideo_RIFF_Write32((int)(cls.capturevideo.soundrate)); // samples/second multiplied by divisor
1339 SCR_CaptureVideo_RIFF_Write32(0); // start
1340 cls.capturevideo.videofile_totalsampleframes_offset = SCR_CaptureVideo_RIFF_GetPosition();
1341 SCR_CaptureVideo_RIFF_Write32(0); // length
1342 SCR_CaptureVideo_RIFF_Write32(cls.capturevideo.soundrate * 2); // suggested buffer size (this is a half second)
1343 SCR_CaptureVideo_RIFF_Write32(0); // quality
1344 SCR_CaptureVideo_RIFF_Write32(4); // sample size
1345 SCR_CaptureVideo_RIFF_Write16(0); // frame left
1346 SCR_CaptureVideo_RIFF_Write16(0); // frame top
1347 SCR_CaptureVideo_RIFF_Write16(0); // frame right
1348 SCR_CaptureVideo_RIFF_Write16(0); // frame bottom
1349 SCR_CaptureVideo_RIFF_Pop();
1350 // audio stream format
1351 SCR_CaptureVideo_RIFF_Push("strf", NULL);
1352 SCR_CaptureVideo_RIFF_Write16(1); // format (uncompressed PCM?)
1353 SCR_CaptureVideo_RIFF_Write16(2); // channels (stereo)
1354 SCR_CaptureVideo_RIFF_Write32(cls.capturevideo.soundrate); // sampleframes per second
1355 SCR_CaptureVideo_RIFF_Write32(cls.capturevideo.soundrate * 4); // average bytes per second
1356 SCR_CaptureVideo_RIFF_Write16(4); // block align
1357 SCR_CaptureVideo_RIFF_Write16(16); // bits per sample
1358 SCR_CaptureVideo_RIFF_Write16(0); // size
1359 SCR_CaptureVideo_RIFF_Pop();
1361 SCR_CaptureVideo_RIFF_Push("indx", NULL);
1362 SCR_CaptureVideo_RIFF_Write16(4); // wLongsPerEntry
1363 SCR_CaptureVideo_RIFF_Write16(0); // bIndexSubType=0, bIndexType=0
1364 cls.capturevideo.videofile_ix_master_audio_inuse_offset = SCR_CaptureVideo_RIFF_GetPosition();
1365 SCR_CaptureVideo_RIFF_Write32(0); // nEntriesInUse
1366 SCR_CaptureVideo_RIFF_WriteFourCC("01wb"); // dwChunkId
1367 SCR_CaptureVideo_RIFF_Write32(0); // dwReserved1
1368 SCR_CaptureVideo_RIFF_Write32(0); // dwReserved2
1369 SCR_CaptureVideo_RIFF_Write32(0); // dwReserved3
1370 cls.capturevideo.videofile_ix_master_audio_start_offset = SCR_CaptureVideo_RIFF_GetPosition();
1371 for(i = 0; i < AVI_MASTER_INDEX_SIZE * 4; ++i)
1372 SCR_CaptureVideo_RIFF_Write32(0); // fill up later
1373 SCR_CaptureVideo_RIFF_Pop();
1374 SCR_CaptureVideo_RIFF_Pop();
1377 cls.capturevideo.videofile_ix_master_audio_inuse = cls.capturevideo.videofile_ix_master_video_inuse = 0;
1379 // extended header (for total #frames)
1380 SCR_CaptureVideo_RIFF_Push("LIST", "odml");
1381 SCR_CaptureVideo_RIFF_Push("dmlh", NULL);
1382 cls.capturevideo.videofile_totalframes_offset2 = SCR_CaptureVideo_RIFF_GetPosition();
1383 SCR_CaptureVideo_RIFF_Write32(0);
1384 SCR_CaptureVideo_RIFF_Pop();
1385 SCR_CaptureVideo_RIFF_Pop();
1387 // close the AVI header list
1388 SCR_CaptureVideo_RIFF_Pop();
1389 // software that produced this AVI video file
1390 SCR_CaptureVideo_RIFF_Push("LIST", "INFO");
1391 SCR_CaptureVideo_RIFF_Push("ISFT", NULL);
1392 SCR_CaptureVideo_RIFF_WriteTerminatedString(engineversion);
1393 SCR_CaptureVideo_RIFF_Pop();
1394 // enable this junk filler if you like the LIST movi to always begin at 4KB in the file (why?)
1396 SCR_CaptureVideo_RIFF_Push("JUNK", NULL);
1397 x = 4096 - SCR_CaptureVideo_RIFF_GetPosition();
1400 const char *junkfiller = "[ DarkPlaces junk data ]";
1401 int i = min(x, (int)strlen(junkfiller));
1402 SCR_CaptureVideo_RIFF_WriteBytes((const unsigned char *)junkfiller, i);
1405 SCR_CaptureVideo_RIFF_Pop();
1407 SCR_CaptureVideo_RIFF_Pop();
1408 // begin the actual video section now
1409 SCR_CaptureVideo_RIFF_Push("LIST", "movi");
1410 cls.capturevideo.videofile_ix_movistart = cls.capturevideo.riffstackstartoffset[1];
1411 // we're done with the headers now...
1412 SCR_CaptureVideo_RIFF_Flush();
1413 if (cls.capturevideo.riffstacklevel != 2)
1414 Sys_Error("SCR_CaptureVideo_BeginVideo: broken AVI writing code (stack level is %i (should be 2) at end of headers)\n", cls.capturevideo.riffstacklevel);
1417 switch(cls.capturevideo.format)
1419 case CAPTUREVIDEOFORMAT_AVI_I420:
1426 void SCR_CaptureVideo_EndVideo(void)
1428 if (!cls.capturevideo.active)
1430 cls.capturevideo.active = false;
1431 if (cls.capturevideo.videofile)
1433 switch(cls.capturevideo.format)
1435 case CAPTUREVIDEOFORMAT_AVI_I420:
1436 // close any open chunks
1437 SCR_CaptureVideo_RIFF_Finish(true);
1438 // go back and fix the video frames and audio samples fields
1439 Con_DPrintf("Finishing capture (%d frames, %d audio frames)\n", cls.capturevideo.frame, cls.capturevideo.soundsampleframe);
1440 FS_Seek(cls.capturevideo.videofile, cls.capturevideo.videofile_totalframes_offset1, SEEK_SET);
1441 SCR_CaptureVideo_RIFF_Write32(cls.capturevideo.frame);
1442 SCR_CaptureVideo_RIFF_Flush();
1443 FS_Seek(cls.capturevideo.videofile, cls.capturevideo.videofile_totalframes_offset2, SEEK_SET);
1444 SCR_CaptureVideo_RIFF_Write32(cls.capturevideo.frame);
1445 SCR_CaptureVideo_RIFF_Flush();
1446 if (cls.capturevideo.soundrate)
1448 FS_Seek(cls.capturevideo.videofile, cls.capturevideo.videofile_totalsampleframes_offset, SEEK_SET);
1449 SCR_CaptureVideo_RIFF_Write32(cls.capturevideo.soundsampleframe);
1450 SCR_CaptureVideo_RIFF_Flush();
1456 FS_Close(cls.capturevideo.videofile);
1457 cls.capturevideo.videofile = NULL;
1460 if (cls.capturevideo.screenbuffer)
1462 Mem_Free (cls.capturevideo.screenbuffer);
1463 cls.capturevideo.screenbuffer = NULL;
1466 if (cls.capturevideo.outbuffer)
1468 Mem_Free (cls.capturevideo.outbuffer);
1469 cls.capturevideo.outbuffer = NULL;
1472 if (cls.capturevideo.riffindexbuffer.data)
1474 Mem_Free(cls.capturevideo.riffindexbuffer.data);
1475 cls.capturevideo.riffindexbuffer.data = NULL;
1478 memset(&cls.capturevideo, 0, sizeof(cls.capturevideo));
1481 // converts from BGRA32 to I420 colorspace (identical to YV12 except chroma plane order is reversed), this colorspace is handled by the Intel(r) 4:2:0 codec on Windows
1482 void SCR_CaptureVideo_ConvertFrame_BGRA_to_I420_flip(int width, int height, unsigned char *instart, unsigned char *outstart)
1485 int blockr, blockg, blockb;
1486 int outoffset = (width/2)*(height/2);
1487 unsigned char *b, *out;
1488 // process one line at a time, and CbCr every other line at 2 pixel intervals
1489 for (y = 0;y < height;y++)
1492 for (b = instart + (height-1-y)*width*4, out = outstart + y*width, x = 0;x < width;x++, b += 4, out++)
1497 *out = cls.capturevideo.yuvnormalizetable[0][cls.capturevideo.rgbtoyuvscaletable[0][0][blockr] + cls.capturevideo.rgbtoyuvscaletable[0][1][blockg] + cls.capturevideo.rgbtoyuvscaletable[0][2][blockb]];
1501 // 2x2 Cr and Cb planes
1502 int inpitch = width*4;
1503 for (b = instart + (height-2-y)*width*4, out = outstart + width*height + (y/2)*(width/2), x = 0;x < width/2;x++, b += 8, out++)
1505 blockr = (b[2] + b[6] + b[inpitch+2] + b[inpitch+6]) >> 2;
1506 blockg = (b[1] + b[5] + b[inpitch+1] + b[inpitch+5]) >> 2;
1507 blockb = (b[0] + b[4] + b[inpitch+0] + b[inpitch+4]) >> 2;
1509 out[0 ] = cls.capturevideo.yuvnormalizetable[1][cls.capturevideo.rgbtoyuvscaletable[1][0][blockr] + cls.capturevideo.rgbtoyuvscaletable[1][1][blockg] + cls.capturevideo.rgbtoyuvscaletable[1][2][blockb] + 128];
1511 out[outoffset] = cls.capturevideo.yuvnormalizetable[2][cls.capturevideo.rgbtoyuvscaletable[2][0][blockr] + cls.capturevideo.rgbtoyuvscaletable[2][1][blockg] + cls.capturevideo.rgbtoyuvscaletable[2][2][blockb] + 128];
1517 static void SCR_ScaleDownBGRA(unsigned char *in, int inw, int inh, unsigned char *out, int outw, int outh)
1519 // TODO optimize this function
1524 // memcpy is faster than me
1525 if(inw == outw && inh == outh)
1527 memcpy(out, in, 4 * inw * inh);
1531 // otherwise: a box filter
1532 area = (float)outw * (float)outh / (float)inw / (float)inh;
1533 for(y = 0; y < outh; ++y)
1535 float iny0 = y / (float)outh * inh; int iny0_i = floor(iny0);
1536 float iny1 = (y+1) / (float)outh * inh; int iny1_i = ceil(iny1);
1537 for(x = 0; x < outw; ++x)
1539 float inx0 = x / (float)outw * inw; int inx0_i = floor(inx0);
1540 float inx1 = (x+1) / (float)outw * inw; int inx1_i = ceil(inx1);
1541 float r = 0, g = 0, b = 0, alpha = 0;
1544 for(yy = iny0_i; yy < iny1_i; ++yy)
1546 float ya = min(yy+1, iny1) - max(iny0, yy);
1547 for(xx = inx0_i; xx < inx1_i; ++xx)
1549 float a = ya * (min(xx+1, inx1) - max(inx0, xx));
1550 r += a * in[4*(xx + inw * yy)+0];
1551 g += a * in[4*(xx + inw * yy)+1];
1552 b += a * in[4*(xx + inw * yy)+2];
1553 alpha += a * in[4*(xx + inw * yy)+3];
1557 out[4*(x + outw * y)+0] = r * area;
1558 out[4*(x + outw * y)+1] = g * area;
1559 out[4*(x + outw * y)+2] = b * area;
1560 out[4*(x + outw * y)+3] = alpha * area;
1565 qboolean SCR_CaptureVideo_VideoFrame(int newframenum)
1567 int x = 0, y = 0, width = cls.capturevideo.width, height = cls.capturevideo.height;
1568 unsigned char *in, *out;
1570 //return SCR_ScreenShot(filename, cls.capturevideo.buffer, cls.capturevideo.buffer + vid.width * vid.height * 3, cls.capturevideo.buffer + vid.width * vid.height * 6, 0, 0, vid.width, vid.height, false, false, false, jpeg, true);
1571 // speed is critical here, so do saving as directly as possible
1572 switch (cls.capturevideo.format)
1574 case CAPTUREVIDEOFORMAT_AVI_I420:
1575 // if there's no videofile we have to just give up, and abort saving
1576 if (!cls.capturevideo.videofile)
1578 // FIXME: width/height must be multiple of 2, enforce this?
1579 qglReadPixels (x, y, vid.width, vid.height, GL_BGRA, GL_UNSIGNED_BYTE, cls.capturevideo.screenbuffer);CHECKGLERROR
1580 SCR_ScaleDownBGRA (cls.capturevideo.screenbuffer, vid.width, vid.height, cls.capturevideo.outbuffer, width, height);
1581 in = cls.capturevideo.outbuffer;
1582 out = cls.capturevideo.outbuffer + width*height*4;
1583 SCR_CaptureVideo_ConvertFrame_BGRA_to_I420_flip(width, height, in, out);
1584 x = width*height+(width/2)*(height/2)*2;
1585 SCR_CaptureVideo_RIFF_OverflowCheck(8 + x);
1586 for (;cls.capturevideo.frame < newframenum;cls.capturevideo.frame++)
1588 SCR_CaptureVideo_RIFF_IndexEntry("00dc", x, 0x10); // AVIIF_KEYFRAME
1589 SCR_CaptureVideo_RIFF_Push("00dc", NULL);
1590 SCR_CaptureVideo_RIFF_WriteBytes(out, x);
1591 SCR_CaptureVideo_RIFF_Pop();
1599 void SCR_CaptureVideo_SoundFrame(unsigned char *bufstereo16le, size_t length, int rate)
1602 cls.capturevideo.soundrate = rate;
1603 cls.capturevideo.soundsampleframe += length;
1604 switch (cls.capturevideo.format)
1606 case CAPTUREVIDEOFORMAT_AVI_I420:
1608 SCR_CaptureVideo_RIFF_OverflowCheck(8 + x);
1609 SCR_CaptureVideo_RIFF_IndexEntry("01wb", x, 0x10); // AVIIF_KEYFRAME
1610 SCR_CaptureVideo_RIFF_Push("01wb", NULL);
1611 SCR_CaptureVideo_RIFF_WriteBytes(bufstereo16le, x);
1612 SCR_CaptureVideo_RIFF_Pop();
1619 void SCR_CaptureVideo(void)
1622 if (cl_capturevideo.integer && r_render.integer)
1624 if (!cls.capturevideo.active)
1625 SCR_CaptureVideo_BeginVideo();
1626 if (cls.capturevideo.framerate != cl_capturevideo_fps.value)
1628 Con_Printf("You can not change the video framerate while recording a video.\n");
1629 Cvar_SetValueQuick(&cl_capturevideo_fps, cls.capturevideo.framerate);
1631 // for AVI saving we have to make sure that sound is saved before video
1632 if (cls.capturevideo.soundrate && !cls.capturevideo.soundsampleframe)
1634 if (cls.capturevideo.realtime)
1636 // preserve sound sync by duplicating frames when running slow
1637 newframenum = (int)((realtime - cls.capturevideo.starttime) * cls.capturevideo.framerate);
1640 newframenum = cls.capturevideo.frame + 1;
1641 // if falling behind more than one second, stop
1642 if (newframenum - cls.capturevideo.frame > 60 * (int)ceil(cls.capturevideo.framerate))
1644 Cvar_SetValueQuick(&cl_capturevideo, 0);
1645 Con_Printf("video saving failed on frame %i, your machine is too slow for this capture speed.\n", cls.capturevideo.frame);
1646 SCR_CaptureVideo_EndVideo();
1650 SCR_CaptureVideo_VideoFrame(newframenum);
1651 if (cls.capturevideo.error)
1653 Cvar_SetValueQuick(&cl_capturevideo, 0);
1654 Con_Printf("video saving failed on frame %i, out of disk space? stopping video capture.\n", cls.capturevideo.frame);
1655 SCR_CaptureVideo_EndVideo();
1658 else if (cls.capturevideo.active)
1659 SCR_CaptureVideo_EndVideo();
1666 Grab six views for environment mapping tests
1673 qboolean flipx, flipy, flipdiagonaly;
1677 {{ 0, 0, 0}, "rt", false, false, false},
1678 {{ 0, 270, 0}, "ft", false, false, false},
1679 {{ 0, 180, 0}, "lf", false, false, false},
1680 {{ 0, 90, 0}, "bk", false, false, false},
1681 {{-90, 180, 0}, "up", true, true, false},
1682 {{ 90, 180, 0}, "dn", true, true, false},
1684 {{ 0, 0, 0}, "px", true, true, true},
1685 {{ 0, 90, 0}, "py", false, true, false},
1686 {{ 0, 180, 0}, "nx", false, false, true},
1687 {{ 0, 270, 0}, "ny", true, false, false},
1688 {{-90, 180, 0}, "pz", false, false, true},
1689 {{ 90, 180, 0}, "nz", false, false, true}
1692 static void R_Envmap_f (void)
1695 char filename[MAX_QPATH], basename[MAX_QPATH];
1696 unsigned char *buffer1;
1697 unsigned char *buffer2;
1698 unsigned char *buffer3;
1700 if (Cmd_Argc() != 3)
1702 Con_Print("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");
1706 strlcpy (basename, Cmd_Argv(1), sizeof (basename));
1707 size = atoi(Cmd_Argv(2));
1708 if (size != 128 && size != 256 && size != 512 && size != 1024)
1710 Con_Print("envmap: size must be one of 128, 256, 512, or 1024\n");
1713 if (size > vid.width || size > vid.height)
1715 Con_Print("envmap: your resolution is not big enough to render that size\n");
1719 r_refdef.envmap = true;
1721 R_UpdateVariables();
1723 r_refdef.view.x = 0;
1724 r_refdef.view.y = 0;
1725 r_refdef.view.z = 0;
1726 r_refdef.view.width = size;
1727 r_refdef.view.height = size;
1728 r_refdef.view.depth = 1;
1729 r_refdef.view.useperspective = true;
1730 r_refdef.view.isoverlay = false;
1732 r_refdef.view.frustum_x = tan(90 * M_PI / 360.0);
1733 r_refdef.view.frustum_y = tan(90 * M_PI / 360.0);
1735 buffer1 = (unsigned char *)Mem_Alloc(tempmempool, size * size * 3);
1736 buffer2 = (unsigned char *)Mem_Alloc(tempmempool, size * size * 3);
1737 buffer3 = (unsigned char *)Mem_Alloc(tempmempool, size * size * 3 + 18);
1739 for (j = 0;j < 12;j++)
1741 dpsnprintf(filename, sizeof(filename), "env/%s%s.tga", basename, envmapinfo[j].name);
1742 Matrix4x4_CreateFromQuakeEntity(&r_refdef.view.matrix, r_refdef.view.origin[0], r_refdef.view.origin[1], r_refdef.view.origin[2], envmapinfo[j].angles[0], envmapinfo[j].angles[1], envmapinfo[j].angles[2], 1);
1743 r_refdef.view.quality = 1;
1744 r_refdef.view.clear = true;
1748 SCR_ScreenShot(filename, buffer1, buffer2, buffer3, 0, vid.height - (r_refdef.view.y + r_refdef.view.height), size, size, envmapinfo[j].flipx, envmapinfo[j].flipy, envmapinfo[j].flipdiagonaly, false, false);
1755 r_refdef.envmap = false;
1758 //=============================================================================
1760 void SHOWLMP_decodehide(void)
1764 lmplabel = MSG_ReadString();
1765 for (i = 0;i < cl.num_showlmps;i++)
1766 if (cl.showlmps[i].isactive && strcmp(cl.showlmps[i].label, lmplabel) == 0)
1768 cl.showlmps[i].isactive = false;
1773 void SHOWLMP_decodeshow(void)
1776 char lmplabel[256], picname[256];
1778 strlcpy (lmplabel,MSG_ReadString(), sizeof (lmplabel));
1779 strlcpy (picname, MSG_ReadString(), sizeof (picname));
1780 if (gamemode == GAME_NEHAHRA) // LordHavoc: nasty old legacy junk
1787 x = MSG_ReadShort();
1788 y = MSG_ReadShort();
1790 if (!cl.showlmps || cl.num_showlmps >= cl.max_showlmps)
1792 showlmp_t *oldshowlmps = cl.showlmps;
1793 cl.max_showlmps += 16;
1794 cl.showlmps = Mem_Alloc(cls.levelmempool, cl.max_showlmps * sizeof(showlmp_t));
1795 if (cl.num_showlmps)
1796 memcpy(cl.showlmps, oldshowlmps, cl.num_showlmps * sizeof(showlmp_t));
1798 Mem_Free(oldshowlmps);
1800 for (k = 0;k < cl.max_showlmps;k++)
1801 if (cl.showlmps[k].isactive && !strcmp(cl.showlmps[k].label, lmplabel))
1803 if (k == cl.max_showlmps)
1804 for (k = 0;k < cl.max_showlmps;k++)
1805 if (!cl.showlmps[k].isactive)
1807 cl.showlmps[k].isactive = true;
1808 strlcpy (cl.showlmps[k].label, lmplabel, sizeof (cl.showlmps[k].label));
1809 strlcpy (cl.showlmps[k].pic, picname, sizeof (cl.showlmps[k].pic));
1810 cl.showlmps[k].x = x;
1811 cl.showlmps[k].y = y;
1812 cl.num_showlmps = max(cl.num_showlmps, k + 1);
1815 void SHOWLMP_drawall(void)
1818 for (i = 0;i < cl.num_showlmps;i++)
1819 if (cl.showlmps[i].isactive)
1820 DrawQ_Pic(cl.showlmps[i].x, cl.showlmps[i].y, Draw_CachePic (cl.showlmps[i].pic), 0, 0, 1, 1, 1, 1, 0);
1824 ==============================================================================
1828 ==============================================================================
1831 qboolean SCR_ScreenShot(char *filename, unsigned char *buffer1, unsigned char *buffer2, unsigned char *buffer3, int x, int y, int width, int height, qboolean flipx, qboolean flipy, qboolean flipdiagonal, qboolean jpeg, qboolean gammacorrect)
1833 int indices[3] = {0,1,2};
1836 if (!r_render.integer)
1840 qglReadPixels (x, y, width, height, jpeg ? GL_RGB : GL_BGR, GL_UNSIGNED_BYTE, buffer1);CHECKGLERROR
1842 if (scr_screenshot_gammaboost.value != 1 && gammacorrect)
1845 double igamma = 1.0 / scr_screenshot_gammaboost.value;
1846 unsigned char ramp[256];
1847 for (i = 0;i < 256;i++)
1848 ramp[i] = (unsigned char) (pow(i * (1.0 / 255.0), igamma) * 255.0);
1849 for (i = 0;i < width*height*3;i++)
1850 buffer1[i] = ramp[buffer1[i]];
1853 Image_CopyMux (buffer2, buffer1, width, height, flipx, flipy, flipdiagonal, 3, 3, indices);
1856 ret = JPEG_SaveImage_preflipped (filename, width, height, buffer2);
1858 ret = Image_WriteTGABGR_preflipped (filename, width, height, buffer2, buffer3);
1863 //=============================================================================
1865 extern void R_UpdateFogColor(void);
1866 void R_ClearScreen(qboolean fogcolor)
1873 qglClearColor(r_refdef.fogcolor[0],r_refdef.fogcolor[1],r_refdef.fogcolor[2],0);CHECKGLERROR
1877 qglClearColor(0,0,0,0);CHECKGLERROR
1879 qglClearDepth(1);CHECKGLERROR
1882 // LordHavoc: we use a stencil centered around 128 instead of 0,
1883 // to avoid clamping interfering with strange shadow volume
1885 qglClearStencil(128);CHECKGLERROR
1888 if (r_render.integer)
1889 GL_Clear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | (gl_stencil ? GL_STENCIL_BUFFER_BIT : 0));
1890 // set dithering mode
1891 if (gl_dither.integer)
1893 qglEnable(GL_DITHER);CHECKGLERROR
1897 qglDisable(GL_DITHER);CHECKGLERROR
1901 qboolean CL_VM_UpdateView (void);
1902 void SCR_DrawConsole (void);
1903 void R_Shadow_EditLights_DrawSelectedLightProperties(void);
1907 void SCR_DrawScreen (void)
1911 R_TimeReport_BeginFrame();
1913 R_UpdateVariables();
1915 // Quake uses clockwise winding, so these are swapped
1916 r_refdef.view.cullface_front = GL_BACK;
1917 r_refdef.view.cullface_back = GL_FRONT;
1919 if (cls.signon == SIGNONS)
1923 size = scr_viewsize.value * (1.0 / 100.0);
1924 size = min(size, 1);
1926 if (r_stereo_sidebyside.integer)
1928 r_refdef.view.width = (int)(vid.width * size / 2.5);
1929 r_refdef.view.height = (int)(vid.height * size / 2.5 * (1 - bound(0, r_letterbox.value, 100) / 100));
1930 r_refdef.view.depth = 1;
1931 r_refdef.view.x = (int)((vid.width - r_refdef.view.width * 2.5) * 0.5);
1932 r_refdef.view.y = (int)((vid.height - r_refdef.view.height)/2);
1933 r_refdef.view.z = 0;
1935 r_refdef.view.x += (int)(r_refdef.view.width * 1.5);
1939 r_refdef.view.width = (int)(vid.width * size);
1940 r_refdef.view.height = (int)(vid.height * size * (1 - bound(0, r_letterbox.value, 100) / 100));
1941 r_refdef.view.depth = 1;
1942 r_refdef.view.x = (int)((vid.width - r_refdef.view.width)/2);
1943 r_refdef.view.y = (int)((vid.height - r_refdef.view.height)/2);
1944 r_refdef.view.z = 0;
1947 // LordHavoc: viewzoom (zoom in for sniper rifles, etc)
1948 // LordHavoc: this is designed to produce widescreen fov values
1949 // when the screen is wider than 4/3 width/height aspect, to do
1950 // this it simply assumes the requested fov is the vertical fov
1951 // for a 4x3 display, if the ratio is not 4x3 this makes the fov
1952 // higher/lower according to the ratio
1953 r_refdef.view.useperspective = true;
1954 r_refdef.view.frustum_y = tan(scr_fov.value * M_PI / 360.0) * (3.0/4.0) * cl.viewzoom;
1955 r_refdef.view.frustum_x = r_refdef.view.frustum_y * (float)r_refdef.view.width / (float)r_refdef.view.height / vid_pixelheight.value;
1957 r_refdef.view.frustum_x *= r_refdef.frustumscale_x;
1958 r_refdef.view.frustum_y *= r_refdef.frustumscale_y;
1960 if(!CL_VM_UpdateView())
1963 if (scr_zoomwindow.integer)
1965 float sizex = bound(10, scr_zoomwindow_viewsizex.value, 100) / 100.0;
1966 float sizey = bound(10, scr_zoomwindow_viewsizey.value, 100) / 100.0;
1967 r_refdef.view.width = (int)(vid.width * sizex);
1968 r_refdef.view.height = (int)(vid.height * sizey);
1969 r_refdef.view.depth = 1;
1970 r_refdef.view.x = (int)((vid.width - r_refdef.view.width)/2);
1971 r_refdef.view.y = 0;
1972 r_refdef.view.z = 0;
1974 r_refdef.view.useperspective = true;
1975 r_refdef.view.frustum_y = tan(scr_zoomwindow_fov.value * M_PI / 360.0) * (3.0/4.0) * cl.viewzoom;
1976 r_refdef.view.frustum_x = r_refdef.view.frustum_y * vid_pixelheight.value * (float)r_refdef.view.width / (float)r_refdef.view.height;
1978 r_refdef.view.frustum_x *= r_refdef.frustumscale_x;
1979 r_refdef.view.frustum_y *= r_refdef.frustumscale_y;
1981 if(!CL_VM_UpdateView())
1986 if (!r_stereo_sidebyside.integer)
1988 r_refdef.view.width = vid.width;
1989 r_refdef.view.height = vid.height;
1990 r_refdef.view.depth = 1;
1991 r_refdef.view.x = 0;
1992 r_refdef.view.y = 0;
1993 r_refdef.view.z = 0;
1994 r_refdef.view.useperspective = false;
1998 if(!scr_con_current && !(key_consoleactive & KEY_CONSOLEACTIVE_FORCED))
1999 if ((key_dest == key_game || key_dest == key_message) && !r_letterbox.value)
2000 Con_DrawNotify (); // only draw notify in game
2002 if (cls.signon == SIGNONS)
2007 if (!r_letterbox.value)
2010 SCR_CheckDrawCenterString();
2012 SCR_DrawNetGraph ();
2015 R_Shadow_EditLights_DrawSelectedLightProperties();
2023 if (r_timereport_active)
2026 if (cls.signon == SIGNONS)
2027 R_TimeReport_EndFrame();
2036 void SCR_UpdateLoadingScreen (qboolean clear)
2041 float texcoord2f[8];
2042 // don't do anything if not initialized yet
2043 if (vid_hidden || !scr_refresh.integer)
2045 // release mouse grab while loading
2046 if (!vid.fullscreen)
2047 VID_SetMouse(false, false, false);
2049 qglViewport(0, 0, vid.width, vid.height);CHECKGLERROR
2050 //qglDisable(GL_SCISSOR_TEST);CHECKGLERROR
2051 //qglDepthMask(1);CHECKGLERROR
2052 qglColorMask(1,1,1,1);CHECKGLERROR
2053 qglClearColor(0,0,0,0);CHECKGLERROR
2054 // when starting up a new video mode, make sure the screen is cleared to black
2057 qglClear(GL_COLOR_BUFFER_BIT);CHECKGLERROR
2059 //qglDisable(GL_CULL_FACE);CHECKGLERROR
2062 GL_SetupView_Mode_Ortho(0, 0, vid_conwidth.integer, vid_conheight.integer, -10, 100);
2064 R_Mesh_Matrix(&identitymatrix);
2065 // draw the loading plaque
2066 pic = Draw_CachePic ("gfx/loading");
2067 x = (vid_conwidth.integer - pic->width)/2;
2068 y = (vid_conheight.integer - pic->height)/2;
2070 GL_BlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
2071 GL_DepthRange(0, 1);
2072 GL_PolygonOffset(0, 0);
2073 GL_DepthTest(false);
2074 R_Mesh_VertexPointer(vertex3f, 0, 0);
2075 R_Mesh_ColorPointer(NULL, 0, 0);
2076 R_Mesh_ResetTextureState();
2077 R_Mesh_TexBind(0, R_GetTexture(pic->tex));
2078 R_Mesh_TexCoordPointer(0, 2, texcoord2f, 0, 0);
2079 R_SetupGenericShader(true);
2080 vertex3f[2] = vertex3f[5] = vertex3f[8] = vertex3f[11] = 0;
2081 vertex3f[0] = vertex3f[9] = x;
2082 vertex3f[1] = vertex3f[4] = y;
2083 vertex3f[3] = vertex3f[6] = x + pic->width;
2084 vertex3f[7] = vertex3f[10] = y + pic->height;
2085 texcoord2f[0] = 0;texcoord2f[1] = 0;
2086 texcoord2f[2] = 1;texcoord2f[3] = 0;
2087 texcoord2f[4] = 1;texcoord2f[5] = 1;
2088 texcoord2f[6] = 0;texcoord2f[7] = 1;
2089 if (vid.stereobuffer)
2091 qglDrawBuffer(GL_FRONT_LEFT);
2092 R_Mesh_Draw(0, 4, 0, 2, NULL, polygonelements, 0, 0);
2093 qglDrawBuffer(GL_FRONT_RIGHT);
2094 R_Mesh_Draw(0, 4, 0, 2, NULL, polygonelements, 0, 0);
2098 qglDrawBuffer(GL_FRONT);
2099 R_Mesh_Draw(0, 4, 0, 2, NULL, polygonelements, 0, 0);
2103 // not necessary when rendering to GL_FRONT buffers
2105 // however this IS necessary on Windows Vista
2109 extern cvar_t cl_minfps;
2110 extern cvar_t cl_minfps_fade;
2111 extern cvar_t cl_minfps_qualitymax;
2112 extern cvar_t cl_minfps_qualitymin;
2113 extern cvar_t cl_minfps_qualitypower;
2114 extern cvar_t cl_minfps_qualityscale;
2115 static double cl_updatescreen_rendertime = 0;
2116 static double cl_updatescreen_quality = 1;
2117 void CL_UpdateScreen(void)
2120 float conwidth, conheight;
2122 if (!scr_initialized || !con_initialized)
2123 return; // not initialized yet
2125 if(gamemode == GAME_NEXUIZ)
2127 // play a bit with the palette (experimental)
2128 palette_rgb_pantscolormap[15][0] = 128 + 127 * sin(cl.time / exp(1) + 0*M_PI/3);
2129 palette_rgb_pantscolormap[15][1] = 128 + 127 * sin(cl.time / exp(1) + 2*M_PI/3);
2130 palette_rgb_pantscolormap[15][2] = 128 + 127 * sin(cl.time / exp(1) + 4*M_PI/3);
2131 palette_rgb_shirtcolormap[15][0] = 128 + 127 * sin(cl.time / M_PI + 5*M_PI/3);
2132 palette_rgb_shirtcolormap[15][1] = 128 + 127 * sin(cl.time / M_PI + 3*M_PI/3);
2133 palette_rgb_shirtcolormap[15][2] = 128 + 127 * sin(cl.time / M_PI + 1*M_PI/3);
2134 memcpy(palette_rgb_pantsscoreboard[15], palette_rgb_pantscolormap[15], sizeof(*palette_rgb_pantscolormap));
2135 memcpy(palette_rgb_shirtscoreboard[15], palette_rgb_shirtcolormap[15], sizeof(*palette_rgb_shirtcolormap));
2138 if (vid_hidden || !scr_refresh.integer)
2141 rendertime1 = Sys_DoubleTime();
2143 conwidth = bound(320, vid_conwidth.value, 2048);
2144 conheight = bound(200, vid_conheight.value, 1536);
2145 if (vid_conwidth.value != conwidth)
2146 Cvar_SetValue("vid_conwidth", conwidth);
2147 if (vid_conheight.value != conheight)
2148 Cvar_SetValue("vid_conheight", conheight);
2151 if (scr_viewsize.value < 30)
2152 Cvar_Set ("viewsize","30");
2153 if (scr_viewsize.value > 120)
2154 Cvar_Set ("viewsize","120");
2156 // bound field of view
2157 if (scr_fov.value < 1)
2158 Cvar_Set ("fov","1");
2159 if (scr_fov.value > 170)
2160 Cvar_Set ("fov","170");
2162 // validate r_textureunits cvar
2163 if (r_textureunits.integer > gl_textureunits)
2164 Cvar_SetValueQuick(&r_textureunits, gl_textureunits);
2165 if (r_textureunits.integer < 1)
2166 Cvar_SetValueQuick(&r_textureunits, 1);
2168 // validate gl_combine cvar
2169 if (gl_combine.integer && !gl_combine_extension)
2170 Cvar_SetValueQuick(&gl_combine, 0);
2172 // intermission is always full screen
2173 if (cl.intermission)
2177 if (scr_viewsize.value >= 120)
2178 sb_lines = 0; // no status bar at all
2179 else if (scr_viewsize.value >= 110)
2180 sb_lines = 24; // no inventory
2185 r_refdef.view.colormask[0] = 1;
2186 r_refdef.view.colormask[1] = 1;
2187 r_refdef.view.colormask[2] = 1;
2189 SCR_SetUpToDrawConsole();
2192 qglDrawBuffer(GL_BACK);CHECKGLERROR
2193 qglViewport(0, 0, vid.width, vid.height);CHECKGLERROR
2194 qglDisable(GL_SCISSOR_TEST);CHECKGLERROR
2195 qglDepthMask(1);CHECKGLERROR
2196 qglColorMask(1,1,1,1);CHECKGLERROR
2197 qglClearColor(0,0,0,0);CHECKGLERROR
2198 R_ClearScreen(false);
2199 r_refdef.view.clear = false;
2200 r_refdef.view.isoverlay = false;
2201 r_refdef.view.quality = bound(cl_minfps_qualitymin.value, pow(cl_updatescreen_quality, cl_minfps_qualitypower.value) * cl_minfps_qualityscale.value, cl_minfps_qualitymax.value);
2203 if(scr_stipple.integer)
2205 GLubyte stipple[128];
2206 int i, s, width, parts;
2207 static int frame = 0;
2210 s = scr_stipple.integer;
2212 width = (s & 070) >> 3;
2214 qglEnable(GL_POLYGON_STIPPLE); // 0x0B42
2215 for(i = 0; i < 128; ++i)
2218 stipple[i] = (((line >> width) + frame) & ((1 << parts) - 1)) ? 0x00 : 0xFF;
2220 qglPolygonStipple(stipple);
2223 qglDisable(GL_POLYGON_STIPPLE);
2225 if (vid.stereobuffer || r_stereo_redblue.integer || r_stereo_redgreen.integer || r_stereo_redcyan.integer || r_stereo_sidebyside.integer)
2227 matrix4x4_t originalmatrix = r_refdef.view.matrix;
2228 matrix4x4_t offsetmatrix;
2229 Matrix4x4_CreateFromQuakeEntity(&offsetmatrix, 0, r_stereo_separation.value * 0.5f, 0, 0, r_stereo_angle.value * 0.5f, 0, 1);
2230 Matrix4x4_Concat(&r_refdef.view.matrix, &originalmatrix, &offsetmatrix);
2232 if (r_stereo_sidebyside.integer)
2235 if (r_stereo_redblue.integer || r_stereo_redgreen.integer || r_stereo_redcyan.integer)
2237 r_refdef.view.colormask[0] = 1;
2238 r_refdef.view.colormask[1] = 0;
2239 r_refdef.view.colormask[2] = 0;
2242 if (vid.stereobuffer)
2243 qglDrawBuffer(GL_BACK_RIGHT);
2247 Matrix4x4_CreateFromQuakeEntity(&offsetmatrix, 0, r_stereo_separation.value * -0.5f, 0, 0, r_stereo_angle.value * -0.5f, 0, 1);
2248 Matrix4x4_Concat(&r_refdef.view.matrix, &originalmatrix, &offsetmatrix);
2250 if (r_stereo_sidebyside.integer)
2253 if (r_stereo_redblue.integer || r_stereo_redgreen.integer || r_stereo_redcyan.integer)
2255 r_refdef.view.colormask[0] = 0;
2256 r_refdef.view.colormask[1] = r_stereo_redcyan.integer || r_stereo_redgreen.integer;
2257 r_refdef.view.colormask[2] = r_stereo_redcyan.integer || r_stereo_redblue.integer;
2260 if (vid.stereobuffer)
2261 qglDrawBuffer(GL_BACK_LEFT);
2265 r_refdef.view.matrix = originalmatrix;
2272 // quality adjustment according to render time
2274 cl_updatescreen_rendertime += ((Sys_DoubleTime() - rendertime1) - cl_updatescreen_rendertime) * bound(0, cl_minfps_fade.value, 1);
2275 if (cl_minfps.value > 0 && cl_updatescreen_rendertime > 0 && !cls.timedemo && (!cls.capturevideo.active || !cls.capturevideo.realtime))
2276 cl_updatescreen_quality = 1 / (cl_updatescreen_rendertime * cl_minfps.value);
2278 cl_updatescreen_quality = 1;
2280 if (!vid_activewindow)
2281 VID_SetMouse(false, false, false);
2282 else if (key_consoleactive)
2283 VID_SetMouse(vid.fullscreen, false, false);
2284 else if (key_dest == key_menu_grabbed)
2285 VID_SetMouse(true, !in_client_mouse, true);
2286 else if (key_dest == key_menu)
2287 VID_SetMouse(vid.fullscreen, !in_client_mouse, true);
2289 VID_SetMouse(vid.fullscreen, vid_mouse.integer && !cls.demoplayback && !cl.csqc_wantsmousemove, true);
2294 void CL_Screen_NewMap(void)