7 #include "cl_collision.h"
11 #ifdef CONFIG_VIDEO_CAPTURE
16 // we have to include snd_main.h here only to get access to snd_renderbuffer->format.speed when writing the AVI headers
19 cvar_t scr_viewsize = {CF_CLIENT | CF_ARCHIVE, "viewsize","100", "how large the view should be, 110 disables inventory bar, 120 disables status bar"};
20 cvar_t scr_fov = {CF_CLIENT | CF_ARCHIVE, "fov","90", "field of vision, 1-170 degrees, default 90, some players use 110-130"};
21 cvar_t scr_conalpha = {CF_CLIENT | CF_ARCHIVE, "scr_conalpha", "1", "opacity of console background gfx/conback"};
22 cvar_t scr_conalphafactor = {CF_CLIENT | CF_ARCHIVE, "scr_conalphafactor", "1", "opacity of console background gfx/conback relative to scr_conalpha; when 0, gfx/conback is not drawn"};
23 cvar_t scr_conalpha2factor = {CF_CLIENT | CF_ARCHIVE, "scr_conalpha2factor", "0", "opacity of console background gfx/conback2 relative to scr_conalpha; when 0, gfx/conback2 is not drawn"};
24 cvar_t scr_conalpha3factor = {CF_CLIENT | CF_ARCHIVE, "scr_conalpha3factor", "0", "opacity of console background gfx/conback3 relative to scr_conalpha; when 0, gfx/conback3 is not drawn"};
25 cvar_t scr_conbrightness = {CF_CLIENT | CF_ARCHIVE, "scr_conbrightness", "1", "brightness of console background (0 = black, 1 = image)"};
26 cvar_t scr_conforcewhiledisconnected = {CF_CLIENT, "scr_conforcewhiledisconnected", "1", "1 forces fullscreen console while disconnected, 2 also forces it when the listen server has started but the client is still loading"};
27 cvar_t scr_conheight = {CF_CLIENT | CF_ARCHIVE, "scr_conheight", "0.5", "fraction of screen height occupied by console (reduced as necessary for visibility of loading progress and infobar)"};
28 cvar_t scr_conscroll_x = {CF_CLIENT | CF_ARCHIVE, "scr_conscroll_x", "0", "scroll speed of gfx/conback in x direction"};
29 cvar_t scr_conscroll_y = {CF_CLIENT | CF_ARCHIVE, "scr_conscroll_y", "0", "scroll speed of gfx/conback in y direction"};
30 cvar_t scr_conscroll2_x = {CF_CLIENT | CF_ARCHIVE, "scr_conscroll2_x", "0", "scroll speed of gfx/conback2 in x direction"};
31 cvar_t scr_conscroll2_y = {CF_CLIENT | CF_ARCHIVE, "scr_conscroll2_y", "0", "scroll speed of gfx/conback2 in y direction"};
32 cvar_t scr_conscroll3_x = {CF_CLIENT | CF_ARCHIVE, "scr_conscroll3_x", "0", "scroll speed of gfx/conback3 in x direction"};
33 cvar_t scr_conscroll3_y = {CF_CLIENT | CF_ARCHIVE, "scr_conscroll3_y", "0", "scroll speed of gfx/conback3 in y direction"};
35 cvar_t scr_menuforcewhiledisconnected = {CF_CLIENT, "scr_menuforcewhiledisconnected", "0", "forces menu while disconnected"};
37 cvar_t scr_centertime = {CF_CLIENT, "scr_centertime","2", "how long centerprint messages show"};
38 cvar_t scr_showram = {CF_CLIENT | CF_ARCHIVE, "showram","1", "show ram icon if low on surface cache memory (not used)"};
39 cvar_t scr_showturtle = {CF_CLIENT | CF_ARCHIVE, "showturtle","0", "show turtle icon when framerate is too low"};
40 cvar_t scr_showpause = {CF_CLIENT | CF_ARCHIVE, "showpause","1", "show pause icon when game is paused"};
41 cvar_t scr_showbrand = {CF_CLIENT, "showbrand","0", "shows gfx/brand.tga in a corner of the screen (different values select different positions, including centered)"};
42 cvar_t scr_printspeed = {CF_CLIENT, "scr_printspeed","0", "speed of intermission printing (episode end texts), a value of 0 disables the slow printing"};
43 cvar_t scr_loadingscreen_background = {CF_CLIENT, "scr_loadingscreen_background","0", "show the last visible background during loading screen (costs one screenful of video memory)"};
44 cvar_t scr_loadingscreen_scale = {CF_CLIENT, "scr_loadingscreen_scale","1", "scale factor of the background"};
45 cvar_t scr_loadingscreen_scale_base = {CF_CLIENT, "scr_loadingscreen_scale_base","0", "0 = console pixels, 1 = video pixels"};
46 cvar_t scr_loadingscreen_scale_limit = {CF_CLIENT, "scr_loadingscreen_scale_limit","0", "0 = no limit, 1 = until first edge hits screen edge, 2 = until last edge hits screen edge, 3 = until width hits screen width, 4 = until height hits screen height"};
47 cvar_t scr_loadingscreen_picture = {CF_CLIENT, "scr_loadingscreen_picture", "gfx/loading", "picture shown during loading"};
48 cvar_t scr_loadingscreen_count = {CF_CLIENT, "scr_loadingscreen_count","1", "number of loading screen files to use randomly (named loading.tga, loading2.tga, loading3.tga, ...)"};
49 cvar_t scr_loadingscreen_firstforstartup = {CF_CLIENT, "scr_loadingscreen_firstforstartup","0", "remove loading.tga from random scr_loadingscreen_count selection and only display it on client startup, 0 = normal, 1 = firstforstartup"};
50 cvar_t scr_loadingscreen_barcolor = {CF_CLIENT, "scr_loadingscreen_barcolor", "0 0 1", "rgb color of loadingscreen progress bar"};
51 cvar_t scr_loadingscreen_barheight = {CF_CLIENT, "scr_loadingscreen_barheight", "8", "the height of the loadingscreen progress bar"};
52 cvar_t scr_loadingscreen_maxfps = {CF_CLIENT, "scr_loadingscreen_maxfps", "20", "maximum FPS for loading screen so it will not update very often (this reduces loading time with lots of models)"};
53 cvar_t scr_infobar_height = {CF_CLIENT, "scr_infobar_height", "8", "the height of the infobar items"};
54 cvar_t vid_conwidthauto = {CF_CLIENT | CF_ARCHIVE, "vid_conwidthauto", "1", "automatically update vid_conwidth to match aspect ratio"};
55 cvar_t vid_conwidth = {CF_CLIENT | CF_ARCHIVE, "vid_conwidth", "640", "virtual width of 2D graphics system (note: changes may be overwritten, see vid_conwidthauto)"};
56 cvar_t vid_conheight = {CF_CLIENT | CF_ARCHIVE, "vid_conheight", "480", "virtual height of 2D graphics system"};
57 cvar_t vid_pixelheight = {CF_CLIENT | CF_ARCHIVE, "vid_pixelheight", "1", "adjusts vertical field of vision to account for non-square pixels (1280x1024 on a CRT monitor for example)"};
58 cvar_t scr_screenshot_jpeg = {CF_CLIENT | CF_ARCHIVE, "scr_screenshot_jpeg","1", "save jpeg instead of targa"};
59 cvar_t scr_screenshot_jpeg_quality = {CF_CLIENT | CF_ARCHIVE, "scr_screenshot_jpeg_quality","0.9", "image quality of saved jpeg"};
60 cvar_t scr_screenshot_png = {CF_CLIENT | CF_ARCHIVE, "scr_screenshot_png","0", "save png instead of targa"};
61 cvar_t scr_screenshot_gammaboost = {CF_CLIENT | CF_ARCHIVE, "scr_screenshot_gammaboost","1", "gamma correction on saved screenshots and videos, 1.0 saves unmodified images"};
62 cvar_t scr_screenshot_alpha = {CF_CLIENT, "scr_screenshot_alpha","0", "try to write an alpha channel to screenshots (debugging feature)"};
63 cvar_t scr_screenshot_timestamp = {CF_CLIENT | CF_ARCHIVE, "scr_screenshot_timestamp", "1", "use a timestamp based number of the type YYYYMMDDHHMMSSsss instead of sequential numbering"};
64 // scr_screenshot_name is defined in fs.c
65 #ifdef CONFIG_VIDEO_CAPTURE
66 cvar_t cl_capturevideo = {CF_CLIENT, "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)"};
67 cvar_t cl_capturevideo_demo_stop = {CF_CLIENT | CF_ARCHIVE, "cl_capturevideo_demo_stop", "1", "automatically stops video recording when demo ends"};
68 cvar_t cl_capturevideo_printfps = {CF_CLIENT | CF_ARCHIVE, "cl_capturevideo_printfps", "1", "prints the frames per second captured in capturevideo (is only written to the log file, not to the console, as that would be visible on the video)"};
69 cvar_t cl_capturevideo_width = {CF_CLIENT | CF_ARCHIVE, "cl_capturevideo_width", "0", "scales all frames to this resolution before saving the video"};
70 cvar_t cl_capturevideo_height = {CF_CLIENT | CF_ARCHIVE, "cl_capturevideo_height", "0", "scales all frames to this resolution before saving the video"};
71 cvar_t cl_capturevideo_realtime = {CF_CLIENT, "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"};
72 cvar_t cl_capturevideo_fps = {CF_CLIENT | CF_ARCHIVE, "cl_capturevideo_fps", "30", "how many frames per second to save (29.97 for NTSC, 30 for typical PC video, 15 can be useful)"};
73 cvar_t cl_capturevideo_nameformat = {CF_CLIENT | CF_ARCHIVE, "cl_capturevideo_nameformat", "dpvideo", "prefix for saved videos (the date is encoded using strftime escapes)"};
74 cvar_t cl_capturevideo_number = {CF_CLIENT | CF_ARCHIVE, "cl_capturevideo_number", "1", "number to append to video filename, incremented each time a capture begins"};
75 cvar_t cl_capturevideo_ogg = {CF_CLIENT | CF_ARCHIVE, "cl_capturevideo_ogg", "1", "save captured video data as Ogg/Vorbis/Theora streams"};
76 cvar_t cl_capturevideo_framestep = {CF_CLIENT | CF_ARCHIVE, "cl_capturevideo_framestep", "1", "when set to n >= 1, render n frames to capture one (useful for motion blur like effects)"};
78 cvar_t r_letterbox = {CF_CLIENT, "r_letterbox", "0", "reduces vertical height of view to simulate a letterboxed movie effect (can be used by mods for cutscenes)"};
79 cvar_t r_stereo_separation = {CF_CLIENT, "r_stereo_separation", "4", "separation distance of eyes in the world (negative values are only useful for cross-eyed viewing)"};
80 cvar_t r_stereo_sidebyside = {CF_CLIENT, "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)"};
81 cvar_t r_stereo_horizontal = {CF_CLIENT, "r_stereo_horizontal", "0", "aspect skewed side by side view for special decoder/display hardware"};
82 cvar_t r_stereo_vertical = {CF_CLIENT, "r_stereo_vertical", "0", "aspect skewed top and bottom view for special decoder/display hardware"};
83 cvar_t r_stereo_redblue = {CF_CLIENT, "r_stereo_redblue", "0", "red/blue anaglyph stereo glasses (note: most of these glasses are actually red/cyan, try that one too)"};
84 cvar_t r_stereo_redcyan = {CF_CLIENT, "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"};
85 cvar_t r_stereo_redgreen = {CF_CLIENT, "r_stereo_redgreen", "0", "red/green anaglyph stereo glasses (for those who don't mind yellow)"};
86 cvar_t r_stereo_angle = {CF_CLIENT, "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)"};
87 cvar_t scr_stipple = {CF_CLIENT, "scr_stipple", "0", "interlacing-like stippling of the display"};
88 cvar_t scr_refresh = {CF_CLIENT, "scr_refresh", "1", "allows you to completely shut off rendering for benchmarking purposes"};
89 cvar_t scr_screenshot_name_in_mapdir = {CF_CLIENT | CF_ARCHIVE, "scr_screenshot_name_in_mapdir", "0", "if set to 1, screenshots are placed in a subdirectory named like the map they are from"};
90 cvar_t net_graph = {CF_CLIENT | CF_ARCHIVE, "net_graph", "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)"};
91 cvar_t cl_demo_mousegrab = {CF_CLIENT, "cl_demo_mousegrab", "0", "Allows reading the mouse input while playing demos. Useful for camera mods developed in csqc. (0: never, 1: always)"};
92 cvar_t timedemo_screenshotframelist = {CF_CLIENT, "timedemo_screenshotframelist", "", "when performing a timedemo, take screenshots of each frame in this space-separated list - example: 1 201 401"};
93 cvar_t vid_touchscreen_outlinealpha = {CF_CLIENT, "vid_touchscreen_outlinealpha", "0", "opacity of touchscreen area outlines"};
94 cvar_t vid_touchscreen_overlayalpha = {CF_CLIENT, "vid_touchscreen_overlayalpha", "0.25", "opacity of touchscreen area icons"};
96 extern cvar_t sbar_info_pos;
97 extern cvar_t r_fog_clear;
99 int jpeg_supported = false;
101 qbool scr_initialized; // ready to draw
103 qbool scr_loading = false; // we are in a loading screen
105 unsigned int scr_con_current;
106 static unsigned int scr_con_margin_bottom;
108 extern int con_vislines;
110 extern int cl_punchangle_applied;
112 static void SCR_ScreenShot_f(cmd_state_t *cmd);
113 static void R_Envmap_f(cmd_state_t *cmd);
116 void R_ClearScreen(qbool fogcolor);
119 ===============================================================================
123 ===============================================================================
126 char scr_centerstring[MAX_INPUTLINE];
127 float scr_centertime_start; // for slow victory printing
128 float scr_centertime_off;
129 int scr_center_lines;
131 int scr_erase_center;
132 char scr_infobarstring[MAX_INPUTLINE];
133 float scr_infobartime_off;
139 Called for important messages that should stay in the center of the screen
143 void SCR_CenterPrint(const char *str)
145 dp_strlcpy (scr_centerstring, str, sizeof (scr_centerstring));
146 scr_centertime_off = scr_centertime.value;
147 scr_centertime_start = cl.time;
149 // count the number of lines for centering
150 scr_center_lines = 1;
163 Print something to the center of the screen using SCR_Centerprint
166 static void SCR_Centerprint_f (cmd_state_t *cmd)
168 char msg[MAX_INPUTLINE];
169 unsigned int i, c, p;
173 dp_strlcpy(msg, Cmd_Argv(cmd,1), sizeof(msg));
174 for(i = 2; i < c; ++i)
176 dp_strlcat(msg, " ", sizeof(msg));
177 dp_strlcat(msg, Cmd_Argv(cmd, i), sizeof(msg));
179 c = (unsigned int)strlen(msg);
180 for(p = 0, i = 0; i < c; ++i)
186 else if(msg[i+1] == '\\')
198 SCR_CenterPrint(msg);
202 static void SCR_DrawCenterString (void)
209 if(cl.intermission == 2) // in finale,
210 if(sb_showscores) // make TAB hide the finale message (sb_showscores overrides finale in sbar.c)
213 if(scr_centertime.value <= 0 && !cl.intermission)
216 // the finale prints the characters one at a time, except if printspeed is an absurdly high value
217 if (cl.intermission && scr_printspeed.value > 0 && scr_printspeed.value < 1000000)
218 remaining = (int)(scr_printspeed.value * (cl.time - scr_centertime_start));
222 scr_erase_center = 0;
223 start = scr_centerstring;
228 if (scr_center_lines <= 4)
229 y = (int)(vid_conheight.integer*0.35);
236 // scan the number of characters on the line, not counting color codes
237 char *newline = strchr(start, '\n');
238 int l = newline ? (newline - start) : (int)strlen(start);
239 float width = DrawQ_TextWidth(start, l, 8, 8, false, FONT_CENTERPRINT);
241 x = (int) (vid_conwidth.integer - width)/2;
246 DrawQ_String(x, y, start, l, 8, 8, 1, 1, 1, 1, 0, &color, false, FONT_CENTERPRINT);
255 start = newline + 1; // skip the \n
259 static void SCR_CheckDrawCenterString (void)
261 if (scr_center_lines > scr_erase_lines)
262 scr_erase_lines = scr_center_lines;
264 if (cl.time > cl.oldtime)
265 scr_centertime_off -= cl.time - cl.oldtime;
267 // don't draw if this is a normal stats-screen intermission,
268 // only if it is not an intermission, or a finale intermission
269 if (cl.intermission == 1)
271 if (scr_centertime_off <= 0 && !cl.intermission)
273 if (key_dest != key_game)
276 SCR_DrawCenterString ();
279 static void SCR_DrawNetGraph_DrawGraph (int graphx, int graphy, int graphwidth, int graphheight, float graphscale, int graphlimit, const char *label, float textsize, int packetcounter, netgraphitem_t *netgraph)
281 netgraphitem_t *graph;
284 char bytesstring[128];
285 float g[NETGRAPH_PACKETS][7];
288 DrawQ_Fill(graphx, graphy, graphwidth, graphheight + textsize * 2, 0, 0, 0, 0.5, 0);
289 // draw the bar graph itself
290 memset(g, 0, sizeof(g));
291 for (j = 0;j < NETGRAPH_PACKETS;j++)
293 graph = netgraph + j;
294 g[j][0] = 1.0f - 0.25f * (host.realtime - graph->time);
301 if (graph->unreliablebytes == NETGRAPH_LOSTPACKET)
303 else if (graph->unreliablebytes == NETGRAPH_CHOKEDPACKET)
307 if(netgraph[j].time >= netgraph[(j+NETGRAPH_PACKETS-1)%NETGRAPH_PACKETS].time)
308 if(graph->unreliablebytes + graph->reliablebytes + graph->ackbytes >= graphlimit * (netgraph[j].time - netgraph[(j+NETGRAPH_PACKETS-1)%NETGRAPH_PACKETS].time))
310 g[j][3] = 1.0f - graph->unreliablebytes * graphscale;
311 g[j][4] = g[j][3] - graph->reliablebytes * graphscale;
312 g[j][5] = g[j][4] - graph->ackbytes * graphscale;
313 // count bytes in the last second
314 if (host.realtime - graph->time < 1.0f)
315 totalbytes += graph->unreliablebytes + graph->reliablebytes + graph->ackbytes;
317 if(graph->cleartime >= 0)
318 g[j][6] = 0.5f + 0.5f * (2.0 / M_PI) * atan((M_PI / 2.0) * (graph->cleartime - graph->time));
319 g[j][1] = bound(0.0f, g[j][1], 1.0f);
320 g[j][2] = bound(0.0f, g[j][2], 1.0f);
321 g[j][3] = bound(0.0f, g[j][3], 1.0f);
322 g[j][4] = bound(0.0f, g[j][4], 1.0f);
323 g[j][5] = bound(0.0f, g[j][5], 1.0f);
324 g[j][6] = bound(0.0f, g[j][6], 1.0f);
326 // render the lines for the graph
327 for (j = 0;j < NETGRAPH_PACKETS;j++)
330 b = g[(j+1)%NETGRAPH_PACKETS];
331 if (a[0] < 0.0f || b[0] > 1.0f || b[0] < a[0])
333 DrawQ_Line(1, graphx + graphwidth * a[0], graphy + graphheight * a[2], graphx + graphwidth * b[0], graphy + graphheight * b[2], 1.0f, 1.0f, 1.0f, 1.0f, 0);
334 DrawQ_Line(1, graphx + graphwidth * a[0], graphy + graphheight * a[1], graphx + graphwidth * b[0], graphy + graphheight * b[1], 1.0f, 0.0f, 0.0f, 1.0f, 0);
335 DrawQ_Line(1, graphx + graphwidth * a[0], graphy + graphheight * a[5], graphx + graphwidth * b[0], graphy + graphheight * b[5], 0.0f, 1.0f, 0.0f, 1.0f, 0);
336 DrawQ_Line(1, graphx + graphwidth * a[0], graphy + graphheight * a[4], graphx + graphwidth * b[0], graphy + graphheight * b[4], 1.0f, 1.0f, 1.0f, 1.0f, 0);
337 DrawQ_Line(1, graphx + graphwidth * a[0], graphy + graphheight * a[3], graphx + graphwidth * b[0], graphy + graphheight * b[3], 1.0f, 0.5f, 0.0f, 1.0f, 0);
338 DrawQ_Line(1, graphx + graphwidth * a[0], graphy + graphheight * a[6], graphx + graphwidth * b[0], graphy + graphheight * b[6], 0.0f, 0.0f, 1.0f, 1.0f, 0);
341 y = graphy + graphheight;
342 dpsnprintf(bytesstring, sizeof(bytesstring), "%i", totalbytes);
343 DrawQ_String(x, y, label , 0, textsize, textsize, 1.0f, 1.0f, 1.0f, 1.0f, 0, NULL, false, FONT_DEFAULT);y += textsize;
344 DrawQ_String(x, y, bytesstring, 0, textsize, textsize, 1.0f, 1.0f, 1.0f, 1.0f, 0, NULL, false, FONT_DEFAULT);y += textsize;
352 static void SCR_DrawNetGraph (void)
354 int i, separator1, separator2, graphwidth, graphheight, netgraph_x, netgraph_y, textsize, index, netgraphsperrow, graphlimit;
359 if (cls.state != ca_connected)
363 if (!net_graph.integer)
371 graphscale = 1.0f / 1500.0f;
372 graphlimit = cl_rate.integer;
374 netgraphsperrow = (vid_conwidth.integer + separator2) / (graphwidth * 2 + separator1 + separator2);
375 netgraphsperrow = max(netgraphsperrow, 1);
378 netgraph_x = (vid_conwidth.integer + separator2) - (1 + (index % netgraphsperrow)) * (graphwidth * 2 + separator1 + separator2);
379 netgraph_y = (vid_conheight.integer - 48 - sbar_info_pos.integer + separator2) - (1 + (index / netgraphsperrow)) * (graphheight + textsize + separator2);
381 SCR_DrawNetGraph_DrawGraph(netgraph_x , netgraph_y, graphwidth, graphheight, graphscale, graphlimit, "incoming", textsize, c->incoming_packetcounter, c->incoming_netgraph);
382 SCR_DrawNetGraph_DrawGraph(netgraph_x + graphwidth + separator1, netgraph_y, graphwidth, graphheight, graphscale, graphlimit, "outgoing", textsize, c->outgoing_packetcounter, c->outgoing_netgraph);
385 if (sv.active && net_graph.integer >= 2)
387 for (i = 0;i < svs.maxclients;i++)
389 c = svs.clients[i].netconnection;
392 netgraph_x = (vid_conwidth.integer + separator2) - (1 + (index % netgraphsperrow)) * (graphwidth * 2 + separator1 + separator2);
393 netgraph_y = (vid_conheight.integer - 48 + separator2) - (1 + (index / netgraphsperrow)) * (graphheight + textsize + separator2);
394 SCR_DrawNetGraph_DrawGraph(netgraph_x , netgraph_y, graphwidth, graphheight, graphscale, graphlimit, va(vabuf, sizeof(vabuf), "%s", svs.clients[i].name), textsize, c->outgoing_packetcounter, c->outgoing_netgraph);
395 SCR_DrawNetGraph_DrawGraph(netgraph_x + graphwidth + separator1, netgraph_y, graphwidth, graphheight, graphscale, graphlimit, "" , textsize, c->incoming_packetcounter, c->incoming_netgraph);
406 static void SCR_DrawTurtle (void)
410 if (cls.state != ca_connected)
413 if (!scr_showturtle.integer)
416 if (cl.realframetime < 0.1)
426 DrawQ_Pic (0, 0, Draw_CachePic ("gfx/turtle"), 0, 0, 1, 1, 1, 1, 0);
434 static void SCR_DrawNet (void)
436 if (cls.state != ca_connected)
438 if (host.realtime - cl.last_received_message < 0.3)
440 if (cls.demoplayback)
443 DrawQ_Pic (64, 0, Draw_CachePic ("gfx/net"), 0, 0, 1, 1, 1, 1, 0);
451 static void SCR_DrawPause (void)
455 if (cls.state != ca_connected)
458 if (!scr_showpause.integer) // turn off for screenshots
464 pic = Draw_CachePic ("gfx/pause");
465 DrawQ_Pic ((vid_conwidth.integer - Draw_GetPicWidth(pic))/2, (vid_conheight.integer - Draw_GetPicHeight(pic))/2, pic, 0, 0, 1, 1, 1, 1, 0);
473 static void SCR_DrawBrand (void)
478 if (!scr_showbrand.value)
481 pic = Draw_CachePic ("gfx/brand");
483 switch ((int)scr_showbrand.value)
485 case 1: // bottom left
487 y = vid_conheight.integer - Draw_GetPicHeight(pic);
489 case 2: // bottom centre
490 x = (vid_conwidth.integer - Draw_GetPicWidth(pic)) / 2;
491 y = vid_conheight.integer - Draw_GetPicHeight(pic);
493 case 3: // bottom right
494 x = vid_conwidth.integer - Draw_GetPicWidth(pic);
495 y = vid_conheight.integer - Draw_GetPicHeight(pic);
497 case 4: // centre right
498 x = vid_conwidth.integer - Draw_GetPicWidth(pic);
499 y = (vid_conheight.integer - Draw_GetPicHeight(pic)) / 2;
502 x = vid_conwidth.integer - Draw_GetPicWidth(pic);
505 case 6: // top centre
506 x = (vid_conwidth.integer - Draw_GetPicWidth(pic)) / 2;
513 case 8: // centre left
515 y = (vid_conheight.integer - Draw_GetPicHeight(pic)) / 2;
521 DrawQ_Pic (x, y, pic, 0, 0, 1, 1, 1, 1, 0);
529 static int SCR_DrawQWDownload(int offset)
531 // sync with SCR_InfobarHeight
534 float size = scr_infobar_height.value;
537 if (!cls.qw_downloadname[0])
539 cls.qw_downloadspeedrate = 0;
540 cls.qw_downloadspeedtime = host.realtime;
541 cls.qw_downloadspeedcount = 0;
544 if (host.realtime >= cls.qw_downloadspeedtime + 1)
546 cls.qw_downloadspeedrate = cls.qw_downloadspeedcount;
547 cls.qw_downloadspeedtime = host.realtime;
548 cls.qw_downloadspeedcount = 0;
550 if (cls.protocol == PROTOCOL_QUAKEWORLD)
551 dpsnprintf(temp, sizeof(temp), "Downloading %s %3i%% (%i) at %i bytes/s", cls.qw_downloadname, cls.qw_downloadpercent, cls.qw_downloadmemorycursize, cls.qw_downloadspeedrate);
553 dpsnprintf(temp, sizeof(temp), "Downloading %s %3i%% (%i/%i) at %i bytes/s", cls.qw_downloadname, cls.qw_downloadpercent, cls.qw_downloadmemorycursize, cls.qw_downloadmemorymaxsize, cls.qw_downloadspeedrate);
554 len = (int)strlen(temp);
555 x = (vid_conwidth.integer - DrawQ_TextWidth(temp, len, size, size, true, FONT_INFOBAR)) / 2;
556 y = vid_conheight.integer - size - offset;
557 DrawQ_Fill(0, y, vid_conwidth.integer, size, 0, 0, 0, cls.signon == SIGNONS ? 0.5 : 1, 0);
558 DrawQ_String(x, y, temp, len, size, size, 1, 1, 1, 1, 0, NULL, true, FONT_INFOBAR);
563 SCR_DrawInfobarString
566 static int SCR_DrawInfobarString(int offset)
570 float size = scr_infobar_height.value;
572 len = (int)strlen(scr_infobarstring);
573 x = (vid_conwidth.integer - DrawQ_TextWidth(scr_infobarstring, len, size, size, false, FONT_INFOBAR)) / 2;
574 y = vid_conheight.integer - size - offset;
575 DrawQ_Fill(0, y, vid_conwidth.integer, size, 0, 0, 0, cls.signon == SIGNONS ? 0.5 : 1, 0);
576 DrawQ_String(x, y, scr_infobarstring, len, size, size, 1, 1, 1, 1, 0, NULL, false, FONT_INFOBAR);
585 static int SCR_DrawCurlDownload(int offset)
587 // sync with SCR_InfobarHeight
592 float size = scr_infobar_height.value;
593 Curl_downloadinfo_t *downinfo;
595 char addinfobuf[128];
598 downinfo = Curl_GetDownloadInfo(&nDownloads, &addinfo, addinfobuf, sizeof(addinfobuf));
602 y = vid_conheight.integer - size * nDownloads - offset;
606 len = (int)strlen(addinfo);
607 x = (vid_conwidth.integer - DrawQ_TextWidth(addinfo, len, size, size, true, FONT_INFOBAR)) / 2;
608 DrawQ_Fill(0, y - size, vid_conwidth.integer, size, 1, 1, 1, cls.signon == SIGNONS ? 0.8 : 1, 0);
609 DrawQ_String(x, y - size, addinfo, len, size, size, 0, 0, 0, 1, 0, NULL, true, FONT_INFOBAR);
612 for(i = 0; i != nDownloads; ++i)
614 if(downinfo[i].queued)
615 dpsnprintf(temp, sizeof(temp), "Still in queue: %s", downinfo[i].filename);
616 else if(downinfo[i].progress <= 0)
617 dpsnprintf(temp, sizeof(temp), "Downloading %s ... ???.?%% @ %.1f KiB/s", downinfo[i].filename, downinfo[i].speed / 1024.0);
619 dpsnprintf(temp, sizeof(temp), "Downloading %s ... %5.1f%% @ %.1f KiB/s", downinfo[i].filename, 100.0 * downinfo[i].progress, downinfo[i].speed / 1024.0);
620 len = (int)strlen(temp);
621 x = (vid_conwidth.integer - DrawQ_TextWidth(temp, len, size, size, true, FONT_INFOBAR)) / 2;
622 DrawQ_Fill(0, y + i * size, vid_conwidth.integer, size, 0, 0, 0, cls.signon == SIGNONS ? 0.5 : 1, 0);
623 DrawQ_String(x, y + i * size, temp, len, size, size, 1, 1, 1, 1, 0, NULL, true, FONT_INFOBAR);
628 return size * (nDownloads + (addinfo ? 1 : 0));
636 static void SCR_DrawInfobar(void)
638 unsigned int offset = 0;
639 offset += SCR_DrawQWDownload(offset);
640 offset += SCR_DrawCurlDownload(offset);
641 if(scr_infobartime_off > 0)
642 offset += SCR_DrawInfobarString(offset);
643 if(!offset && scr_loading)
644 offset = scr_loadingscreen_barheight.integer;
645 if(offset != scr_con_margin_bottom)
646 Con_DPrintf("broken console margin calculation: %d != %d\n", offset, scr_con_margin_bottom);
649 static int SCR_InfobarHeight(void)
652 Curl_downloadinfo_t *downinfo;
655 char addinfobuf[128];
657 if (cl.time > cl.oldtime)
658 scr_infobartime_off -= cl.time - cl.oldtime;
659 if(scr_infobartime_off > 0)
661 if(cls.qw_downloadname[0])
664 downinfo = Curl_GetDownloadInfo(&nDownloads, &addinfo, addinfobuf, sizeof(addinfobuf));
667 offset += (nDownloads + (addinfo ? 1 : 0));
670 offset *= scr_infobar_height.value;
680 static void SCR_InfoBar_f(cmd_state_t *cmd)
682 if(Cmd_Argc(cmd) == 3)
684 scr_infobartime_off = atof(Cmd_Argv(cmd, 1));
685 dp_strlcpy(scr_infobarstring, Cmd_Argv(cmd, 2), sizeof(scr_infobarstring));
689 Con_Printf("usage:\ninfobar expiretime \"string\"\n");
692 //=============================================================================
696 SCR_SetUpToDrawConsole
699 static void SCR_SetUpToDrawConsole (void)
702 static int framecounter = 0;
708 if (scr_menuforcewhiledisconnected.integer && key_dest == key_game && cls.state == ca_disconnected)
710 if (framecounter >= 2)
719 if (scr_conforcewhiledisconnected.integer >= 2 && key_dest == key_game && cls.signon != SIGNONS)
720 key_consoleactive |= KEY_CONSOLEACTIVE_FORCED;
721 else if (scr_conforcewhiledisconnected.integer >= 1 && key_dest == key_game && cls.signon != SIGNONS && !sv.active)
722 key_consoleactive |= KEY_CONSOLEACTIVE_FORCED;
724 key_consoleactive &= ~KEY_CONSOLEACTIVE_FORCED;
726 // decide on the height of the console
727 if (key_consoleactive & KEY_CONSOLEACTIVE_USER)
728 scr_con_current = vid_conheight.integer * scr_conheight.value;
730 scr_con_current = 0; // none visible
738 void SCR_DrawConsole (void)
740 // infobar and loading progress are not drawn simultaneously
741 scr_con_margin_bottom = SCR_InfobarHeight() ?: scr_loading * scr_loadingscreen_barheight.integer;
742 if (key_consoleactive & KEY_CONSOLEACTIVE_FORCED)
745 Con_DrawConsole (vid_conheight.integer - scr_con_margin_bottom);
747 else if (scr_con_current)
748 Con_DrawConsole (min(scr_con_current, vid_conheight.integer - scr_con_margin_bottom));
753 //=============================================================================
762 static void SCR_SizeUp_f(cmd_state_t *cmd)
764 Cvar_SetValueQuick(&scr_viewsize, scr_viewsize.value + 10);
775 static void SCR_SizeDown_f(cmd_state_t *cmd)
777 Cvar_SetValueQuick(&scr_viewsize, scr_viewsize.value - 10);
780 #ifdef CONFIG_VIDEO_CAPTURE
781 void SCR_CaptureVideo_EndVideo(void);
783 void CL_Screen_Shutdown(void)
785 #ifdef CONFIG_VIDEO_CAPTURE
786 SCR_CaptureVideo_EndVideo();
790 void CL_Screen_Init(void)
793 Cvar_RegisterVariable (&scr_fov);
794 Cvar_RegisterVariable (&scr_viewsize);
795 Cvar_RegisterVariable (&scr_conalpha);
796 Cvar_RegisterVariable (&scr_conalphafactor);
797 Cvar_RegisterVariable (&scr_conalpha2factor);
798 Cvar_RegisterVariable (&scr_conalpha3factor);
799 Cvar_RegisterVariable (&scr_conscroll_x);
800 Cvar_RegisterVariable (&scr_conscroll_y);
801 Cvar_RegisterVariable (&scr_conscroll2_x);
802 Cvar_RegisterVariable (&scr_conscroll2_y);
803 Cvar_RegisterVariable (&scr_conscroll3_x);
804 Cvar_RegisterVariable (&scr_conscroll3_y);
805 Cvar_RegisterVariable (&scr_conbrightness);
806 Cvar_RegisterVariable (&scr_conforcewhiledisconnected);
807 Cvar_RegisterVariable (&scr_conheight);
809 Cvar_RegisterVariable (&scr_menuforcewhiledisconnected);
811 Cvar_RegisterVariable (&scr_loadingscreen_background);
812 Cvar_RegisterVariable (&scr_loadingscreen_scale);
813 Cvar_RegisterVariable (&scr_loadingscreen_scale_base);
814 Cvar_RegisterVariable (&scr_loadingscreen_scale_limit);
815 Cvar_RegisterVariable (&scr_loadingscreen_picture);
816 Cvar_RegisterVariable (&scr_loadingscreen_count);
817 Cvar_RegisterVariable (&scr_loadingscreen_firstforstartup);
818 Cvar_RegisterVariable (&scr_loadingscreen_barcolor);
819 Cvar_RegisterVariable (&scr_loadingscreen_barheight);
820 Cvar_RegisterVariable (&scr_loadingscreen_maxfps);
821 Cvar_RegisterVariable (&scr_infobar_height);
822 Cvar_RegisterVariable (&scr_showram);
823 Cvar_RegisterVariable (&scr_showturtle);
824 Cvar_RegisterVariable (&scr_showpause);
825 Cvar_RegisterVariable (&scr_showbrand);
826 Cvar_RegisterVariable (&scr_centertime);
827 Cvar_RegisterVariable (&scr_printspeed);
828 Cvar_RegisterVariable (&vid_conwidth);
829 Cvar_RegisterVariable (&vid_conheight);
830 Cvar_RegisterVariable (&vid_pixelheight);
831 Cvar_RegisterVariable (&vid_conwidthauto);
832 Cvar_RegisterVariable (&scr_screenshot_jpeg);
833 Cvar_RegisterVariable (&scr_screenshot_jpeg_quality);
834 Cvar_RegisterVariable (&scr_screenshot_png);
835 Cvar_RegisterVariable (&scr_screenshot_gammaboost);
836 Cvar_RegisterVariable (&scr_screenshot_name_in_mapdir);
837 Cvar_RegisterVariable (&scr_screenshot_alpha);
838 Cvar_RegisterVariable (&scr_screenshot_timestamp);
839 #ifdef CONFIG_VIDEO_CAPTURE
840 Cvar_RegisterVariable (&cl_capturevideo);
841 Cvar_RegisterVariable (&cl_capturevideo_demo_stop);
842 Cvar_RegisterVariable (&cl_capturevideo_printfps);
843 Cvar_RegisterVariable (&cl_capturevideo_width);
844 Cvar_RegisterVariable (&cl_capturevideo_height);
845 Cvar_RegisterVariable (&cl_capturevideo_realtime);
846 Cvar_RegisterVariable (&cl_capturevideo_fps);
847 Cvar_RegisterVariable (&cl_capturevideo_nameformat);
848 Cvar_RegisterVariable (&cl_capturevideo_number);
849 Cvar_RegisterVariable (&cl_capturevideo_ogg);
850 Cvar_RegisterVariable (&cl_capturevideo_framestep);
852 Cvar_RegisterVariable (&r_letterbox);
853 Cvar_RegisterVariable(&r_stereo_separation);
854 Cvar_RegisterVariable(&r_stereo_sidebyside);
855 Cvar_RegisterVariable(&r_stereo_horizontal);
856 Cvar_RegisterVariable(&r_stereo_vertical);
857 Cvar_RegisterVariable(&r_stereo_redblue);
858 Cvar_RegisterVariable(&r_stereo_redcyan);
859 Cvar_RegisterVariable(&r_stereo_redgreen);
860 Cvar_RegisterVariable(&r_stereo_angle);
861 Cvar_RegisterVariable(&scr_stipple);
862 Cvar_RegisterVariable(&scr_refresh);
863 Cvar_RegisterVariable(&net_graph);
864 Cvar_RegisterVirtual(&net_graph, "shownetgraph");
865 Cvar_RegisterVariable(&cl_demo_mousegrab);
866 Cvar_RegisterVariable(&timedemo_screenshotframelist);
867 Cvar_RegisterVariable(&vid_touchscreen_outlinealpha);
868 Cvar_RegisterVariable(&vid_touchscreen_overlayalpha);
869 Cvar_RegisterVariable(&r_speeds_graph);
870 for (i = 0;i < (int)(sizeof(r_speeds_graph_filter)/sizeof(r_speeds_graph_filter[0]));i++)
871 Cvar_RegisterVariable(&r_speeds_graph_filter[i]);
872 Cvar_RegisterVariable(&r_speeds_graph_length);
873 Cvar_RegisterVariable(&r_speeds_graph_seconds);
874 Cvar_RegisterVariable(&r_speeds_graph_x);
875 Cvar_RegisterVariable(&r_speeds_graph_y);
876 Cvar_RegisterVariable(&r_speeds_graph_width);
877 Cvar_RegisterVariable(&r_speeds_graph_height);
878 Cvar_RegisterVariable(&r_speeds_graph_maxtimedelta);
879 Cvar_RegisterVariable(&r_speeds_graph_maxdefault);
881 // if we want no console, turn it off here too
882 if (Sys_CheckParm ("-noconsole"))
883 Cvar_SetQuick(&scr_conforcewhiledisconnected, "0");
885 Cmd_AddCommand(CF_CLIENT, "cprint", SCR_Centerprint_f, "print something at the screen center");
886 Cmd_AddCommand(CF_CLIENT, "sizeup",SCR_SizeUp_f, "increase view size (increases viewsize cvar)");
887 Cmd_AddCommand(CF_CLIENT, "sizedown",SCR_SizeDown_f, "decrease view size (decreases viewsize cvar)");
888 Cmd_AddCommand(CF_CLIENT, "screenshot",SCR_ScreenShot_f, "takes a screenshot of the next rendered frame");
889 Cmd_AddCommand(CF_CLIENT, "envmap", R_Envmap_f, "render a cubemap (skybox) of the current scene");
890 Cmd_AddCommand(CF_CLIENT, "infobar", SCR_InfoBar_f, "display a text in the infobar (usage: infobar expiretime string)");
892 #ifdef CONFIG_VIDEO_CAPTURE
893 SCR_CaptureVideo_Ogg_Init();
896 scr_initialized = true;
904 void SCR_ScreenShot_f(cmd_state_t *cmd)
906 static int shotnumber;
907 static char old_prefix_name[MAX_QPATH];
908 char prefix_name[MAX_QPATH];
909 char filename[MAX_QPATH];
910 unsigned char *buffer1;
911 unsigned char *buffer2;
912 qbool jpeg = (scr_screenshot_jpeg.integer != 0);
913 qbool png = (scr_screenshot_png.integer != 0) && !jpeg;
916 if (Cmd_Argc(cmd) == 2)
919 dp_strlcpy(filename, Cmd_Argv(cmd, 1), sizeof(filename));
920 ext = FS_FileExtension(filename);
921 if (!strcasecmp(ext, "jpg"))
926 else if (!strcasecmp(ext, "tga"))
931 else if (!strcasecmp(ext, "png"))
938 Con_Printf("screenshot: supplied filename must end in .jpg or .tga or .png\n");
942 else if (scr_screenshot_timestamp.integer)
946 // TODO maybe make capturevideo and screenshot use similar name patterns?
947 if (scr_screenshot_name_in_mapdir.integer && cl.worldbasename[0])
948 dpsnprintf(prefix_name, sizeof(prefix_name), "%s/%s%s", cl.worldbasename, scr_screenshot_name.string, Sys_TimeString("%Y%m%d%H%M%S"));
950 dpsnprintf(prefix_name, sizeof(prefix_name), "%s%s", scr_screenshot_name.string, Sys_TimeString("%Y%m%d%H%M%S"));
952 // find a file name to save it to
953 for (shotnumber100 = 0;shotnumber100 < 100;shotnumber100++)
954 if (!FS_SysFileExists(va(vabuf, sizeof(vabuf), "%s/screenshots/%s-%02d.tga", fs_gamedir, prefix_name, shotnumber100))
955 && !FS_SysFileExists(va(vabuf, sizeof(vabuf), "%s/screenshots/%s-%02d.jpg", fs_gamedir, prefix_name, shotnumber100))
956 && !FS_SysFileExists(va(vabuf, sizeof(vabuf), "%s/screenshots/%s-%02d.png", fs_gamedir, prefix_name, shotnumber100)))
958 if (shotnumber100 >= 100)
960 Con_Print("Couldn't create the image file - already 100 shots taken this second!\n");
964 dpsnprintf(filename, sizeof(filename), "screenshots/%s-%02d.%s", prefix_name, shotnumber100, jpeg ? "jpg" : png ? "png" : "tga");
968 // TODO maybe make capturevideo and screenshot use similar name patterns?
969 if (scr_screenshot_name_in_mapdir.integer && cl.worldbasename[0])
970 dpsnprintf(prefix_name, sizeof(prefix_name), "%s/%s", cl.worldbasename, Sys_TimeString(scr_screenshot_name.string));
972 dpsnprintf(prefix_name, sizeof(prefix_name), "%s", Sys_TimeString(scr_screenshot_name.string));
974 // if prefix changed, gamedir or map changed, reset the shotnumber so
976 // FIXME: should probably do this whenever FS_Rescan or something like that occurs?
977 if (strcmp(old_prefix_name, prefix_name))
979 dpsnprintf(old_prefix_name, sizeof(old_prefix_name), "%s", prefix_name );
983 // find a file name to save it to
984 for (;shotnumber < 1000000;shotnumber++)
985 if (!FS_SysFileExists(va(vabuf, sizeof(vabuf), "%s/screenshots/%s%06d.tga", fs_gamedir, prefix_name, shotnumber))
986 && !FS_SysFileExists(va(vabuf, sizeof(vabuf), "%s/screenshots/%s%06d.jpg", fs_gamedir, prefix_name, shotnumber))
987 && !FS_SysFileExists(va(vabuf, sizeof(vabuf), "%s/screenshots/%s%06d.png", fs_gamedir, prefix_name, shotnumber)))
989 if (shotnumber >= 1000000)
991 Con_Print("Couldn't create the image file - you already have 1000000 screenshots!\n");
995 dpsnprintf(filename, sizeof(filename), "screenshots/%s%06d.%s", prefix_name, shotnumber, jpeg ? "jpg" : png ? "png" : "tga");
1000 buffer1 = (unsigned char *)Mem_Alloc(tempmempool, vid.width * vid.height * 4);
1001 buffer2 = (unsigned char *)Mem_Alloc(tempmempool, vid.width * vid.height * (scr_screenshot_alpha.integer ? 4 : 3));
1003 if (SCR_ScreenShot (filename, buffer1, buffer2, 0, 0, vid.width, vid.height, false, false, false, jpeg, png, true, scr_screenshot_alpha.integer != 0))
1004 Con_Printf("Wrote %s\n", filename);
1007 Con_Printf(CON_ERROR "Unable to write %s\n", filename);
1010 if(SCR_ScreenShot (filename, buffer1, buffer2, 0, 0, vid.width, vid.height, false, false, false, false, false, true, scr_screenshot_alpha.integer != 0))
1012 dp_strlcpy(filename + strlen(filename) - 3, "tga", 4);
1013 Con_Printf("Wrote %s\n", filename);
1022 #ifdef CONFIG_VIDEO_CAPTURE
1023 static void SCR_CaptureVideo_BeginVideo(void)
1027 int width = cl_capturevideo_width.integer, height = cl_capturevideo_height.integer;
1028 if (cls.capturevideo.active)
1030 memset(&cls.capturevideo, 0, sizeof(cls.capturevideo));
1031 // soundrate is figured out on the first SoundFrame
1033 if(width == 0 && height != 0)
1034 width = (int) (height * (double)vid.width / ((double)vid.height * vid_pixelheight.value)); // keep aspect
1035 if(width != 0 && height == 0)
1036 height = (int) (width * ((double)vid.height * vid_pixelheight.value) / (double)vid.width); // keep aspect
1038 if(width < 2 || width > vid.width) // can't scale up
1040 if(height < 2 || height > vid.height) // can't scale up
1041 height = vid.height;
1043 // ensure it's all even; if not, scale down a little
1049 cls.capturevideo.width = width;
1050 cls.capturevideo.height = height;
1051 cls.capturevideo.active = true;
1052 cls.capturevideo.framerate = bound(1, cl_capturevideo_fps.value, 1001) * bound(1, cl_capturevideo_framestep.integer, 64);
1053 cls.capturevideo.framestep = cl_capturevideo_framestep.integer;
1054 cls.capturevideo.soundrate = S_GetSoundRate();
1055 cls.capturevideo.soundchannels = S_GetSoundChannels();
1056 cls.capturevideo.startrealtime = host.realtime;
1057 cls.capturevideo.frame = cls.capturevideo.lastfpsframe = 0;
1058 cls.capturevideo.starttime = cls.capturevideo.lastfpstime = host.realtime;
1059 cls.capturevideo.soundsampleframe = 0;
1060 cls.capturevideo.realtime = cl_capturevideo_realtime.integer != 0;
1061 cls.capturevideo.screenbuffer = (unsigned char *)Mem_Alloc(tempmempool, vid.width * vid.height * 4);
1062 cls.capturevideo.outbuffer = (unsigned char *)Mem_Alloc(tempmempool, width * height * (4+4) + 18);
1063 dpsnprintf(cls.capturevideo.basename, sizeof(cls.capturevideo.basename), "video/%s%03i", Sys_TimeString(cl_capturevideo_nameformat.string), cl_capturevideo_number.integer);
1064 Cvar_SetValueQuick(&cl_capturevideo_number, cl_capturevideo_number.integer + 1);
1067 for (i = 0;i < 256;i++)
1069 unsigned char j = (unsigned char)bound(0, 255*pow(i/255.0, gamma), 255);
1070 cls.capturevideo.rgbgammatable[0][i] = j;
1071 cls.capturevideo.rgbgammatable[1][i] = j;
1072 cls.capturevideo.rgbgammatable[2][i] = j;
1076 R = Y + 1.4075 * (Cr - 128);
1077 G = Y + -0.3455 * (Cb - 128) + -0.7169 * (Cr - 128);
1078 B = Y + 1.7790 * (Cb - 128);
1079 Y = R * .299 + G * .587 + B * .114;
1080 Cb = R * -.169 + G * -.332 + B * .500 + 128.;
1081 Cr = R * .500 + G * -.419 + B * -.0813 + 128.;
1084 // identity gamma table
1085 BuildGammaTable16(1.0f, 1.0f, 1.0f, 0.0f, 1.0f, cls.capturevideo.vidramp, 256);
1086 BuildGammaTable16(1.0f, 1.0f, 1.0f, 0.0f, 1.0f, cls.capturevideo.vidramp + 256, 256);
1087 BuildGammaTable16(1.0f, 1.0f, 1.0f, 0.0f, 1.0f, cls.capturevideo.vidramp + 256*2, 256);
1088 if(scr_screenshot_gammaboost.value != 1)
1090 double igamma = 1 / scr_screenshot_gammaboost.value;
1091 for (i = 0;i < 256 * 3;i++)
1092 cls.capturevideo.vidramp[i] = (unsigned short) (0.5 + pow(cls.capturevideo.vidramp[i] * (1.0 / 65535.0), igamma) * 65535.0);
1095 for (i = 0;i < 256;i++)
1097 r = 255*cls.capturevideo.vidramp[i]/65535.0;
1098 g = 255*cls.capturevideo.vidramp[i+256]/65535.0;
1099 b = 255*cls.capturevideo.vidramp[i+512]/65535.0;
1100 // NOTE: we have to round DOWN here, or integer overflows happen. Sorry for slightly wrong looking colors sometimes...
1101 // Y weights from RGB
1102 cls.capturevideo.rgbtoyuvscaletable[0][0][i] = (short)(r * 0.299);
1103 cls.capturevideo.rgbtoyuvscaletable[0][1][i] = (short)(g * 0.587);
1104 cls.capturevideo.rgbtoyuvscaletable[0][2][i] = (short)(b * 0.114);
1105 // Cb weights from RGB
1106 cls.capturevideo.rgbtoyuvscaletable[1][0][i] = (short)(r * -0.169);
1107 cls.capturevideo.rgbtoyuvscaletable[1][1][i] = (short)(g * -0.332);
1108 cls.capturevideo.rgbtoyuvscaletable[1][2][i] = (short)(b * 0.500);
1109 // Cr weights from RGB
1110 cls.capturevideo.rgbtoyuvscaletable[2][0][i] = (short)(r * 0.500);
1111 cls.capturevideo.rgbtoyuvscaletable[2][1][i] = (short)(g * -0.419);
1112 cls.capturevideo.rgbtoyuvscaletable[2][2][i] = (short)(b * -0.0813);
1113 // range reduction of YCbCr to valid signal range
1114 cls.capturevideo.yuvnormalizetable[0][i] = 16 + i * (236-16) / 256;
1115 cls.capturevideo.yuvnormalizetable[1][i] = 16 + i * (240-16) / 256;
1116 cls.capturevideo.yuvnormalizetable[2][i] = 16 + i * (240-16) / 256;
1119 if (cl_capturevideo_ogg.integer)
1121 if(SCR_CaptureVideo_Ogg_Available())
1123 SCR_CaptureVideo_Ogg_BeginVideo();
1127 Con_Print("cl_capturevideo_ogg: libraries not available. Capturing in AVI instead.\n");
1130 SCR_CaptureVideo_Avi_BeginVideo();
1133 void SCR_CaptureVideo_EndVideo(void)
1135 if (!cls.capturevideo.active)
1137 cls.capturevideo.active = false;
1139 Con_Printf("Finishing capture of %s.%s (%d frames, %d audio frames)\n", cls.capturevideo.basename, cls.capturevideo.formatextension, cls.capturevideo.frame, cls.capturevideo.soundsampleframe);
1141 if (cls.capturevideo.videofile)
1143 cls.capturevideo.endvideo();
1146 if (cls.capturevideo.screenbuffer)
1148 Mem_Free (cls.capturevideo.screenbuffer);
1149 cls.capturevideo.screenbuffer = NULL;
1152 if (cls.capturevideo.outbuffer)
1154 Mem_Free (cls.capturevideo.outbuffer);
1155 cls.capturevideo.outbuffer = NULL;
1158 memset(&cls.capturevideo, 0, sizeof(cls.capturevideo));
1161 static void SCR_ScaleDownBGRA(unsigned char *in, int inw, int inh, unsigned char *out, int outw, int outh)
1163 // TODO optimize this function
1168 // memcpy is faster than me
1169 if(inw == outw && inh == outh)
1171 memcpy(out, in, 4 * inw * inh);
1175 // otherwise: a box filter
1176 area = (float)outw * (float)outh / (float)inw / (float)inh;
1177 for(y = 0; y < outh; ++y)
1179 float iny0 = y / (float)outh * inh; int iny0_i = (int) floor(iny0);
1180 float iny1 = (y+1) / (float)outh * inh; int iny1_i = (int) ceil(iny1);
1181 for(x = 0; x < outw; ++x)
1183 float inx0 = x / (float)outw * inw; int inx0_i = (int) floor(inx0);
1184 float inx1 = (x+1) / (float)outw * inw; int inx1_i = (int) ceil(inx1);
1185 float r = 0, g = 0, b = 0, alpha = 0;
1188 for(yy = iny0_i; yy < iny1_i; ++yy)
1190 float ya = min(yy+1, iny1) - max(iny0, yy);
1191 for(xx = inx0_i; xx < inx1_i; ++xx)
1193 float a = ya * (min(xx+1, inx1) - max(inx0, xx));
1194 r += a * in[4*(xx + inw * yy)+0];
1195 g += a * in[4*(xx + inw * yy)+1];
1196 b += a * in[4*(xx + inw * yy)+2];
1197 alpha += a * in[4*(xx + inw * yy)+3];
1201 out[4*(x + outw * y)+0] = (unsigned char) (r * area);
1202 out[4*(x + outw * y)+1] = (unsigned char) (g * area);
1203 out[4*(x + outw * y)+2] = (unsigned char) (b * area);
1204 out[4*(x + outw * y)+3] = (unsigned char) (alpha * area);
1209 static void SCR_CaptureVideo_VideoFrame(int newframestepframenum)
1212 int width = cls.capturevideo.width, height = cls.capturevideo.height;
1214 if(newframestepframenum == cls.capturevideo.framestepframe)
1218 // speed is critical here, so do saving as directly as possible
1220 GL_ReadPixelsBGRA(x, y, vid.width, vid.height, cls.capturevideo.screenbuffer);
1222 SCR_ScaleDownBGRA (cls.capturevideo.screenbuffer, vid.width, vid.height, cls.capturevideo.outbuffer, width, height);
1224 cls.capturevideo.videoframes(newframestepframenum - cls.capturevideo.framestepframe);
1225 cls.capturevideo.framestepframe = newframestepframenum;
1227 if(cl_capturevideo_printfps.integer && host.realtime > cls.capturevideo.lastfpstime + 1)
1229 double fps1 = (cls.capturevideo.frame - cls.capturevideo.lastfpsframe) / (host.realtime - cls.capturevideo.lastfpstime + 0.0000001);
1230 double fps = (cls.capturevideo.frame ) / (host.realtime - cls.capturevideo.starttime + 0.0000001);
1231 Sys_Printf("capturevideo: (%.1fs) last second %.3ffps, total %.3ffps\n", cls.capturevideo.frame / cls.capturevideo.framerate, fps1, fps);
1232 cls.capturevideo.lastfpstime = host.realtime;
1233 cls.capturevideo.lastfpsframe = cls.capturevideo.frame;
1237 void SCR_CaptureVideo_SoundFrame(const portable_sampleframe_t *paintbuffer, size_t length)
1239 cls.capturevideo.soundsampleframe += (int)length;
1240 cls.capturevideo.soundframe(paintbuffer, length);
1243 static void SCR_CaptureVideo(void)
1246 if (cl_capturevideo.integer)
1248 if (!cls.capturevideo.active)
1249 SCR_CaptureVideo_BeginVideo();
1250 if (cls.capturevideo.framerate != cl_capturevideo_fps.value * cl_capturevideo_framestep.integer)
1252 Con_Printf("You can not change the video framerate while recording a video.\n");
1253 Cvar_SetValueQuick(&cl_capturevideo_fps, cls.capturevideo.framerate / (double) cl_capturevideo_framestep.integer);
1255 // for AVI saving we have to make sure that sound is saved before video
1256 if (cls.capturevideo.soundrate && !cls.capturevideo.soundsampleframe)
1258 if (cls.capturevideo.realtime)
1260 // preserve sound sync by duplicating frames when running slow
1261 newframenum = (int)((host.realtime - cls.capturevideo.startrealtime) * cls.capturevideo.framerate);
1264 newframenum = cls.capturevideo.frame + 1;
1265 // if falling behind more than one second, stop
1266 if (newframenum - cls.capturevideo.frame > 60 * (int)ceil(cls.capturevideo.framerate))
1268 Cvar_SetValueQuick(&cl_capturevideo, 0);
1269 Con_Printf("video saving failed on frame %i, your machine is too slow for this capture speed.\n", cls.capturevideo.frame);
1270 SCR_CaptureVideo_EndVideo();
1274 SCR_CaptureVideo_VideoFrame(newframenum / cls.capturevideo.framestep);
1275 cls.capturevideo.frame = newframenum;
1276 if (cls.capturevideo.error)
1278 Cvar_SetValueQuick(&cl_capturevideo, 0);
1279 Con_Printf("video saving failed on frame %i, out of disk space? stopping video capture.\n", cls.capturevideo.frame);
1280 SCR_CaptureVideo_EndVideo();
1283 else if (cls.capturevideo.active)
1284 SCR_CaptureVideo_EndVideo();
1292 Grab six views for environment mapping tests
1299 qbool flipx, flipy, flipdiagonaly;
1303 {{ 0, 0, 0}, "rt", false, false, false},
1304 {{ 0, 270, 0}, "ft", false, false, false},
1305 {{ 0, 180, 0}, "lf", false, false, false},
1306 {{ 0, 90, 0}, "bk", false, false, false},
1307 {{-90, 180, 0}, "up", true, true, false},
1308 {{ 90, 180, 0}, "dn", true, true, false},
1310 {{ 0, 0, 0}, "px", true, true, true},
1311 {{ 0, 90, 0}, "py", false, true, false},
1312 {{ 0, 180, 0}, "nx", false, false, true},
1313 {{ 0, 270, 0}, "ny", true, false, false},
1314 {{-90, 180, 0}, "pz", false, false, true},
1315 {{ 90, 180, 0}, "nz", false, false, true}
1318 static void R_Envmap_f(cmd_state_t *cmd)
1321 char filename[MAX_QPATH], basename[MAX_QPATH];
1322 unsigned char *buffer1;
1323 unsigned char *buffer2;
1324 r_rendertarget_t *rt;
1326 if (Cmd_Argc(cmd) != 3)
1328 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");
1332 if(cls.state != ca_connected) {
1333 Con_Printf("envmap: No map loaded\n");
1337 dp_strlcpy (basename, Cmd_Argv(cmd, 1), sizeof (basename));
1338 size = atoi(Cmd_Argv(cmd, 2));
1339 if (size != 128 && size != 256 && size != 512 && size != 1024)
1341 Con_Print("envmap: size must be one of 128, 256, 512, or 1024\n");
1344 if (size > vid.width || size > vid.height)
1346 Con_Print("envmap: your resolution is not big enough to render that size\n");
1350 r_refdef.envmap = true;
1352 R_UpdateVariables();
1354 r_refdef.view.x = 0;
1355 r_refdef.view.y = 0;
1356 r_refdef.view.z = 0;
1357 r_refdef.view.width = size;
1358 r_refdef.view.height = size;
1359 r_refdef.view.depth = 1;
1360 r_refdef.view.useperspective = true;
1361 r_refdef.view.isoverlay = false;
1362 r_refdef.view.ismain = true;
1364 r_refdef.view.frustum_x = 1; // tan(45 * M_PI / 180.0);
1365 r_refdef.view.frustum_y = 1; // tan(45 * M_PI / 180.0);
1366 r_refdef.view.ortho_x = 90; // abused as angle by VM_CL_R_SetView
1367 r_refdef.view.ortho_y = 90; // abused as angle by VM_CL_R_SetView
1369 buffer1 = (unsigned char *)Mem_Alloc(tempmempool, size * size * 4);
1370 buffer2 = (unsigned char *)Mem_Alloc(tempmempool, size * size * 3);
1372 // TODO: use TEXTYPE_COLORBUFFER16F and output to .exr files as well?
1373 rt = R_RenderTarget_Get(size, size, TEXTYPE_DEPTHBUFFER24STENCIL8, true, TEXTYPE_COLORBUFFER, TEXTYPE_UNUSED, TEXTYPE_UNUSED, TEXTYPE_UNUSED);
1374 CL_UpdateEntityShading();
1375 for (j = 0;j < 12;j++)
1377 dpsnprintf(filename, sizeof(filename), "env/%s%s.tga", basename, envmapinfo[j].name);
1378 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);
1379 r_refdef.view.quality = 1;
1380 r_refdef.view.clear = true;
1382 R_RenderView(rt->fbo, rt->depthtexture, rt->colortexture[0], 0, 0, size, size);
1384 SCR_ScreenShot(filename, buffer1, buffer2, 0, vid.height - (r_refdef.view.y + r_refdef.view.height), size, size, envmapinfo[j].flipx, envmapinfo[j].flipy, envmapinfo[j].flipdiagonaly, false, false, false, false);
1390 r_refdef.envmap = false;
1393 //=============================================================================
1395 void SHOWLMP_decodehide(void)
1399 lmplabel = MSG_ReadString(&cl_message, cl_readstring, sizeof(cl_readstring));
1400 for (i = 0;i < cl.num_showlmps;i++)
1401 if (cl.showlmps[i].isactive && strcmp(cl.showlmps[i].label, lmplabel) == 0)
1403 cl.showlmps[i].isactive = false;
1408 void SHOWLMP_decodeshow(void)
1411 char lmplabel[256], picname[256];
1413 dp_strlcpy (lmplabel,MSG_ReadString(&cl_message, cl_readstring, sizeof(cl_readstring)), sizeof (lmplabel));
1414 dp_strlcpy (picname, MSG_ReadString(&cl_message, cl_readstring, sizeof(cl_readstring)), sizeof (picname));
1415 if (gamemode == GAME_NEHAHRA) // LadyHavoc: nasty old legacy junk
1417 x = MSG_ReadByte(&cl_message);
1418 y = MSG_ReadByte(&cl_message);
1422 x = MSG_ReadShort(&cl_message);
1423 y = MSG_ReadShort(&cl_message);
1425 if (!cl.showlmps || cl.num_showlmps >= cl.max_showlmps)
1427 showlmp_t *oldshowlmps = cl.showlmps;
1428 cl.max_showlmps += 16;
1429 cl.showlmps = (showlmp_t *) Mem_Alloc(cls.levelmempool, cl.max_showlmps * sizeof(showlmp_t));
1432 if (cl.num_showlmps)
1433 memcpy(cl.showlmps, oldshowlmps, cl.num_showlmps * sizeof(showlmp_t));
1434 Mem_Free(oldshowlmps);
1437 for (k = 0;k < cl.max_showlmps;k++)
1438 if (cl.showlmps[k].isactive && !strcmp(cl.showlmps[k].label, lmplabel))
1440 if (k == cl.max_showlmps)
1441 for (k = 0;k < cl.max_showlmps;k++)
1442 if (!cl.showlmps[k].isactive)
1444 cl.showlmps[k].isactive = true;
1445 dp_strlcpy (cl.showlmps[k].label, lmplabel, sizeof (cl.showlmps[k].label));
1446 dp_strlcpy (cl.showlmps[k].pic, picname, sizeof (cl.showlmps[k].pic));
1447 cl.showlmps[k].x = x;
1448 cl.showlmps[k].y = y;
1449 cl.num_showlmps = max(cl.num_showlmps, k + 1);
1452 void SHOWLMP_drawall(void)
1455 for (i = 0;i < cl.num_showlmps;i++)
1456 if (cl.showlmps[i].isactive)
1457 DrawQ_Pic(cl.showlmps[i].x, cl.showlmps[i].y, Draw_CachePic_Flags (cl.showlmps[i].pic, CACHEPICFLAG_NOTPERSISTENT), 0, 0, 1, 1, 1, 1, 0);
1461 ==============================================================================
1465 ==============================================================================
1469 // buffer2: 3*w*h (or 4*w*h if screenshotting alpha too)
1470 qbool SCR_ScreenShot(char *filename, unsigned char *buffer1, unsigned char *buffer2, int x, int y, int width, int height, qbool flipx, qbool flipy, qbool flipdiagonal, qbool jpeg, qbool png, qbool gammacorrect, qbool keep_alpha)
1472 int indices[4] = {0,1,2,3}; // BGRA
1475 GL_ReadPixelsBGRA(x, y, width, height, buffer1);
1477 if(gammacorrect && (scr_screenshot_gammaboost.value != 1))
1480 double igamma = 1.0 / scr_screenshot_gammaboost.value;
1481 unsigned short vidramp[256 * 3];
1482 // identity gamma table
1483 BuildGammaTable16(1.0f, 1.0f, 1.0f, 0.0f, 1.0f, vidramp, 256);
1484 BuildGammaTable16(1.0f, 1.0f, 1.0f, 0.0f, 1.0f, vidramp + 256, 256);
1485 BuildGammaTable16(1.0f, 1.0f, 1.0f, 0.0f, 1.0f, vidramp + 256*2, 256);
1486 if(scr_screenshot_gammaboost.value != 1)
1488 for (i = 0;i < 256 * 3;i++)
1489 vidramp[i] = (unsigned short) (0.5 + pow(vidramp[i] * (1.0 / 65535.0), igamma) * 65535.0);
1491 for (i = 0;i < width*height*4;i += 4)
1493 buffer1[i] = (unsigned char) (vidramp[buffer1[i] + 512] * 255.0 / 65535.0 + 0.5); // B
1494 buffer1[i+1] = (unsigned char) (vidramp[buffer1[i+1] + 256] * 255.0 / 65535.0 + 0.5); // G
1495 buffer1[i+2] = (unsigned char) (vidramp[buffer1[i+2]] * 255.0 / 65535.0 + 0.5); // R
1500 if(keep_alpha && !jpeg)
1503 flipy = !flipy; // TGA: not preflipped
1504 Image_CopyMux (buffer2, buffer1, width, height, flipx, flipy, flipdiagonal, 4, 4, indices);
1506 ret = PNG_SaveImage_preflipped (filename, width, height, true, buffer2);
1508 ret = Image_WriteTGABGRA(filename, width, height, buffer2);
1515 indices[2] = 0; // RGB
1517 Image_CopyMux (buffer2, buffer1, width, height, flipx, flipy, flipdiagonal, 3, 4, indices);
1519 ret = JPEG_SaveImage_preflipped (filename, width, height, buffer2);
1521 ret = PNG_SaveImage_preflipped (filename, width, height, false, buffer2);
1523 ret = Image_WriteTGABGR_preflipped (filename, width, height, buffer2);
1529 //=============================================================================
1531 int scr_numtouchscreenareas;
1532 scr_touchscreenarea_t scr_touchscreenareas[128];
1534 static void SCR_DrawTouchscreenOverlay(void)
1537 scr_touchscreenarea_t *a;
1539 for (i = 0, a = scr_touchscreenareas;i < scr_numtouchscreenareas;i++, a++)
1541 if (vid_touchscreen_outlinealpha.value > 0 && a->rect[0] >= 0 && a->rect[1] >= 0 && a->rect[2] >= 4 && a->rect[3] >= 4)
1543 DrawQ_Fill(a->rect[0] + 2, a->rect[1] , a->rect[2] - 4, 1 , 1, 1, 1, vid_touchscreen_outlinealpha.value * (0.5f + 0.5f * a->active), 0);
1544 DrawQ_Fill(a->rect[0] + 1, a->rect[1] + 1, a->rect[2] - 2, 1 , 1, 1, 1, vid_touchscreen_outlinealpha.value * (0.5f + 0.5f * a->active), 0);
1545 DrawQ_Fill(a->rect[0] , a->rect[1] + 2, 2 , a->rect[3] - 2, 1, 1, 1, vid_touchscreen_outlinealpha.value * (0.5f + 0.5f * a->active), 0);
1546 DrawQ_Fill(a->rect[0] + a->rect[2] - 2, a->rect[1] + 2, 2 , a->rect[3] - 2, 1, 1, 1, vid_touchscreen_outlinealpha.value * (0.5f + 0.5f * a->active), 0);
1547 DrawQ_Fill(a->rect[0] + 1, a->rect[1] + a->rect[3] - 2, a->rect[2] - 2, 1 , 1, 1, 1, vid_touchscreen_outlinealpha.value * (0.5f + 0.5f * a->active), 0);
1548 DrawQ_Fill(a->rect[0] + 2, a->rect[1] + a->rect[3] - 1, a->rect[2] - 4, 1 , 1, 1, 1, vid_touchscreen_outlinealpha.value * (0.5f + 0.5f * a->active), 0);
1550 pic = a->pic ? Draw_CachePic_Flags(a->pic, CACHEPICFLAG_FAILONMISSING) : NULL;
1551 if (Draw_IsPicLoaded(pic))
1552 DrawQ_Pic(a->rect[0], a->rect[1], pic, a->rect[2], a->rect[3], 1, 1, 1, vid_touchscreen_overlayalpha.value * (0.5f + 0.5f * a->active), 0);
1553 if (a->text && a->text[0])
1555 int textwidth = DrawQ_TextWidth(a->text, 0, a->textheight, a->textheight, false, FONT_CHAT);
1556 DrawQ_String(a->rect[0] + (a->rect[2] - textwidth) * 0.5f, a->rect[1] + (a->rect[3] - a->textheight) * 0.5f, a->text, 0, a->textheight, a->textheight, 1.0f, 1.0f, 1.0f, vid_touchscreen_overlayalpha.value, 0, NULL, false, FONT_CHAT);
1561 void R_ClearScreen(qbool fogcolor)
1563 float clearcolor[4];
1564 if (scr_screenshot_alpha.integer)
1565 // clear to transparency (so png screenshots can contain alpha channel, useful for building model pictures)
1566 Vector4Set(clearcolor, 0.0f, 0.0f, 0.0f, 0.0f);
1568 // clear to opaque black (if we're being composited it might otherwise render as transparent)
1569 Vector4Set(clearcolor, 0.0f, 0.0f, 0.0f, 1.0f);
1570 if (fogcolor && r_fog_clear.integer)
1573 VectorCopy(r_refdef.fogcolor, clearcolor);
1575 // clear depth is 1.0
1577 GL_Clear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | (vid.stencil ? GL_STENCIL_BUFFER_BIT : 0), clearcolor, 1.0f, 0);
1581 extern cvar_t v_isometric;
1582 extern cvar_t v_isometric_verticalfov;
1584 typedef struct loadingscreenstack_s
1586 struct loadingscreenstack_s *prev;
1587 char msg[MAX_QPATH];
1588 float absolute_loading_amount_min; // this corresponds to relative completion 0 of this item
1589 float absolute_loading_amount_len; // this corresponds to relative completion 1 of this item
1590 float relative_completion; // 0 .. 1
1592 loadingscreenstack_t;
1593 static loadingscreenstack_t *loadingscreenstack = NULL;
1594 rtexture_t *loadingscreentexture = NULL; // last framebuffer before loading screen, kept for the background
1595 static float loadingscreentexture_vertex3f[12];
1596 static float loadingscreentexture_texcoord2f[8];
1597 static int loadingscreenpic_number = 0;
1598 /// User-friendly connection status for the menu and/or loading screen,
1599 /// colours and \n not supported.
1600 char cl_connect_status[MAX_QPATH]; // should match size of loadingscreenstack_t msg[]
1602 static void SCR_DrawLoadingScreen(void);
1603 static void SCR_DrawScreen (void)
1608 R_UpdateVariables();
1610 // Quake uses clockwise winding, so these are swapped
1611 r_refdef.view.cullface_front = GL_BACK;
1612 r_refdef.view.cullface_back = GL_FRONT;
1614 if (!scr_loading && cls.signon == SIGNONS)
1618 size = scr_viewsize.value * (1.0 / 100.0);
1619 size = min(size, 1);
1621 if (r_stereo_sidebyside.integer)
1623 r_refdef.view.width = (int)(vid.width * size / 2.5);
1624 r_refdef.view.height = (int)(vid.height * size / 2.5 * (1 - bound(0, r_letterbox.value, 100) / 100));
1625 r_refdef.view.depth = 1;
1626 r_refdef.view.x = (int)((vid.width - r_refdef.view.width * 2.5) * 0.5);
1627 r_refdef.view.y = (int)((vid.height - r_refdef.view.height)/2);
1628 r_refdef.view.z = 0;
1630 r_refdef.view.x += (int)(r_refdef.view.width * 1.5);
1632 else if (r_stereo_horizontal.integer)
1634 r_refdef.view.width = (int)(vid.width * size / 2);
1635 r_refdef.view.height = (int)(vid.height * size * (1 - bound(0, r_letterbox.value, 100) / 100));
1636 r_refdef.view.depth = 1;
1637 r_refdef.view.x = (int)((vid.width - r_refdef.view.width * 2.0)/2);
1638 r_refdef.view.y = (int)((vid.height - r_refdef.view.height)/2);
1639 r_refdef.view.z = 0;
1641 r_refdef.view.x += (int)(r_refdef.view.width);
1643 else if (r_stereo_vertical.integer)
1645 r_refdef.view.width = (int)(vid.width * size);
1646 r_refdef.view.height = (int)(vid.height * size * (1 - bound(0, r_letterbox.value, 100) / 100) / 2);
1647 r_refdef.view.depth = 1;
1648 r_refdef.view.x = (int)((vid.width - r_refdef.view.width)/2);
1649 r_refdef.view.y = (int)((vid.height - r_refdef.view.height * 2.0)/2);
1650 r_refdef.view.z = 0;
1652 r_refdef.view.y += (int)(r_refdef.view.height);
1656 r_refdef.view.width = (int)(vid.width * size);
1657 r_refdef.view.height = (int)(vid.height * size * (1 - bound(0, r_letterbox.value, 100) / 100));
1658 r_refdef.view.depth = 1;
1659 r_refdef.view.x = (int)((vid.width - r_refdef.view.width)/2);
1660 r_refdef.view.y = (int)((vid.height - r_refdef.view.height)/2);
1661 r_refdef.view.z = 0;
1664 // LadyHavoc: viewzoom (zoom in for sniper rifles, etc)
1665 // LadyHavoc: this is designed to produce widescreen fov values
1666 // when the screen is wider than 4/3 width/height aspect, to do
1667 // this it simply assumes the requested fov is the vertical fov
1668 // for a 4x3 display, if the ratio is not 4x3 this makes the fov
1669 // higher/lower according to the ratio
1670 r_refdef.view.useperspective = true;
1671 r_refdef.view.frustum_y = tan(scr_fov.value * M_PI / 360.0) * (3.0 / 4.0) * cl.viewzoom;
1672 r_refdef.view.frustum_x = r_refdef.view.frustum_y * (float)r_refdef.view.width / (float)r_refdef.view.height / vid_pixelheight.value;
1674 r_refdef.view.frustum_x *= r_refdef.frustumscale_x;
1675 r_refdef.view.frustum_y *= r_refdef.frustumscale_y;
1676 r_refdef.view.ortho_x = atan(r_refdef.view.frustum_x) * (360.0 / M_PI); // abused as angle by VM_CL_R_SetView
1677 r_refdef.view.ortho_y = atan(r_refdef.view.frustum_y) * (360.0 / M_PI); // abused as angle by VM_CL_R_SetView
1679 r_refdef.view.ismain = true;
1681 // if CSQC is loaded, it is required to provide the CSQC_UpdateView function,
1682 // and won't render a view if it does not call that.
1684 CL_VM_UpdateView(r_stereo_side ? 0.0 : max(0.0, cl.time - cl.oldtime));
1687 // Prepare the scene mesh for rendering - this is lightning beams and other effects rendered as normal surfaces
1688 CL_MeshEntities_Scene_FinalizeRenderEntity();
1690 CL_UpdateEntityShading();
1691 R_RenderView(0, NULL, NULL, r_refdef.view.x, r_refdef.view.y, r_refdef.view.width, r_refdef.view.height);
1695 // Don't apply debugging stuff like r_showsurfaces to the UI
1696 r_refdef.view.showdebug = false;
1698 if (!r_stereo_sidebyside.integer && !r_stereo_horizontal.integer && !r_stereo_vertical.integer)
1700 r_refdef.view.width = vid.width;
1701 r_refdef.view.height = vid.height;
1702 r_refdef.view.depth = 1;
1703 r_refdef.view.x = 0;
1704 r_refdef.view.y = 0;
1705 r_refdef.view.z = 0;
1706 r_refdef.view.useperspective = false;
1709 if (cls.timedemo && cls.td_frames > 0 && timedemo_screenshotframelist.string && timedemo_screenshotframelist.string[0])
1713 t = timedemo_screenshotframelist.string;
1721 if (framenum == cls.td_frames)
1723 while (*t && *t != ' ')
1728 // we need to take a screenshot of this frame...
1729 char filename[MAX_QPATH];
1730 unsigned char *buffer1;
1731 unsigned char *buffer2;
1732 dpsnprintf(filename, sizeof(filename), "timedemoscreenshots/%s%06d.tga", cls.demoname, cls.td_frames);
1733 buffer1 = (unsigned char *)Mem_Alloc(tempmempool, vid.width * vid.height * 4);
1734 buffer2 = (unsigned char *)Mem_Alloc(tempmempool, vid.width * vid.height * 3);
1735 SCR_ScreenShot(filename, buffer1, buffer2, 0, 0, vid.width, vid.height, false, false, false, false, false, true, false);
1743 if(!scr_con_current && !(key_consoleactive & KEY_CONSOLEACTIVE_FORCED))
1744 if ((key_dest == key_game || key_dest == key_message) && !r_letterbox.value && !scr_loading)
1745 Con_DrawNotify (); // only draw notify in game
1747 if (cl.islocalgame && (key_dest != key_game || key_consoleactive))
1750 host.paused = false;
1752 if (!scr_loading && cls.signon == SIGNONS)
1757 if (!r_letterbox.value)
1760 SCR_CheckDrawCenterString();
1762 SCR_DrawNetGraph ();
1768 R_Shadow_EditLights_DrawSelectedLightProperties();
1772 // connect_status replaces any dummy_status
1773 if ((!loadingscreenstack || loadingscreenstack->msg[0] == '\0') && cl_connect_status[0] != '\0')
1775 loadingscreenstack_t connect_status, *og_ptr = loadingscreenstack;
1777 connect_status.absolute_loading_amount_min = 0;
1778 dp_strlcpy(connect_status.msg, cl_connect_status, sizeof(cl_connect_status));
1779 loadingscreenstack = &connect_status;
1780 SCR_DrawLoadingScreen();
1781 loadingscreenstack = og_ptr;
1784 SCR_DrawLoadingScreen();
1793 SCR_DrawTouchscreenOverlay();
1795 if (r_timereport_active)
1798 R_TimeReport_EndFrame();
1799 R_TimeReport_BeginFrame();
1806 R_RenderTarget_FreeUnused(false);
1809 static void SCR_ClearLoadingScreenTexture(void)
1811 if(loadingscreentexture)
1812 R_FreeTexture(loadingscreentexture);
1813 loadingscreentexture = NULL;
1816 extern rtexturepool_t *r_main_texturepool;
1817 static void SCR_SetLoadingScreenTexture(void)
1820 float loadingscreentexture_w;
1821 float loadingscreentexture_h;
1823 SCR_ClearLoadingScreenTexture();
1825 w = vid.width; h = vid.height;
1826 loadingscreentexture_w = loadingscreentexture_h = 1;
1828 loadingscreentexture = R_LoadTexture2D(r_main_texturepool, "loadingscreentexture", w, h, NULL, TEXTYPE_COLORBUFFER, TEXF_RENDERTARGET | TEXF_FORCENEAREST | TEXF_CLAMP, -1, NULL);
1829 R_Mesh_CopyToTexture(loadingscreentexture, 0, 0, 0, 0, vid.width, vid.height);
1831 loadingscreentexture_vertex3f[2] = loadingscreentexture_vertex3f[5] = loadingscreentexture_vertex3f[8] = loadingscreentexture_vertex3f[11] = 0;
1832 loadingscreentexture_vertex3f[0] = loadingscreentexture_vertex3f[9] = 0;
1833 loadingscreentexture_vertex3f[1] = loadingscreentexture_vertex3f[4] = 0;
1834 loadingscreentexture_vertex3f[3] = loadingscreentexture_vertex3f[6] = vid_conwidth.integer;
1835 loadingscreentexture_vertex3f[7] = loadingscreentexture_vertex3f[10] = vid_conheight.integer;
1836 loadingscreentexture_texcoord2f[0] = 0;loadingscreentexture_texcoord2f[1] = loadingscreentexture_h;
1837 loadingscreentexture_texcoord2f[2] = loadingscreentexture_w;loadingscreentexture_texcoord2f[3] = loadingscreentexture_h;
1838 loadingscreentexture_texcoord2f[4] = loadingscreentexture_w;loadingscreentexture_texcoord2f[5] = 0;
1839 loadingscreentexture_texcoord2f[6] = 0;loadingscreentexture_texcoord2f[7] = 0;
1842 static void SCR_ChooseLoadingPic(qbool startup)
1844 if(startup && scr_loadingscreen_firstforstartup.integer)
1845 loadingscreenpic_number = 0;
1846 else if(scr_loadingscreen_firstforstartup.integer)
1847 if(scr_loadingscreen_count.integer > 1)
1848 loadingscreenpic_number = rand() % (scr_loadingscreen_count.integer - 1) + 1;
1850 loadingscreenpic_number = 0;
1852 loadingscreenpic_number = rand() % (scr_loadingscreen_count.integer > 1 ? scr_loadingscreen_count.integer : 1);
1857 SCR_BeginLoadingPlaque
1861 void SCR_BeginLoadingPlaque(qbool startup)
1863 loadingscreenstack_t dummy_status;
1865 // we need to push a dummy status so CL_UpdateScreen knows we have things to load...
1866 if (!loadingscreenstack)
1868 dummy_status.msg[0] = '\0';
1869 dummy_status.absolute_loading_amount_min = 0;
1870 loadingscreenstack = &dummy_status;
1873 SCR_DeferLoadingPlaque(startup);
1874 if (scr_loadingscreen_background.integer)
1875 SCR_SetLoadingScreenTexture();
1878 if (loadingscreenstack == &dummy_status)
1879 loadingscreenstack = NULL;
1882 void SCR_DeferLoadingPlaque(qbool startup)
1884 SCR_ChooseLoadingPic(startup);
1888 void SCR_EndLoadingPlaque(void)
1890 scr_loading = false;
1891 SCR_ClearLoadingScreenTexture();
1894 //=============================================================================
1896 void SCR_PushLoadingScreen (const char *msg, float len_in_parent)
1898 loadingscreenstack_t *s = (loadingscreenstack_t *) Z_Malloc(sizeof(loadingscreenstack_t));
1899 s->prev = loadingscreenstack;
1900 loadingscreenstack = s;
1902 dp_strlcpy(s->msg, msg, sizeof(s->msg));
1903 s->relative_completion = 0;
1907 s->absolute_loading_amount_min = s->prev->absolute_loading_amount_min + s->prev->absolute_loading_amount_len * s->prev->relative_completion;
1908 s->absolute_loading_amount_len = s->prev->absolute_loading_amount_len * len_in_parent;
1909 if(s->absolute_loading_amount_len > s->prev->absolute_loading_amount_min + s->prev->absolute_loading_amount_len - s->absolute_loading_amount_min)
1910 s->absolute_loading_amount_len = s->prev->absolute_loading_amount_min + s->prev->absolute_loading_amount_len - s->absolute_loading_amount_min;
1914 s->absolute_loading_amount_min = 0;
1915 s->absolute_loading_amount_len = 1;
1922 void SCR_PopLoadingScreen (qbool redraw)
1924 loadingscreenstack_t *s = loadingscreenstack;
1928 Con_DPrintf("Popping a loading screen item from an empty stack!\n");
1932 loadingscreenstack = s->prev;
1934 s->prev->relative_completion = (s->absolute_loading_amount_min + s->absolute_loading_amount_len - s->prev->absolute_loading_amount_min) / s->prev->absolute_loading_amount_len;
1937 if (scr_loading && redraw)
1941 void SCR_ClearLoadingScreen (qbool redraw)
1943 while(loadingscreenstack)
1944 SCR_PopLoadingScreen(redraw && !loadingscreenstack->prev);
1947 static float SCR_DrawLoadingStack_r(loadingscreenstack_t *s, float y, float size)
1957 total += SCR_DrawLoadingStack_r(s->prev, y, 8);
1959 if(!s->prev || strcmp(s->msg, s->prev->msg))
1961 len = strlen(s->msg);
1962 x = (vid_conwidth.integer - DrawQ_TextWidth(s->msg, len, size, size, true, FONT_INFOBAR)) / 2;
1964 DrawQ_String(x, y, s->msg, len, size, size, 1, 1, 1, 1, 0, NULL, true, FONT_INFOBAR);
1971 len = strlen(s->msg);
1972 x = (vid_conwidth.integer - DrawQ_TextWidth(s->msg, len, size, size, true, FONT_INFOBAR)) / 2;
1974 DrawQ_String(x, y, s->msg, len, size, size, 1, 1, 1, 1, 0, NULL, true, FONT_INFOBAR);
1981 static void SCR_DrawLoadingStack(void)
1986 SCR_DrawLoadingStack_r(loadingscreenstack, vid_conheight.integer, scr_loadingscreen_barheight.value);
1987 if(loadingscreenstack)
1989 // height = 32; // sorry, using the actual one is ugly
1990 GL_BlendFunc(GL_SRC_ALPHA, GL_ONE);
1991 GL_DepthRange(0, 1);
1992 GL_PolygonOffset(0, 0);
1993 GL_DepthTest(false);
1994 //R_Mesh_ResetTextureState();
1995 verts[2] = verts[5] = verts[8] = verts[11] = 0;
1996 verts[0] = verts[9] = 0;
1997 verts[1] = verts[4] = vid_conheight.integer - scr_loadingscreen_barheight.value;
1998 verts[3] = verts[6] = vid_conwidth.integer * loadingscreenstack->absolute_loading_amount_min;
1999 verts[7] = verts[10] = vid_conheight.integer;
2001 #if _MSC_VER >= 1400
2002 #define sscanf sscanf_s
2004 colors[0] = 0; colors[1] = 0; colors[2] = 0; colors[3] = 1;
2005 colors[4] = 0; colors[5] = 0; colors[6] = 0; colors[7] = 1;
2006 sscanf(scr_loadingscreen_barcolor.string, "%f %f %f", &colors[8], &colors[9], &colors[10]); colors[11] = 1;
2007 sscanf(scr_loadingscreen_barcolor.string, "%f %f %f", &colors[12], &colors[13], &colors[14]); colors[15] = 1;
2009 R_Mesh_PrepareVertices_Generic_Arrays(4, verts, colors, NULL);
2010 R_SetupShader_Generic_NoTexture(true, true);
2011 R_Mesh_Draw(0, 4, 0, 2, polygonelement3i, NULL, 0, polygonelement3s, NULL, 0);
2015 static void SCR_DrawLoadingScreen (void)
2017 cachepic_t *loadingscreenpic;
2018 float loadingscreenpic_vertex3f[12];
2019 float loadingscreenpic_texcoord2f[8];
2020 float x, y, w, h, sw, sh, f;
2023 GL_BlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
2024 GL_DepthRange(0, 1);
2025 GL_PolygonOffset(0, 0);
2026 GL_DepthTest(false);
2029 if(loadingscreentexture)
2031 R_Mesh_PrepareVertices_Generic_Arrays(4, loadingscreentexture_vertex3f, NULL, loadingscreentexture_texcoord2f);
2032 R_SetupShader_Generic(loadingscreentexture, false, true, true);
2033 R_Mesh_Draw(0, 4, 0, 2, polygonelement3i, NULL, 0, polygonelement3s, NULL, 0);
2036 loadingscreenpic = Draw_CachePic_Flags(loadingscreenpic_number ? va(vabuf, sizeof(vabuf), "%s%d", scr_loadingscreen_picture.string, loadingscreenpic_number+1) : scr_loadingscreen_picture.string, loadingscreenpic_number ? CACHEPICFLAG_NOTPERSISTENT : 0);
2037 w = Draw_GetPicWidth(loadingscreenpic);
2038 h = Draw_GetPicHeight(loadingscreenpic);
2041 w *= scr_loadingscreen_scale.value;
2042 h *= scr_loadingscreen_scale.value;
2045 if(scr_loadingscreen_scale_base.integer)
2047 w *= vid_conwidth.integer / (float) vid.width;
2048 h *= vid_conheight.integer / (float) vid.height;
2051 // apply scale limit
2052 sw = w / vid_conwidth.integer;
2053 sh = h / vid_conheight.integer;
2055 switch(scr_loadingscreen_scale_limit.integer)
2076 x = (vid_conwidth.integer - w)/2;
2077 y = (vid_conheight.integer - h)/2;
2078 loadingscreenpic_vertex3f[2] = loadingscreenpic_vertex3f[5] = loadingscreenpic_vertex3f[8] = loadingscreenpic_vertex3f[11] = 0;
2079 loadingscreenpic_vertex3f[0] = loadingscreenpic_vertex3f[9] = x;
2080 loadingscreenpic_vertex3f[1] = loadingscreenpic_vertex3f[4] = y;
2081 loadingscreenpic_vertex3f[3] = loadingscreenpic_vertex3f[6] = x + w;
2082 loadingscreenpic_vertex3f[7] = loadingscreenpic_vertex3f[10] = y + h;
2083 loadingscreenpic_texcoord2f[0] = 0;loadingscreenpic_texcoord2f[1] = 0;
2084 loadingscreenpic_texcoord2f[2] = 1;loadingscreenpic_texcoord2f[3] = 0;
2085 loadingscreenpic_texcoord2f[4] = 1;loadingscreenpic_texcoord2f[5] = 1;
2086 loadingscreenpic_texcoord2f[6] = 0;loadingscreenpic_texcoord2f[7] = 1;
2088 R_Mesh_PrepareVertices_Generic_Arrays(4, loadingscreenpic_vertex3f, NULL, loadingscreenpic_texcoord2f);
2089 R_SetupShader_Generic(Draw_GetPicTexture(loadingscreenpic), true, true, false);
2090 R_Mesh_Draw(0, 4, 0, 2, polygonelement3i, NULL, 0, polygonelement3s, NULL, 0);
2092 SCR_DrawLoadingStack();
2095 qbool R_Stereo_ColorMasking(void)
2097 return r_stereo_redblue.integer || r_stereo_redgreen.integer || r_stereo_redcyan.integer;
2100 qbool R_Stereo_Active(void)
2102 return (vid.stereobuffer || r_stereo_sidebyside.integer || r_stereo_horizontal.integer || r_stereo_vertical.integer || R_Stereo_ColorMasking());
2105 static void SCR_UpdateVars(void)
2107 float conwidth = bound(160, vid_conwidth.value, 32768);
2108 float conheight = bound(90, vid_conheight.value, 24576);
2109 if (vid_conwidthauto.integer)
2110 conwidth = floor(conheight * vid.width / (vid.height * vid_pixelheight.value));
2111 if (vid_conwidth.value != conwidth)
2112 Cvar_SetValueQuick(&vid_conwidth, conwidth);
2113 if (vid_conheight.value != conheight)
2114 Cvar_SetValueQuick(&vid_conheight, conheight);
2117 if (scr_viewsize.value < 30)
2118 Cvar_SetValueQuick(&scr_viewsize, 30);
2119 if (scr_viewsize.value > 120)
2120 Cvar_SetValueQuick(&scr_viewsize, 120);
2122 // bound field of view
2123 if (scr_fov.value < 1)
2124 Cvar_SetValueQuick(&scr_fov, 1);
2125 if (scr_fov.value > 170)
2126 Cvar_SetValueQuick(&scr_fov, 170);
2128 // intermission is always full screen
2129 if (cl.intermission)
2133 if (scr_viewsize.value >= 120)
2134 sb_lines = 0; // no status bar at all
2135 else if (scr_viewsize.value >= 110)
2136 sb_lines = 24; // no inventory
2138 sb_lines = 24 + 16 + 8;
2142 extern cvar_t cl_minfps;
2143 extern cvar_t cl_minfps_fade;
2144 extern cvar_t cl_minfps_qualitymax;
2145 extern cvar_t cl_minfps_qualitymin;
2146 extern cvar_t cl_minfps_qualitymultiply;
2147 extern cvar_t cl_minfps_qualityhysteresis;
2148 extern cvar_t cl_minfps_qualitystepmax;
2149 extern cvar_t cl_minfps_force;
2150 void CL_UpdateScreen(void)
2152 static double cl_updatescreen_quality = 1;
2155 static double drawscreenstart = 0.0;
2156 double drawscreendelta;
2157 r_viewport_t viewport;
2159 // TODO: Move to a better place.
2160 cl_punchangle_applied = 0;
2164 drawscreendelta = Sys_DirtyTime() - drawscreenstart;
2165 #ifdef CONFIG_VIDEO_CAPTURE
2166 if (cl_minfps.value > 0 && (cl_minfps_force.integer || !(cls.timedemo || (cls.capturevideo.active && !cls.capturevideo.realtime))) && drawscreendelta >= 0 && drawscreendelta < 60)
2168 if (cl_minfps.value > 0 && (cl_minfps_force.integer || !cls.timedemo) && drawscreendelta >= 0 && drawscreendelta < 60)
2171 // quality adjustment according to render time
2172 double actualframetime;
2173 double targetframetime;
2178 // fade lastdrawscreentime
2179 r_refdef.lastdrawscreentime += (drawscreendelta - r_refdef.lastdrawscreentime) * cl_minfps_fade.value;
2181 // find actual and target frame times
2182 actualframetime = r_refdef.lastdrawscreentime;
2183 targetframetime = (1.0 / cl_minfps.value);
2185 // we scale hysteresis by quality
2186 h = cl_updatescreen_quality * cl_minfps_qualityhysteresis.value;
2188 // calculate adjustment assuming linearity
2189 f = cl_updatescreen_quality / actualframetime * cl_minfps_qualitymultiply.value;
2190 adjust = (targetframetime - actualframetime) * f;
2192 // one sided hysteresis
2194 adjust = max(0, adjust - h);
2197 // (targetframetime - actualframetime) * f > h
2198 // ((1.0 / cl_minfps.value) - actualframetime) * (cl_updatescreen_quality / actualframetime * cl_minfps_qualitymultiply.value) > (cl_updatescreen_quality * cl_minfps_qualityhysteresis.value)
2199 // ((1.0 / cl_minfps.value) - actualframetime) * (cl_minfps_qualitymultiply.value / actualframetime) > cl_minfps_qualityhysteresis.value
2200 // (1.0 / cl_minfps.value) * (cl_minfps_qualitymultiply.value / actualframetime) - cl_minfps_qualitymultiply.value > cl_minfps_qualityhysteresis.value
2201 // (1.0 / cl_minfps.value) * (cl_minfps_qualitymultiply.value / actualframetime) > cl_minfps_qualityhysteresis.value + cl_minfps_qualitymultiply.value
2202 // (1.0 / cl_minfps.value) / actualframetime > (cl_minfps_qualityhysteresis.value + cl_minfps_qualitymultiply.value) / cl_minfps_qualitymultiply.value
2203 // (1.0 / cl_minfps.value) / actualframetime > 1.0 + cl_minfps_qualityhysteresis.value / cl_minfps_qualitymultiply.value
2204 // cl_minfps.value * actualframetime < 1.0 / (1.0 + cl_minfps_qualityhysteresis.value / cl_minfps_qualitymultiply.value)
2205 // actualframetime < 1.0 / cl_minfps.value / (1.0 + cl_minfps_qualityhysteresis.value / cl_minfps_qualitymultiply.value)
2206 // actualfps > cl_minfps.value * (1.0 + cl_minfps_qualityhysteresis.value / cl_minfps_qualitymultiply.value)
2209 // (targetframetime - actualframetime) * f < 0
2210 // ((1.0 / cl_minfps.value) - actualframetime) * (cl_updatescreen_quality / actualframetime * cl_minfps_qualitymultiply.value) < 0
2211 // ((1.0 / cl_minfps.value) - actualframetime) < 0
2212 // -actualframetime) < -(1.0 / cl_minfps.value)
2213 // actualfps < cl_minfps.value
2216 Con_Printf("adjust UP if fps > %f, adjust DOWN if fps < %f\n",
2217 cl_minfps.value * (1.0 + cl_minfps_qualityhysteresis.value / cl_minfps_qualitymultiply.value),
2221 // don't adjust too much at once
2222 adjust = bound(-cl_minfps_qualitystepmax.value, adjust, cl_minfps_qualitystepmax.value);
2225 cl_updatescreen_quality += adjust;
2226 cl_updatescreen_quality = bound(max(0.01, cl_minfps_qualitymin.value), cl_updatescreen_quality, cl_minfps_qualitymax.value);
2230 cl_updatescreen_quality = 1;
2231 r_refdef.lastdrawscreentime = 0;
2235 drawscreenstart = Sys_DirtyTime();
2237 Sbar_ShowFPS_Update();
2239 if (!scr_initialized || !con_initialized || !scr_refresh.integer)
2240 return; // not initialized yet
2242 if(IS_NEXUIZ_DERIVED(gamemode))
2244 // play a bit with the palette (experimental)
2245 palette_rgb_pantscolormap[15][0] = (unsigned char) (128 + 127 * sin(cl.time / exp(1.0f) + 0.0f*M_PI/3.0f));
2246 palette_rgb_pantscolormap[15][1] = (unsigned char) (128 + 127 * sin(cl.time / exp(1.0f) + 2.0f*M_PI/3.0f));
2247 palette_rgb_pantscolormap[15][2] = (unsigned char) (128 + 127 * sin(cl.time / exp(1.0f) + 4.0f*M_PI/3.0f));
2248 palette_rgb_shirtcolormap[15][0] = (unsigned char) (128 + 127 * sin(cl.time / M_PI + 5.0f*M_PI/3.0f));
2249 palette_rgb_shirtcolormap[15][1] = (unsigned char) (128 + 127 * sin(cl.time / M_PI + 3.0f*M_PI/3.0f));
2250 palette_rgb_shirtcolormap[15][2] = (unsigned char) (128 + 127 * sin(cl.time / M_PI + 1.0f*M_PI/3.0f));
2251 memcpy(palette_rgb_pantsscoreboard[15], palette_rgb_pantscolormap[15], sizeof(*palette_rgb_pantscolormap));
2252 memcpy(palette_rgb_shirtscoreboard[15], palette_rgb_shirtcolormap[15], sizeof(*palette_rgb_shirtcolormap));
2255 #ifdef CONFIG_VIDEO_CAPTURE
2256 if (vid_hidden && !cls.capturevideo.active && !cl_capturevideo.integer)
2267 if(!loadingscreenstack && !cls.connect_trying && (cls.state != ca_connected || cls.signon == SIGNONS))
2268 SCR_EndLoadingPlaque();
2269 else if (scr_loadingscreen_maxfps.value > 0)
2271 static float lastupdate;
2272 float now = Sys_DirtyTime();
2273 if (now - lastupdate < min(1.0f / scr_loadingscreen_maxfps.value, 0.1))
2281 R_FrameData_NewFrame();
2282 R_BufferData_NewFrame();
2284 Matrix4x4_OriginFromMatrix(&r_refdef.view.matrix, vieworigin);
2285 R_HDR_UpdateIrisAdaptation(vieworigin);
2287 r_refdef.view.colormask[0] = 1;
2288 r_refdef.view.colormask[1] = 1;
2289 r_refdef.view.colormask[2] = 1;
2291 SCR_SetUpToDrawConsole();
2295 qglDrawBuffer(GL_BACK);CHECKGLERROR
2298 R_Viewport_InitOrtho(&viewport, &identitymatrix, 0, 0, vid.width, vid.height, 0, 0, vid_conwidth.integer, vid_conheight.integer, -10, 100, NULL);
2299 R_Mesh_SetRenderTargets(0, NULL, NULL, NULL, NULL, NULL);
2300 R_SetViewport(&viewport);
2301 GL_ScissorTest(false);
2302 GL_ColorMask(1,1,1,1);
2305 R_ClearScreen(false);
2306 r_refdef.view.clear = false;
2307 r_refdef.view.isoverlay = false;
2309 // calculate r_refdef.view.quality
2310 r_refdef.view.quality = cl_updatescreen_quality;
2312 if(scr_stipple.integer)
2314 Con_Print("FIXME: scr_stipple not implemented\n");
2315 Cvar_SetValueQuick(&scr_stipple, 0);
2319 if (R_Stereo_Active())
2323 if (r_stereo_redblue.integer || r_stereo_redgreen.integer || r_stereo_redcyan.integer)
2325 r_refdef.view.colormask[0] = 1;
2326 r_refdef.view.colormask[1] = 0;
2327 r_refdef.view.colormask[2] = 0;
2330 if (vid.stereobuffer)
2331 qglDrawBuffer(GL_BACK_RIGHT);
2336 r_refdef.view.clear = true;
2338 if (r_stereo_redblue.integer || r_stereo_redgreen.integer || r_stereo_redcyan.integer)
2340 r_refdef.view.colormask[0] = 0;
2341 r_refdef.view.colormask[1] = r_stereo_redcyan.integer || r_stereo_redgreen.integer;
2342 r_refdef.view.colormask[2] = r_stereo_redcyan.integer || r_stereo_redblue.integer;
2345 if (vid.stereobuffer)
2346 qglDrawBuffer(GL_BACK_LEFT);
2358 #ifdef CONFIG_VIDEO_CAPTURE
2362 qglFlush(); // ensure that the commands are submitted to the GPU before we do other things
2366 void CL_Screen_NewMap(void)