2001-02-19 21:15:25 +00:00
|
|
|
/*
|
|
|
|
gl_screen.c
|
|
|
|
|
|
|
|
master for refresh, status bar, console, chat, notify, etc
|
|
|
|
|
|
|
|
Copyright (C) 1996-1997 Id Software, Inc.
|
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or
|
|
|
|
modify it under the terms of the GNU General Public License
|
|
|
|
as published by the Free Software Foundation; either version 2
|
|
|
|
of the License, or (at your option) any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
|
|
|
|
|
|
See the GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program; if not, write to:
|
|
|
|
|
|
|
|
Free Software Foundation, Inc.
|
|
|
|
59 Temple Place - Suite 330
|
|
|
|
Boston, MA 02111-1307, USA
|
|
|
|
|
|
|
|
*/
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
# include "config.h"
|
|
|
|
#endif
|
2003-01-15 15:31:36 +00:00
|
|
|
|
2012-02-22 07:32:34 +00:00
|
|
|
#define NH_DEFINE
|
|
|
|
#include "namehack.h"
|
|
|
|
|
2001-02-19 21:15:25 +00:00
|
|
|
#ifdef HAVE_STRING_H
|
|
|
|
# include <string.h>
|
|
|
|
#endif
|
|
|
|
#ifdef HAVE_STRINGS_H
|
|
|
|
# include <strings.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <time.h>
|
|
|
|
|
2001-05-31 03:41:35 +00:00
|
|
|
#include "QF/cvar.h"
|
2001-05-09 22:40:51 +00:00
|
|
|
#include "QF/draw.h"
|
2003-05-23 17:17:01 +00:00
|
|
|
#include "QF/dstring.h"
|
2003-09-04 18:59:39 +00:00
|
|
|
#include "QF/image.h"
|
2002-12-11 16:45:40 +00:00
|
|
|
#include "QF/quakefs.h"
|
|
|
|
#include "QF/render.h"
|
2001-05-23 06:33:23 +00:00
|
|
|
#include "QF/screen.h"
|
2001-04-15 21:11:41 +00:00
|
|
|
#include "QF/sys.h"
|
2001-05-09 17:57:57 +00:00
|
|
|
#include "QF/tga.h"
|
2003-05-23 17:17:01 +00:00
|
|
|
#include "QF/va.h"
|
2001-08-22 11:00:25 +00:00
|
|
|
#include "QF/GL/defines.h"
|
|
|
|
#include "QF/GL/funcs.h"
|
2012-02-22 12:53:17 +00:00
|
|
|
#include "QF/GL/qf_draw.h"
|
2001-08-22 11:00:25 +00:00
|
|
|
#include "QF/GL/qf_rmain.h"
|
|
|
|
#include "QF/GL/qf_vid.h"
|
2001-04-15 21:11:41 +00:00
|
|
|
|
2001-05-31 18:11:05 +00:00
|
|
|
#include "compat.h"
|
2012-02-14 08:28:09 +00:00
|
|
|
#include "r_internal.h"
|
2001-02-19 21:15:25 +00:00
|
|
|
#include "sbar.h"
|
2019-07-08 16:00:47 +00:00
|
|
|
#include "vid_gl.h"
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-09-09 21:41:35 +00:00
|
|
|
/* SCREEN SHOTS */
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2012-02-18 13:28:42 +00:00
|
|
|
tex_t *
|
2012-02-22 07:32:34 +00:00
|
|
|
gl_SCR_CaptureBGR (void)
|
2012-01-05 10:19:37 +00:00
|
|
|
{
|
|
|
|
int count;
|
|
|
|
tex_t *tex;
|
|
|
|
|
|
|
|
count = vid.width * vid.height;
|
|
|
|
tex = malloc (field_offset (tex_t, data[count * 3]));
|
|
|
|
SYS_CHECKMEM (tex);
|
|
|
|
tex->width = vid.width;
|
|
|
|
tex->height = vid.height;
|
|
|
|
tex->format = tex_rgb;
|
|
|
|
tex->palette = 0;
|
|
|
|
qfglReadPixels (0, 0, tex->width, tex->height, GL_BGR_EXT,
|
|
|
|
GL_UNSIGNED_BYTE, tex->data);
|
|
|
|
return tex;
|
|
|
|
}
|
|
|
|
|
2012-02-18 13:28:42 +00:00
|
|
|
tex_t *
|
2012-02-22 07:32:34 +00:00
|
|
|
gl_SCR_ScreenShot (int width, int height)
|
2001-05-23 06:33:23 +00:00
|
|
|
{
|
2002-12-10 18:24:38 +00:00
|
|
|
unsigned char *src, *dest, *snap;
|
2001-09-01 08:57:04 +00:00
|
|
|
float fracw, frach;
|
|
|
|
int count, dex, dey, dx, dy, nx, r, g, b, x, y, w, h;
|
|
|
|
tex_t *tex;
|
2001-05-23 06:33:23 +00:00
|
|
|
|
2002-12-10 18:24:38 +00:00
|
|
|
snap = Hunk_TempAlloc (vid.width * vid.height * 3);
|
2001-05-23 06:33:23 +00:00
|
|
|
|
2002-12-10 18:24:38 +00:00
|
|
|
qfglReadPixels (0, 0, vid.width, vid.height, GL_RGB, GL_UNSIGNED_BYTE,
|
|
|
|
snap);
|
2001-05-23 06:33:23 +00:00
|
|
|
|
2012-10-20 16:10:00 +00:00
|
|
|
w = (vid.width < width) ? vid.width : width;
|
|
|
|
h = (vid.height < height) ? vid.height : height;
|
2001-05-23 06:33:23 +00:00
|
|
|
|
2002-12-11 05:33:54 +00:00
|
|
|
fracw = (float) vid.width / (float) w;
|
|
|
|
frach = (float) vid.height / (float) h;
|
|
|
|
|
2002-12-10 18:24:38 +00:00
|
|
|
tex = malloc (field_offset (tex_t, data[w * h]));
|
|
|
|
if (!tex)
|
|
|
|
return 0;
|
|
|
|
|
2002-12-09 17:47:12 +00:00
|
|
|
tex->width = w;
|
|
|
|
tex->height = h;
|
|
|
|
tex->palette = vid.palette;
|
|
|
|
|
2001-05-23 06:33:23 +00:00
|
|
|
for (y = 0; y < h; y++) {
|
2002-12-11 05:46:42 +00:00
|
|
|
dest = tex->data + (w * y);
|
2001-05-23 06:33:23 +00:00
|
|
|
|
|
|
|
for (x = 0; x < w; x++) {
|
|
|
|
r = g = b = 0;
|
|
|
|
|
|
|
|
dx = x * fracw;
|
|
|
|
dex = (x + 1) * fracw;
|
|
|
|
if (dex == dx)
|
|
|
|
dex++; // at least one
|
|
|
|
dy = y * frach;
|
|
|
|
dey = (y + 1) * frach;
|
|
|
|
if (dey == dy)
|
|
|
|
dey++; // at least one
|
|
|
|
|
|
|
|
count = 0;
|
2001-09-09 21:41:35 +00:00
|
|
|
for (; dy < dey; dy++) {
|
2002-12-10 18:24:38 +00:00
|
|
|
src = snap + (vid.width * 3 * dy) + dx * 3;
|
2001-05-23 06:33:23 +00:00
|
|
|
for (nx = dx; nx < dex; nx++) {
|
|
|
|
r += *src++;
|
|
|
|
g += *src++;
|
|
|
|
b += *src++;
|
|
|
|
count++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
r /= count;
|
|
|
|
g /= count;
|
|
|
|
b /= count;
|
2002-12-11 05:46:42 +00:00
|
|
|
*dest++ = MipColor (r, g, b);
|
2001-05-23 06:33:23 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return tex;
|
|
|
|
}
|
2001-05-09 17:57:57 +00:00
|
|
|
|
2001-02-19 21:15:25 +00:00
|
|
|
void
|
2012-02-22 07:32:34 +00:00
|
|
|
gl_SCR_ScreenShot_f (void)
|
2001-02-19 21:15:25 +00:00
|
|
|
{
|
2003-05-23 17:17:01 +00:00
|
|
|
dstring_t *pcxname = dstring_new ();
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2012-01-05 10:19:37 +00:00
|
|
|
// find a file name to save it to
|
2003-05-23 17:17:01 +00:00
|
|
|
if (!QFS_NextFilename (pcxname,
|
2012-01-05 08:04:23 +00:00
|
|
|
va ("%s/qf", qfs_gamedir->dir.shots), ".tga")) {
|
2007-11-06 10:17:14 +00:00
|
|
|
Sys_Printf ("SCR_ScreenShot_f: Couldn't create a TGA file\n");
|
2003-05-23 17:17:01 +00:00
|
|
|
} else {
|
2012-01-05 10:19:37 +00:00
|
|
|
tex_t *tex;
|
|
|
|
|
2012-02-22 07:32:34 +00:00
|
|
|
tex = gl_SCR_CaptureBGR ();
|
2012-01-05 10:19:37 +00:00
|
|
|
WriteTGAfile (pcxname->str, tex->data, tex->width, tex->height);
|
|
|
|
free (tex);
|
2007-11-06 10:17:14 +00:00
|
|
|
Sys_Printf ("Wrote %s/%s\n", qfs_userpath, pcxname->str);
|
2001-02-19 21:15:25 +00:00
|
|
|
}
|
2003-05-23 17:17:01 +00:00
|
|
|
dstring_delete (pcxname);
|
2001-02-19 21:15:25 +00:00
|
|
|
}
|
|
|
|
|
2003-01-06 18:28:13 +00:00
|
|
|
static void
|
2001-02-19 21:15:25 +00:00
|
|
|
SCR_TileClear (void)
|
|
|
|
{
|
|
|
|
if (r_refdef.vrect.x > 0) {
|
|
|
|
// left
|
2012-02-14 08:28:09 +00:00
|
|
|
Draw_TileClear (0, 0, r_refdef.vrect.x, vid.height - vr_data.lineadj);
|
2001-02-19 21:15:25 +00:00
|
|
|
// right
|
|
|
|
Draw_TileClear (r_refdef.vrect.x + r_refdef.vrect.width, 0,
|
|
|
|
vid.width - r_refdef.vrect.x + r_refdef.vrect.width,
|
2012-02-14 08:28:09 +00:00
|
|
|
vid.height - vr_data.lineadj);
|
2001-02-19 21:15:25 +00:00
|
|
|
}
|
|
|
|
if (r_refdef.vrect.y > 0) {
|
|
|
|
// top
|
|
|
|
Draw_TileClear (r_refdef.vrect.x, 0,
|
|
|
|
r_refdef.vrect.x + r_refdef.vrect.width,
|
|
|
|
r_refdef.vrect.y);
|
|
|
|
// bottom
|
|
|
|
Draw_TileClear (r_refdef.vrect.x,
|
|
|
|
r_refdef.vrect.y + r_refdef.vrect.height,
|
|
|
|
r_refdef.vrect.width,
|
2012-02-14 08:28:09 +00:00
|
|
|
vid.height - vr_data.lineadj -
|
2001-02-19 21:15:25 +00:00
|
|
|
(r_refdef.vrect.height + r_refdef.vrect.y));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
SCR_UpdateScreen
|
|
|
|
|
|
|
|
This is called every frame, and can also be called explicitly to flush
|
|
|
|
text to the screen.
|
|
|
|
|
|
|
|
WARNING: be very careful calling this from elsewhere, because the refresh
|
|
|
|
needs almost the entire 256k of stack space!
|
|
|
|
*/
|
2012-02-18 13:28:42 +00:00
|
|
|
void
|
2012-02-22 07:32:34 +00:00
|
|
|
gl_SCR_UpdateScreen (double realtime, SCR_Func scr_3dfunc, SCR_Func *scr_funcs)
|
2001-02-19 21:15:25 +00:00
|
|
|
{
|
|
|
|
double time1 = 0, time2;
|
2003-09-05 06:55:12 +00:00
|
|
|
static int begun = 0;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2004-02-15 03:40:50 +00:00
|
|
|
if (scr_skipupdate)
|
2001-02-19 21:15:25 +00:00
|
|
|
return;
|
|
|
|
|
2003-09-05 06:55:12 +00:00
|
|
|
if (begun)
|
2019-07-08 16:00:47 +00:00
|
|
|
gl_ctx->end_rendering ();
|
2002-02-27 05:22:21 +00:00
|
|
|
|
2012-02-14 08:28:09 +00:00
|
|
|
vr_data.realtime = realtime;
|
2001-05-20 03:54:55 +00:00
|
|
|
|
2001-02-19 21:15:25 +00:00
|
|
|
vid.numpages = 2 + gl_triplebuffer->int_val;
|
|
|
|
|
|
|
|
scr_copytop = 0;
|
2013-01-13 08:23:00 +00:00
|
|
|
vr_data.scr_copyeverything = 1;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2002-01-16 21:53:42 +00:00
|
|
|
if (!scr_initialized)
|
|
|
|
return; // not initialized yet
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2003-09-05 06:55:12 +00:00
|
|
|
begun = 1;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
if (r_speeds->int_val) {
|
|
|
|
time1 = Sys_DoubleTime ();
|
2012-02-22 07:32:34 +00:00
|
|
|
gl_c_brush_polys = 0;
|
|
|
|
gl_c_alias_polys = 0;
|
2001-02-19 21:15:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (oldfov != scr_fov->value) { // determine size of refresh window
|
|
|
|
oldfov = scr_fov->value;
|
|
|
|
vid.recalc_refdef = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (vid.recalc_refdef)
|
|
|
|
SCR_CalcRefdef ();
|
|
|
|
|
|
|
|
// do 3D refresh drawing, and then update the screen
|
2012-01-28 11:45:14 +00:00
|
|
|
scr_3dfunc ();
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2002-07-07 02:34:48 +00:00
|
|
|
SCR_SetUpToDrawConsole ();
|
2012-01-13 10:51:45 +00:00
|
|
|
GL_Set2D ();
|
2004-05-07 03:54:35 +00:00
|
|
|
GL_DrawReset ();
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
// draw any areas not covered by the refresh
|
|
|
|
SCR_TileClear ();
|
|
|
|
|
2009-12-23 06:29:11 +00:00
|
|
|
GL_Set2DScaled ();
|
|
|
|
|
2004-03-01 23:47:39 +00:00
|
|
|
while (*scr_funcs) {
|
|
|
|
(*scr_funcs)();
|
|
|
|
scr_funcs++;
|
2001-02-19 21:15:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (r_speeds->int_val) {
|
2002-06-13 22:51:43 +00:00
|
|
|
// qfglFinish ();
|
2001-02-19 21:15:25 +00:00
|
|
|
time2 = Sys_DoubleTime ();
|
2010-11-23 05:09:30 +00:00
|
|
|
Sys_MaskPrintf (SYS_DEV, "%3i ms %4i wpoly %4i epoly %4i parts\n",
|
2012-02-22 07:32:34 +00:00
|
|
|
(int) ((time2 - time1) * 1000), gl_c_brush_polys,
|
|
|
|
gl_c_alias_polys, numparticles);
|
2001-02-19 21:15:25 +00:00
|
|
|
}
|
|
|
|
|
2002-06-13 05:24:52 +00:00
|
|
|
GL_FlushText ();
|
2002-02-27 05:22:21 +00:00
|
|
|
qfglFlush ();
|
2004-07-10 02:32:30 +00:00
|
|
|
|
|
|
|
if (gl_finish->int_val) {
|
2019-07-08 16:00:47 +00:00
|
|
|
gl_ctx->end_rendering ();
|
2004-07-10 02:32:30 +00:00
|
|
|
begun = 0;
|
|
|
|
}
|
2001-02-19 21:15:25 +00:00
|
|
|
}
|