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
|
|
|
|
|
|
|
static __attribute__ ((unused)) const char rcsid[] =
|
|
|
|
"$Id$";
|
|
|
|
|
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-03-27 20:33:07 +00:00
|
|
|
#include "QF/console.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"
|
|
|
|
#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"
|
2001-05-11 19:21:48 +00:00
|
|
|
#include "r_cvar.h"
|
2002-10-02 04:15:23 +00:00
|
|
|
#include "r_dynamic.h"
|
2001-05-23 06:33:23 +00:00
|
|
|
#include "r_local.h"
|
2002-12-11 17:34:48 +00:00
|
|
|
#include "r_screen.h"
|
2001-02-19 21:15:25 +00:00
|
|
|
#include "sbar.h"
|
|
|
|
#include "view.h"
|
|
|
|
|
|
|
|
int glx, gly, glwidth, glheight;
|
|
|
|
|
|
|
|
/*
|
|
|
|
SCR_CalcRefdef
|
|
|
|
|
|
|
|
Must be called whenever vid changes
|
|
|
|
Internal use only
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
SCR_CalcRefdef (void)
|
|
|
|
{
|
|
|
|
float size;
|
2003-02-11 21:24:27 +00:00
|
|
|
int h, lines;
|
2001-02-19 21:15:25 +00:00
|
|
|
qboolean full = false;
|
|
|
|
|
|
|
|
scr_fullupdate = 0; // force a background redraw
|
|
|
|
vid.recalc_refdef = 0;
|
|
|
|
|
|
|
|
// force the status bar to redraw
|
|
|
|
Sbar_Changed ();
|
|
|
|
|
|
|
|
// bound field of view
|
2002-04-28 08:30:54 +00:00
|
|
|
Cvar_SetValue (scr_fov, bound (1, scr_fov->value, 170));
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2003-02-11 21:24:27 +00:00
|
|
|
if (r_viewsize >= 100) {
|
2001-02-19 21:15:25 +00:00
|
|
|
full = true;
|
|
|
|
size = 100.0;
|
|
|
|
} else {
|
2003-02-11 21:24:27 +00:00
|
|
|
size = r_viewsize;
|
2001-02-19 21:15:25 +00:00
|
|
|
}
|
|
|
|
// intermission is always full screen
|
2003-02-11 21:24:27 +00:00
|
|
|
lines = r_lineadj;
|
2001-09-09 21:41:35 +00:00
|
|
|
if (r_force_fullscreen /* FIXME: better test */) {
|
2001-02-19 21:15:25 +00:00
|
|
|
full = true;
|
|
|
|
size = 100.0;
|
2003-02-11 21:24:27 +00:00
|
|
|
lines = 0;
|
2001-02-19 21:15:25 +00:00
|
|
|
}
|
|
|
|
size /= 100.0;
|
|
|
|
|
2003-02-11 21:24:27 +00:00
|
|
|
h = vid.height - lines;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
r_refdef.vrect.width = vid.width * size + 0.5;
|
|
|
|
if (r_refdef.vrect.width < 96) {
|
|
|
|
size = 96.0 / r_refdef.vrect.width;
|
|
|
|
r_refdef.vrect.width = 96; // min for icons
|
|
|
|
}
|
|
|
|
|
|
|
|
r_refdef.vrect.height = vid.height * size + 0.5;
|
2002-12-11 16:45:40 +00:00
|
|
|
if (r_refdef.vrect.height > h)
|
|
|
|
r_refdef.vrect.height = h;
|
2001-02-19 21:15:25 +00:00
|
|
|
r_refdef.vrect.x = (vid.width - r_refdef.vrect.width) / 2;
|
|
|
|
if (full)
|
|
|
|
r_refdef.vrect.y = 0;
|
|
|
|
else
|
|
|
|
r_refdef.vrect.y = (h - r_refdef.vrect.height) / 2;
|
|
|
|
|
2002-04-28 08:30:54 +00:00
|
|
|
r_refdef.fov_x = scr_fov->value;
|
2001-02-19 21:15:25 +00:00
|
|
|
r_refdef.fov_y =
|
|
|
|
CalcFov (r_refdef.fov_x, r_refdef.vrect.width, r_refdef.vrect.height);
|
|
|
|
|
|
|
|
scr_vrect = r_refdef.vrect;
|
|
|
|
}
|
|
|
|
|
2001-09-09 21:41:35 +00:00
|
|
|
/* SCREEN SHOTS */
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-05-23 06:33:23 +00:00
|
|
|
tex_t *
|
|
|
|
SCR_ScreenShot (int width, int height)
|
|
|
|
{
|
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
|
|
|
|
2003-04-17 00:01:48 +00:00
|
|
|
w = (vid.width < (unsigned int) width) ? vid.width
|
|
|
|
: (unsigned int) width;
|
|
|
|
h = (vid.height < (unsigned int) height) ? vid.height
|
|
|
|
: (unsigned int) 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
|
|
|
|
SCR_ScreenShot_f (void)
|
|
|
|
{
|
|
|
|
byte *buffer;
|
2003-05-23 17:17:01 +00:00
|
|
|
dstring_t *pcxname = dstring_new ();
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
// find a file name to save it to
|
2003-05-23 17:17:01 +00:00
|
|
|
if (!QFS_NextFilename (pcxname,
|
|
|
|
va ("%s/qf", qfs_gamedir->dir.def), ".tga")) {
|
2001-02-19 21:15:25 +00:00
|
|
|
Con_Printf ("SCR_ScreenShot_f: Couldn't create a TGA file\n");
|
2003-05-23 17:17:01 +00:00
|
|
|
} else {
|
|
|
|
buffer = malloc (glwidth * glheight * 3);
|
|
|
|
SYS_CHECKMEM (buffer);
|
|
|
|
qfglReadPixels (glx, gly, glwidth, glheight, GL_BGR_EXT,
|
|
|
|
GL_UNSIGNED_BYTE, buffer);
|
|
|
|
WriteTGAfile (pcxname->str, buffer, glwidth, glheight);
|
|
|
|
free (buffer);
|
|
|
|
Con_Printf ("Wrote %s\n", 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
|
2003-02-11 21:24:27 +00:00
|
|
|
Draw_TileClear (0, 0, r_refdef.vrect.x, vid.height - r_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,
|
2003-02-11 21:24:27 +00:00
|
|
|
vid.height - r_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,
|
2003-02-11 21:24:27 +00:00
|
|
|
vid.height - r_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!
|
|
|
|
*/
|
|
|
|
void
|
2001-12-09 14:05:30 +00:00
|
|
|
SCR_UpdateScreen (double realtime, 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
|
|
|
|
|
|
|
if (block_drawing)
|
|
|
|
return;
|
|
|
|
|
2003-09-05 06:55:12 +00:00
|
|
|
if (begun)
|
|
|
|
GL_EndRendering ();
|
2002-02-27 05:22:21 +00:00
|
|
|
|
2001-05-20 03:54:55 +00:00
|
|
|
r_realtime = realtime;
|
|
|
|
|
2001-02-19 21:15:25 +00:00
|
|
|
vid.numpages = 2 + gl_triplebuffer->int_val;
|
|
|
|
|
|
|
|
scr_copytop = 0;
|
|
|
|
scr_copyeverything = 0;
|
|
|
|
|
2002-01-16 21:53:42 +00:00
|
|
|
if (!scr_initialized)
|
|
|
|
return; // not initialized yet
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
GL_BeginRendering (&glx, &gly, &glwidth, &glheight);
|
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 ();
|
|
|
|
c_brush_polys = 0;
|
|
|
|
c_alias_polys = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
|
V_RenderView ();
|
|
|
|
|
2002-07-07 02:34:48 +00:00
|
|
|
SCR_SetUpToDrawConsole ();
|
2001-02-19 21:15:25 +00:00
|
|
|
GL_Set2D ();
|
|
|
|
|
2001-11-03 07:50:57 +00:00
|
|
|
// also makes polyblend apply to whole screen
|
|
|
|
if (v_blend[3]) {
|
2002-06-13 22:51:43 +00:00
|
|
|
qfglDisable (GL_TEXTURE_2D);
|
2001-11-03 07:50:57 +00:00
|
|
|
qfglBegin (GL_QUADS);
|
|
|
|
|
|
|
|
qfglColor4fv (v_blend);
|
|
|
|
qfglVertex2f (0, 0);
|
|
|
|
qfglVertex2f (vid.width, 0);
|
|
|
|
qfglVertex2f (vid.width, vid.height);
|
|
|
|
qfglVertex2f (0, vid.height);
|
|
|
|
|
|
|
|
qfglEnd ();
|
|
|
|
qfglColor3ubv (color_white);
|
2002-06-13 22:51:43 +00:00
|
|
|
qfglEnable (GL_TEXTURE_2D);
|
2001-11-03 07:50:57 +00:00
|
|
|
}
|
|
|
|
|
2001-02-19 21:15:25 +00:00
|
|
|
// draw any areas not covered by the refresh
|
|
|
|
SCR_TileClear ();
|
|
|
|
|
2001-08-22 11:00:25 +00:00
|
|
|
if (r_force_fullscreen /*FIXME better test*/ == 1 && key_dest ==
|
|
|
|
key_game) {
|
2001-02-19 21:15:25 +00:00
|
|
|
Sbar_IntermissionOverlay ();
|
2001-08-22 11:00:25 +00:00
|
|
|
} else if (r_force_fullscreen /*FIXME better test*/ == 2 &&
|
|
|
|
key_dest == key_game) {
|
2001-02-19 21:15:25 +00:00
|
|
|
Sbar_FinaleOverlay ();
|
2001-12-09 14:05:30 +00:00
|
|
|
SCR_CheckDrawCenterString ();
|
2001-02-19 21:15:25 +00:00
|
|
|
} else {
|
2001-05-23 06:33:23 +00:00
|
|
|
while (*scr_funcs) {
|
2001-12-09 14:05:30 +00:00
|
|
|
(*scr_funcs)();
|
2001-05-23 06:33:23 +00:00
|
|
|
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 ();
|
2002-10-02 04:15:23 +00:00
|
|
|
Con_Printf ("%3i ms %4i wpoly %4i epoly %4i parts\n",
|
2001-02-19 21:15:25 +00:00
|
|
|
(int) ((time2 - time1) * 1000), c_brush_polys,
|
2002-10-02 04:15:23 +00:00
|
|
|
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 ();
|
2001-02-19 21:15:25 +00:00
|
|
|
}
|