2002-12-11 17:34:48 +00:00
|
|
|
/*
|
|
|
|
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
|
|
|
|
2002-12-11 17:34:48 +00:00
|
|
|
#ifdef HAVE_STRING_H
|
|
|
|
# include <string.h>
|
|
|
|
#endif
|
|
|
|
#ifdef HAVE_STRINGS_H
|
|
|
|
# include <strings.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include "QF/cmd.h"
|
|
|
|
#include "QF/cvar.h"
|
|
|
|
#include "QF/draw.h"
|
2022-03-07 05:39:47 +00:00
|
|
|
#include "QF/dstring.h"
|
2003-09-04 18:59:39 +00:00
|
|
|
#include "QF/image.h"
|
2022-03-07 05:39:47 +00:00
|
|
|
#include "QF/png.h"
|
2002-12-11 17:34:48 +00:00
|
|
|
#include "QF/pcx.h"
|
2022-03-07 05:39:47 +00:00
|
|
|
#include "QF/quakefs.h"
|
2002-12-11 17:34:48 +00:00
|
|
|
#include "QF/render.h"
|
|
|
|
#include "QF/screen.h"
|
|
|
|
#include "QF/sys.h"
|
2022-03-07 05:39:47 +00:00
|
|
|
#include "QF/va.h"
|
2002-12-11 17:34:48 +00:00
|
|
|
|
2022-03-17 03:00:43 +00:00
|
|
|
#include "QF/scene/entity.h"
|
2022-02-28 07:59:38 +00:00
|
|
|
#include "QF/scene/transform.h"
|
2021-07-10 09:04:34 +00:00
|
|
|
#include "QF/ui/view.h"
|
|
|
|
|
2002-12-11 17:34:48 +00:00
|
|
|
#include "compat.h"
|
2012-02-14 08:28:09 +00:00
|
|
|
#include "r_internal.h"
|
2002-12-11 17:34:48 +00:00
|
|
|
#include "sbar.h"
|
|
|
|
|
2012-05-21 23:23:22 +00:00
|
|
|
// only the refresh window will be updated unless these variables are flagged
|
2002-12-11 17:34:48 +00:00
|
|
|
int scr_copytop;
|
2022-03-06 04:47:41 +00:00
|
|
|
byte *draw_chars; // 8*8 graphic characters FIXME location
|
2021-01-12 07:14:46 +00:00
|
|
|
qboolean r_cache_thrash; // set if surface cache is thrashing
|
|
|
|
|
2002-12-11 17:34:48 +00:00
|
|
|
qboolean scr_skipupdate;
|
2022-03-06 04:47:41 +00:00
|
|
|
static qboolean scr_initialized;// ready to draw
|
|
|
|
static qpic_t *scr_ram;
|
|
|
|
static qpic_t *scr_turtle;
|
2002-12-11 17:34:48 +00:00
|
|
|
|
2004-02-08 00:37:11 +00:00
|
|
|
void
|
2013-01-30 12:20:25 +00:00
|
|
|
R_SetVrect (const vrect_t *vrectin, vrect_t *vrect, int lineadj)
|
2004-02-08 00:37:11 +00:00
|
|
|
{
|
|
|
|
float size;
|
|
|
|
int h;
|
|
|
|
|
2013-01-13 07:53:22 +00:00
|
|
|
size = min (r_viewsize, 100);
|
2021-01-12 07:14:46 +00:00
|
|
|
if (r_data->force_fullscreen) {
|
2022-03-07 14:32:44 +00:00
|
|
|
// intermission is always full screen
|
2004-02-08 00:37:11 +00:00
|
|
|
size = 100.0;
|
|
|
|
lineadj = 0;
|
|
|
|
}
|
|
|
|
size /= 100.0;
|
|
|
|
|
2013-01-13 07:07:11 +00:00
|
|
|
h = vrectin->height - lineadj;
|
2004-02-08 00:37:11 +00:00
|
|
|
|
2013-01-13 07:07:11 +00:00
|
|
|
vrect->width = vrectin->width * size + 0.5;
|
|
|
|
if (vrect->width < 96) {
|
|
|
|
size = 96.0 / vrectin->width;
|
|
|
|
vrect->width = 96; // min for icons
|
2004-02-08 00:37:11 +00:00
|
|
|
}
|
2013-01-13 07:07:11 +00:00
|
|
|
vrect->width &= ~7;
|
2004-02-08 00:37:11 +00:00
|
|
|
|
2013-01-13 07:07:11 +00:00
|
|
|
vrect->height = vrectin->height * size + 0.5;
|
|
|
|
if (vrect->height > h)
|
|
|
|
vrect->height = h;
|
|
|
|
vrect->height &= ~1;
|
2004-02-08 00:37:11 +00:00
|
|
|
|
2013-01-13 07:07:11 +00:00
|
|
|
vrect->x = (vrectin->width - vrect->width) / 2;
|
|
|
|
vrect->y = (h - vrect->height) / 2;
|
2004-02-08 00:37:11 +00:00
|
|
|
}
|
|
|
|
|
2021-04-01 10:40:25 +00:00
|
|
|
static float __attribute__((pure))
|
|
|
|
CalcFov (float fov_x, float width, float height)
|
|
|
|
{
|
2022-03-18 02:03:37 +00:00
|
|
|
double f = fov_x * M_PI / 360;
|
|
|
|
double c = cos(f);
|
|
|
|
double s = sin(f);
|
2021-04-01 10:40:25 +00:00
|
|
|
|
2022-03-18 02:03:37 +00:00
|
|
|
return 360 * atan2 (s * height, c * width) / M_PI;
|
2021-04-01 10:40:25 +00:00
|
|
|
}
|
|
|
|
|
2022-03-05 05:35:56 +00:00
|
|
|
static void
|
2004-02-08 00:37:11 +00:00
|
|
|
SCR_CalcRefdef (void)
|
|
|
|
{
|
|
|
|
vrect_t vrect;
|
2012-02-14 08:28:09 +00:00
|
|
|
refdef_t *refdef = r_data->refdef;
|
2004-02-08 00:37:11 +00:00
|
|
|
|
|
|
|
// force a background redraw
|
2021-01-12 07:14:46 +00:00
|
|
|
r_data->scr_fullupdate = 0;
|
|
|
|
r_data->vid->recalc_refdef = 0;
|
2004-02-08 00:37:11 +00:00
|
|
|
|
|
|
|
vrect.x = 0;
|
|
|
|
vrect.y = 0;
|
2021-01-12 07:14:46 +00:00
|
|
|
vrect.width = r_data->vid->width;
|
|
|
|
vrect.height = r_data->vid->height;
|
2004-02-08 00:37:11 +00:00
|
|
|
|
2021-07-10 09:04:34 +00:00
|
|
|
R_SetVrect (&vrect, &refdef->vrect, r_data->lineadj);
|
2004-05-07 03:54:35 +00:00
|
|
|
|
2021-07-10 09:30:46 +00:00
|
|
|
view_setgeometry (r_data->scr_view, refdef->vrect.x, refdef->vrect.y,
|
2021-07-10 09:04:34 +00:00
|
|
|
refdef->vrect.width, refdef->vrect.height);
|
2004-02-08 00:37:11 +00:00
|
|
|
|
2021-07-15 12:23:06 +00:00
|
|
|
// bound field of view
|
2022-03-18 02:03:37 +00:00
|
|
|
Cvar_SetValue (scr_fov, bound (0, scr_fov->value, 170));
|
2021-07-15 12:23:06 +00:00
|
|
|
|
|
|
|
refdef->fov_y = CalcFov (refdef->fov_x, refdef->vrect.width,
|
|
|
|
refdef->vrect.height);
|
|
|
|
|
2004-02-08 00:37:11 +00:00
|
|
|
// notify the refresh of the change
|
2021-04-01 10:17:19 +00:00
|
|
|
r_funcs->R_ViewChanged ();
|
2004-02-08 00:37:11 +00:00
|
|
|
}
|
2002-12-11 17:34:48 +00:00
|
|
|
|
2021-01-11 07:57:31 +00:00
|
|
|
/*
|
|
|
|
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!
|
|
|
|
*/
|
|
|
|
void
|
2022-02-28 07:59:38 +00:00
|
|
|
SCR_UpdateScreen (transform_t *camera, double realtime, SCR_Func *scr_funcs)
|
2021-01-11 07:57:31 +00:00
|
|
|
{
|
|
|
|
if (scr_skipupdate || !scr_initialized) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2022-03-17 08:50:38 +00:00
|
|
|
if (r_timegraph->int_val || r_speeds->int_val || r_dspeeds->int_val) {
|
|
|
|
r_time1 = Sys_DoubleTime ();
|
|
|
|
}
|
|
|
|
|
2022-03-17 03:00:43 +00:00
|
|
|
refdef_t *refdef = r_data->refdef;
|
2022-02-28 07:59:38 +00:00
|
|
|
if (camera) {
|
2022-03-17 03:00:43 +00:00
|
|
|
Transform_GetWorldMatrix (camera, refdef->camera);
|
|
|
|
Transform_GetWorldInverse (camera, refdef->camera_inverse);
|
2022-02-28 07:59:38 +00:00
|
|
|
} else {
|
2022-03-17 03:00:43 +00:00
|
|
|
mat4fidentity (refdef->camera);
|
|
|
|
mat4fidentity (refdef->camera_inverse);
|
2022-02-28 07:59:38 +00:00
|
|
|
}
|
2022-03-17 03:00:43 +00:00
|
|
|
|
[renderer] Clean up use of vup/vright/vpn
This moves the common camera setup code out of the individual drivers,
and completely removes vup/vright/vpn from the non-software renderers.
This has highlighted the craziness around AngleVectors with it putting
+X forward, -Y right and +Z up. The main issue with this is it requires
a 90 degree pre-rotation about the Z axis to get the camera pointing in
the right direction, and that's for the native sw renderer (vulkan needs
a 90 degree pre-rotation about X, and gl and glsl need to invert an
axis, too), though at least it's just a matrix swizzle and vector
negation. However, it does mean the camera matrices can't be used
directly.
Also rename vpn to vfwd (still abbreviated, but fwd is much clearer in
meaning (to me, at least) than pn (plane normal, I guess, but which
way?)).
2022-03-14 00:34:24 +00:00
|
|
|
// FIXME pre-rotate the camera 90 degrees about the z axis such that the
|
|
|
|
// camera forward vector (camera Y) points along the world +X axis and the
|
|
|
|
// camera right vector (camera X) points along the world -Y axis. This
|
|
|
|
// should not be necessary here but is due to AngleVectors (and thus
|
|
|
|
// AngleQuat for compatibility) treating X as forward and Y as left (or -Y
|
|
|
|
// as right). Fixing this would take an audit of the usage of both, but is
|
|
|
|
// probably worthwhile in the long run.
|
2022-03-17 03:00:43 +00:00
|
|
|
refdef->frame.mat[0] = -refdef->camera[1];
|
|
|
|
refdef->frame.mat[1] = refdef->camera[0];
|
|
|
|
refdef->frame.mat[2] = refdef->camera[2];
|
|
|
|
refdef->frame.mat[3] = refdef->camera[3];
|
|
|
|
|
|
|
|
//FIXME breaks fisheye as it calls the view render many times
|
|
|
|
EntQueue_Clear (r_ent_queue);
|
|
|
|
r_framecount++;
|
|
|
|
R_SetFrustum ();
|
2022-02-28 07:59:38 +00:00
|
|
|
|
2021-01-12 07:14:46 +00:00
|
|
|
r_data->realtime = realtime;
|
|
|
|
scr_copytop = r_data->scr_copyeverything = 0;
|
2021-01-11 07:57:31 +00:00
|
|
|
|
2021-01-12 07:14:46 +00:00
|
|
|
if (r_data->vid->recalc_refdef) {
|
2021-01-11 07:57:31 +00:00
|
|
|
SCR_CalcRefdef ();
|
|
|
|
}
|
|
|
|
|
2022-03-17 08:50:38 +00:00
|
|
|
R_RunParticles (r_data->frametime);
|
2022-03-17 03:00:43 +00:00
|
|
|
R_AnimateLight ();
|
|
|
|
refdef->viewleaf = 0;
|
|
|
|
if (refdef->worldmodel) {
|
|
|
|
vec4f_t position = refdef->frame.position;
|
|
|
|
refdef->viewleaf = Mod_PointInLeaf (&position[0], refdef->worldmodel);
|
|
|
|
}
|
2022-03-17 08:50:38 +00:00
|
|
|
R_MarkLeaves ();
|
|
|
|
R_PushDlights (vec3_origin);
|
2022-03-17 03:00:43 +00:00
|
|
|
|
2022-03-07 14:32:44 +00:00
|
|
|
r_funcs->begin_frame ();
|
|
|
|
r_funcs->render_view ();
|
2022-03-17 08:50:38 +00:00
|
|
|
r_funcs->draw_entities (r_ent_queue);
|
|
|
|
r_funcs->draw_particles (&r_psystem);
|
2022-03-17 15:14:48 +00:00
|
|
|
r_funcs->draw_transparent ();
|
2022-03-15 06:42:43 +00:00
|
|
|
r_funcs->set_2d (0);
|
2022-03-08 21:55:31 +00:00
|
|
|
view_draw (r_data->scr_view);
|
2022-03-15 06:42:43 +00:00
|
|
|
r_funcs->set_2d (1);
|
2022-03-07 14:32:44 +00:00
|
|
|
while (*scr_funcs) {
|
2022-03-15 06:42:43 +00:00
|
|
|
(*scr_funcs) ();
|
2022-03-07 14:32:44 +00:00
|
|
|
scr_funcs++;
|
|
|
|
}
|
|
|
|
r_funcs->end_frame ();
|
2004-02-08 00:37:11 +00:00
|
|
|
}
|
2002-12-11 17:34:48 +00:00
|
|
|
|
2013-01-30 12:09:11 +00:00
|
|
|
void
|
|
|
|
SCR_SetFOV (float fov)
|
|
|
|
{
|
|
|
|
refdef_t *refdef = r_data->refdef;
|
|
|
|
refdef->fov_x = fov;
|
2021-03-25 13:01:31 +00:00
|
|
|
r_data->vid->recalc_refdef = 1;
|
2013-01-30 12:09:11 +00:00
|
|
|
}
|
|
|
|
|
2012-04-11 13:45:23 +00:00
|
|
|
static void
|
|
|
|
ScreenShot_f (void)
|
|
|
|
{
|
2022-03-07 05:39:47 +00:00
|
|
|
dstring_t *name = dstring_new ();
|
|
|
|
|
|
|
|
// find a file name to save it to
|
|
|
|
if (!QFS_NextFilename (name, va (0, "%s/qf",
|
|
|
|
qfs_gamedir->dir.shots), ".png")) {
|
|
|
|
Sys_Printf ("SCR_ScreenShot_f: Couldn't create a PNG file\n");
|
|
|
|
} else {
|
|
|
|
tex_t *tex;
|
|
|
|
|
|
|
|
tex = r_funcs->SCR_CaptureBGR ();
|
|
|
|
WritePNGqfs (name->str, tex->data, tex->width, tex->height);
|
|
|
|
free (tex);
|
|
|
|
Sys_Printf ("Wrote %s/%s\n", qfs_userpath, name->str);
|
|
|
|
}
|
|
|
|
dstring_delete (name);
|
2012-04-11 13:45:23 +00:00
|
|
|
}
|
|
|
|
|
2002-12-11 17:34:48 +00:00
|
|
|
/*
|
|
|
|
SCR_SizeUp_f
|
|
|
|
|
|
|
|
Keybinding command
|
|
|
|
*/
|
2003-01-06 18:28:13 +00:00
|
|
|
static void
|
2002-12-11 17:34:48 +00:00
|
|
|
SCR_SizeUp_f (void)
|
|
|
|
{
|
|
|
|
if (scr_viewsize->int_val < 120) {
|
|
|
|
Cvar_SetValue (scr_viewsize, scr_viewsize->int_val + 10);
|
2021-01-12 07:14:46 +00:00
|
|
|
r_data->vid->recalc_refdef = 1;
|
2002-12-11 17:34:48 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
SCR_SizeDown_f
|
|
|
|
|
|
|
|
Keybinding command
|
|
|
|
*/
|
2003-01-06 18:28:13 +00:00
|
|
|
static void
|
2002-12-11 17:34:48 +00:00
|
|
|
SCR_SizeDown_f (void)
|
|
|
|
{
|
|
|
|
Cvar_SetValue (scr_viewsize, scr_viewsize->int_val - 10);
|
2021-01-12 07:14:46 +00:00
|
|
|
r_data->vid->recalc_refdef = 1;
|
2002-12-11 17:34:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
SCR_DrawRam (void)
|
|
|
|
{
|
|
|
|
if (!scr_showram->int_val)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (!r_cache_thrash)
|
|
|
|
return;
|
|
|
|
|
2021-07-10 09:04:34 +00:00
|
|
|
//FIXME view
|
2021-07-10 09:30:46 +00:00
|
|
|
r_funcs->Draw_Pic (r_data->scr_view->xpos + 32, r_data->scr_view->ypos,
|
2021-07-10 09:04:34 +00:00
|
|
|
scr_ram);
|
2002-12-11 17:34:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
SCR_DrawTurtle (void)
|
|
|
|
{
|
|
|
|
static int count;
|
|
|
|
|
|
|
|
if (!scr_showturtle->int_val)
|
|
|
|
return;
|
|
|
|
|
2021-01-12 07:14:46 +00:00
|
|
|
if (r_data->frametime < 0.1) {
|
2002-12-11 17:34:48 +00:00
|
|
|
count = 0;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
count++;
|
|
|
|
if (count < 3)
|
|
|
|
return;
|
|
|
|
|
2021-07-10 09:04:34 +00:00
|
|
|
//FIXME view
|
2021-07-10 09:30:46 +00:00
|
|
|
r_funcs->Draw_Pic (r_data->scr_view->xpos, r_data->scr_view->ypos,
|
2021-07-10 09:04:34 +00:00
|
|
|
scr_turtle);
|
2002-12-11 17:34:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
SCR_DrawPause (void)
|
|
|
|
{
|
|
|
|
qpic_t *pic;
|
|
|
|
|
|
|
|
if (!scr_showpause->int_val) // turn off for screenshots
|
|
|
|
return;
|
|
|
|
|
2021-01-12 07:14:46 +00:00
|
|
|
if (!r_data->paused)
|
2002-12-11 17:34:48 +00:00
|
|
|
return;
|
|
|
|
|
2021-07-10 09:04:34 +00:00
|
|
|
//FIXME view conwidth
|
2021-01-12 07:14:46 +00:00
|
|
|
pic = r_funcs->Draw_CachePic ("gfx/pause.lmp", true);
|
2021-07-10 09:04:34 +00:00
|
|
|
r_funcs->Draw_Pic ((r_data->vid->conview->xlen - pic->width) / 2,
|
|
|
|
(r_data->vid->conview->ylen - 48 - pic->height) / 2,
|
|
|
|
pic);
|
2002-12-11 17:34:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
Find closest color in the palette for named color
|
|
|
|
*/
|
2022-03-07 14:32:44 +00:00
|
|
|
static int
|
2002-12-11 17:34:48 +00:00
|
|
|
MipColor (int r, int g, int b)
|
|
|
|
{
|
|
|
|
float bestdist, dist;
|
|
|
|
int r1, g1, b1, i;
|
|
|
|
int best = 0;
|
|
|
|
static int lastbest;
|
|
|
|
static int lr = -1, lg = -1, lb = -1;
|
|
|
|
|
|
|
|
if (r == lr && g == lg && b == lb)
|
|
|
|
return lastbest;
|
|
|
|
|
|
|
|
bestdist = 256 * 256 * 3;
|
|
|
|
|
|
|
|
for (i = 0; i < 256; i++) {
|
|
|
|
int j;
|
|
|
|
j = i * 3;
|
2021-01-12 07:14:46 +00:00
|
|
|
r1 = r_data->vid->palette[j] - r;
|
|
|
|
g1 = r_data->vid->palette[j + 1] - g;
|
|
|
|
b1 = r_data->vid->palette[j + 2] - b;
|
2002-12-11 17:34:48 +00:00
|
|
|
dist = r1 * r1 + g1 * g1 + b1 * b1;
|
|
|
|
if (dist < bestdist) {
|
|
|
|
bestdist = dist;
|
|
|
|
best = i;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
lr = r;
|
|
|
|
lg = g;
|
|
|
|
lb = b;
|
|
|
|
lastbest = best;
|
|
|
|
return best;
|
|
|
|
}
|
|
|
|
|
|
|
|
// in draw.c
|
|
|
|
|
2003-01-06 18:28:13 +00:00
|
|
|
static void
|
2006-12-03 06:25:57 +00:00
|
|
|
SCR_DrawCharToSnap (int num, byte *dest, int width)
|
2002-12-11 17:34:48 +00:00
|
|
|
{
|
|
|
|
byte *source;
|
|
|
|
int col, row, drawline, x;
|
|
|
|
|
|
|
|
row = num >> 4;
|
|
|
|
col = num & 15;
|
|
|
|
source = draw_chars + (row << 10) + (col << 3);
|
|
|
|
|
|
|
|
drawline = 8;
|
|
|
|
|
|
|
|
while (drawline--) {
|
|
|
|
for (x = 0; x < 8; x++)
|
|
|
|
if (source[x])
|
|
|
|
dest[x] = source[x];
|
|
|
|
else
|
|
|
|
dest[x] = 98;
|
|
|
|
source += 128;
|
|
|
|
dest -= width;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
SCR_DrawStringToSnap (const char *s, tex_t *tex, int x, int y)
|
|
|
|
{
|
|
|
|
byte *dest;
|
|
|
|
byte *buf = tex->data;
|
|
|
|
const unsigned char *p;
|
|
|
|
int width = tex->width;
|
|
|
|
|
|
|
|
dest = buf + ((y * width) + x);
|
|
|
|
|
|
|
|
p = (const unsigned char *) s;
|
|
|
|
while (*p) {
|
|
|
|
SCR_DrawCharToSnap (*p++, dest, width);
|
|
|
|
dest += 8;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-03-07 05:39:47 +00:00
|
|
|
tex_t *
|
|
|
|
SCR_SnapScreen (unsigned width, unsigned height)
|
|
|
|
{
|
|
|
|
byte *src, *dest;
|
|
|
|
float fracw, frach;
|
|
|
|
unsigned count, dex, dey, dx, dy, nx, r, g, b, x, y, w, h;
|
|
|
|
tex_t *tex;
|
|
|
|
|
|
|
|
tex_t *snap = r_funcs->SCR_CaptureBGR ();
|
|
|
|
|
|
|
|
//FIXME casts
|
|
|
|
w = ((unsigned)snap->width < width) ? (unsigned)snap->width : width;
|
|
|
|
h = ((unsigned)snap->height < height) ? (unsigned)snap->height : height;
|
|
|
|
|
|
|
|
fracw = (float) snap->width / (float) w;
|
|
|
|
frach = (float) snap->height / (float) h;
|
|
|
|
|
|
|
|
tex = malloc (sizeof (tex_t) + w * h);
|
|
|
|
tex->data = (byte *) (tex + 1);
|
|
|
|
if (!tex)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
tex->width = w;
|
|
|
|
tex->height = h;
|
|
|
|
tex->palette = r_data->vid->palette;
|
|
|
|
|
|
|
|
for (y = 0; y < h; y++) {
|
|
|
|
dest = tex->data + (w * y);
|
|
|
|
|
|
|
|
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;
|
|
|
|
for (; dy < dey; dy++) {
|
|
|
|
src = snap->data + (snap->width * 3 * dy) + dx * 3;
|
|
|
|
for (nx = dx; nx < dex; nx++) {
|
|
|
|
b += *src++;
|
|
|
|
g += *src++;
|
|
|
|
r += *src++;
|
|
|
|
count++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
r /= count;
|
|
|
|
g /= count;
|
|
|
|
b /= count;
|
|
|
|
*dest++ = MipColor (r, g, b);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
free (snap);
|
|
|
|
|
|
|
|
return tex;
|
|
|
|
}
|
|
|
|
|
2002-12-11 17:34:48 +00:00
|
|
|
void
|
|
|
|
SCR_Init (void)
|
|
|
|
{
|
|
|
|
// register our commands
|
2012-04-11 13:45:23 +00:00
|
|
|
Cmd_AddCommand ("screenshot", ScreenShot_f, "Take a screenshot, "
|
2022-03-07 05:39:47 +00:00
|
|
|
"saves as qfxxxx.png in the QF directory");
|
2002-12-11 17:34:48 +00:00
|
|
|
Cmd_AddCommand ("sizeup", SCR_SizeUp_f, "Increases the screen size");
|
|
|
|
Cmd_AddCommand ("sizedown", SCR_SizeDown_f, "Decreases the screen size");
|
|
|
|
|
2021-01-12 07:14:46 +00:00
|
|
|
scr_ram = r_funcs->Draw_PicFromWad ("ram");
|
|
|
|
scr_turtle = r_funcs->Draw_PicFromWad ("turtle");
|
2002-12-11 17:34:48 +00:00
|
|
|
|
|
|
|
scr_initialized = true;
|
2022-03-17 08:50:38 +00:00
|
|
|
|
|
|
|
r_ent_queue = EntQueue_New (mod_num_types);
|
2002-12-11 17:34:48 +00:00
|
|
|
}
|