2000-05-10 20:33:16 +00:00
|
|
|
/*
|
2000-05-14 18:06:53 +00:00
|
|
|
vid_glx.c
|
2000-05-10 20:33:16 +00:00
|
|
|
|
2000-05-17 18:28:13 +00:00
|
|
|
OpenGL GLX video driver
|
2000-05-10 20:33:16 +00:00
|
|
|
|
2000-05-11 16:03:29 +00:00
|
|
|
Copyright (C) 1996-1997 Id Software, Inc.
|
2000-05-23 06:36:33 +00:00
|
|
|
Copyright (C) 2000 Marcus Sundberg [mackan@stacken.kth.se]
|
2000-05-10 20:33:16 +00:00
|
|
|
|
2000-05-11 16:03:29 +00:00
|
|
|
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.
|
2000-05-10 20:33:16 +00:00
|
|
|
|
2000-05-11 16:03:29 +00:00
|
|
|
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.
|
2000-05-10 20:33:16 +00:00
|
|
|
|
2000-05-11 16:03:29 +00:00
|
|
|
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
|
|
|
|
|
|
|
|
$Id$
|
2000-05-10 20:33:16 +00:00
|
|
|
*/
|
2000-05-11 16:03:29 +00:00
|
|
|
|
2000-07-11 05:05:27 +00:00
|
|
|
#ifdef HAVE_CONFIG_H
|
2000-10-28 05:05:17 +00:00
|
|
|
# include "config.h"
|
2000-07-11 05:05:27 +00:00
|
|
|
#endif
|
2000-12-30 02:16:36 +00:00
|
|
|
#ifdef HAVE_STRING_H
|
2000-12-30 18:26:29 +00:00
|
|
|
# include <string.h>
|
2000-12-30 02:16:36 +00:00
|
|
|
#endif
|
|
|
|
#ifdef HAVE_STRINGS_H
|
2000-12-30 18:26:29 +00:00
|
|
|
# include <strings.h>
|
2000-12-30 02:16:36 +00:00
|
|
|
#endif
|
2000-05-23 06:36:33 +00:00
|
|
|
|
2000-05-10 11:29:38 +00:00
|
|
|
#include <GL/glx.h>
|
|
|
|
|
|
|
|
#include <X11/keysym.h>
|
|
|
|
#include <X11/cursorfont.h>
|
|
|
|
|
2000-05-23 16:57:12 +00:00
|
|
|
#ifdef HAVE_DGA
|
2000-05-23 06:36:33 +00:00
|
|
|
# include <X11/extensions/xf86dga.h>
|
2000-05-10 11:29:38 +00:00
|
|
|
#endif
|
|
|
|
|
2000-07-11 05:05:27 +00:00
|
|
|
#include "console.h"
|
2000-12-05 06:33:44 +00:00
|
|
|
#include "context_x11.h"
|
2000-10-26 06:08:09 +00:00
|
|
|
#include "glquake.h"
|
2000-12-05 06:33:44 +00:00
|
|
|
#include "host.h"
|
2000-09-24 03:43:06 +00:00
|
|
|
#include "input.h"
|
2000-10-26 06:08:09 +00:00
|
|
|
#include "qargs.h"
|
2000-12-05 06:33:44 +00:00
|
|
|
#include "qendian.h"
|
|
|
|
#include "quakefs.h"
|
|
|
|
#include "sbar.h"
|
|
|
|
#include "va.h"
|
2000-07-11 05:05:27 +00:00
|
|
|
|
2000-10-28 05:05:17 +00:00
|
|
|
#define WARP_WIDTH 320
|
|
|
|
#define WARP_HEIGHT 200
|
2000-05-10 11:29:38 +00:00
|
|
|
|
2000-12-08 06:51:37 +00:00
|
|
|
static qboolean vid_initialized = false;
|
2000-05-10 11:29:38 +00:00
|
|
|
|
2000-12-08 06:51:37 +00:00
|
|
|
static GLXContext ctx = NULL;
|
2000-05-10 11:29:38 +00:00
|
|
|
|
2000-10-28 05:05:17 +00:00
|
|
|
extern void GL_Init_Common (void);
|
|
|
|
extern void VID_Init8bitPalette (void);
|
2000-12-08 06:51:37 +00:00
|
|
|
|
2000-05-10 11:29:38 +00:00
|
|
|
/*-----------------------------------------------------------------------*/
|
|
|
|
|
|
|
|
const char *gl_vendor;
|
|
|
|
const char *gl_renderer;
|
|
|
|
const char *gl_version;
|
|
|
|
const char *gl_extensions;
|
|
|
|
|
2000-05-23 06:36:33 +00:00
|
|
|
void
|
2000-10-28 05:05:17 +00:00
|
|
|
VID_Shutdown (void)
|
2000-05-10 11:29:38 +00:00
|
|
|
{
|
2000-05-23 06:36:33 +00:00
|
|
|
if (!vid_initialized)
|
2000-05-10 11:29:38 +00:00
|
|
|
return;
|
|
|
|
|
2000-10-28 05:05:17 +00:00
|
|
|
Con_Printf ("VID_Shutdown\n");
|
2000-05-10 11:29:38 +00:00
|
|
|
|
2001-04-23 03:52:20 +00:00
|
|
|
X11_RestoreVidMode ();
|
|
|
|
X11_CloseDisplay ();
|
2000-05-10 11:29:38 +00:00
|
|
|
}
|
2000-10-26 06:08:09 +00:00
|
|
|
|
2000-06-29 09:21:23 +00:00
|
|
|
#if 0
|
2000-05-23 06:36:33 +00:00
|
|
|
static void
|
2000-10-28 05:05:17 +00:00
|
|
|
signal_handler (int sig)
|
2000-05-10 11:29:38 +00:00
|
|
|
{
|
2000-10-28 05:05:17 +00:00
|
|
|
printf ("Received signal %d, exiting...\n", sig);
|
|
|
|
Sys_Quit ();
|
|
|
|
exit (sig);
|
2000-05-10 11:29:38 +00:00
|
|
|
}
|
|
|
|
|
2000-05-23 06:36:33 +00:00
|
|
|
static void
|
2000-10-28 05:05:17 +00:00
|
|
|
InitSig (void)
|
2000-05-10 11:29:38 +00:00
|
|
|
{
|
2000-10-28 05:05:17 +00:00
|
|
|
signal (SIGHUP, signal_handler);
|
|
|
|
signal (SIGINT, signal_handler);
|
|
|
|
signal (SIGQUIT, signal_handler);
|
|
|
|
signal (SIGILL, signal_handler);
|
|
|
|
signal (SIGTRAP, signal_handler);
|
|
|
|
signal (SIGIOT, signal_handler);
|
|
|
|
signal (SIGBUS, signal_handler);
|
|
|
|
/* signal (SIGFPE, signal_handler); */
|
|
|
|
signal (SIGSEGV, signal_handler);
|
|
|
|
signal (SIGTERM, signal_handler);
|
2000-05-10 11:29:38 +00:00
|
|
|
}
|
2000-06-29 09:21:23 +00:00
|
|
|
#endif
|
2000-05-23 06:36:33 +00:00
|
|
|
|
2000-05-10 11:29:38 +00:00
|
|
|
/*
|
2001-02-09 02:53:09 +00:00
|
|
|
GL_Init
|
2000-05-10 11:29:38 +00:00
|
|
|
*/
|
2000-10-26 06:08:09 +00:00
|
|
|
void
|
|
|
|
GL_Init (void)
|
2000-05-10 11:29:38 +00:00
|
|
|
{
|
2000-10-28 05:05:17 +00:00
|
|
|
GL_Init_Common ();
|
2000-05-10 11:29:38 +00:00
|
|
|
}
|
|
|
|
|
2000-10-26 06:08:09 +00:00
|
|
|
void
|
|
|
|
GL_EndRendering (void)
|
2000-05-10 11:29:38 +00:00
|
|
|
{
|
2000-10-28 05:05:17 +00:00
|
|
|
glFlush ();
|
|
|
|
glXSwapBuffers (x_disp, x_win);
|
2000-06-04 13:53:29 +00:00
|
|
|
Sbar_Changed ();
|
2000-05-10 11:29:38 +00:00
|
|
|
}
|
|
|
|
|
2000-10-26 06:08:09 +00:00
|
|
|
void
|
2000-10-28 05:05:17 +00:00
|
|
|
VID_Init (unsigned char *palette)
|
2000-05-10 11:29:38 +00:00
|
|
|
{
|
2000-12-08 06:51:37 +00:00
|
|
|
int i;
|
|
|
|
int attrib[] = {
|
2000-05-10 11:29:38 +00:00
|
|
|
GLX_RGBA,
|
|
|
|
GLX_RED_SIZE, 1,
|
|
|
|
GLX_GREEN_SIZE, 1,
|
|
|
|
GLX_BLUE_SIZE, 1,
|
|
|
|
GLX_DOUBLEBUFFER,
|
|
|
|
GLX_DEPTH_SIZE, 1,
|
|
|
|
None
|
|
|
|
};
|
|
|
|
|
2000-10-21 07:15:30 +00:00
|
|
|
VID_GetWindowSize (640, 480);
|
2001-01-09 00:03:08 +00:00
|
|
|
Con_CheckResize (); // Now that we have a window size, fix console
|
|
|
|
|
2000-05-10 11:29:38 +00:00
|
|
|
vid.maxwarpwidth = WARP_WIDTH;
|
|
|
|
vid.maxwarpheight = WARP_HEIGHT;
|
|
|
|
vid.colormap = host_colormap;
|
2000-10-28 05:05:17 +00:00
|
|
|
vid.fullbright = 256 - LittleLong (*((int *) vid.colormap + 2048));
|
2000-05-10 11:29:38 +00:00
|
|
|
|
2000-12-08 06:51:37 +00:00
|
|
|
/* Interpret command-line params */
|
2000-05-10 11:29:38 +00:00
|
|
|
|
2000-05-23 06:36:33 +00:00
|
|
|
/* Set vid parameters */
|
2000-05-10 11:29:38 +00:00
|
|
|
|
2000-10-28 05:05:17 +00:00
|
|
|
if ((i = COM_CheckParm ("-conwidth")))
|
2000-12-08 06:51:37 +00:00
|
|
|
vid.conwidth = atoi (com_argv[i + 1]);
|
2000-05-10 11:29:38 +00:00
|
|
|
else
|
2000-10-21 07:15:30 +00:00
|
|
|
vid.conwidth = scr_width;
|
2000-05-10 11:29:38 +00:00
|
|
|
|
2000-12-08 06:51:37 +00:00
|
|
|
vid.conwidth &= 0xfff8; // make it a multiple of eight
|
2000-10-28 05:05:17 +00:00
|
|
|
vid.conwidth = max (vid.conwidth, 320);
|
2000-05-10 11:29:38 +00:00
|
|
|
|
|
|
|
// pick a conheight that matches with correct aspect
|
2000-05-23 06:36:33 +00:00
|
|
|
vid.conheight = vid.conwidth * 3 / 4;
|
2000-05-10 11:29:38 +00:00
|
|
|
|
2000-12-08 06:51:37 +00:00
|
|
|
if ((i = COM_CheckParm ("-conheight"))) // conheight no smaller than
|
|
|
|
// 200px
|
|
|
|
vid.conheight = atoi (com_argv[i + 1]);
|
2000-10-28 05:05:17 +00:00
|
|
|
vid.conheight = max (vid.conheight, 200);
|
2000-05-10 11:29:38 +00:00
|
|
|
|
2001-04-23 03:52:20 +00:00
|
|
|
X11_OpenDisplay ();
|
2000-05-10 11:29:38 +00:00
|
|
|
|
2000-10-28 05:05:17 +00:00
|
|
|
x_visinfo = glXChooseVisual (x_disp, x_screen, attrib);
|
2000-09-24 03:43:06 +00:00
|
|
|
if (!x_visinfo) {
|
2000-12-08 06:51:37 +00:00
|
|
|
fprintf (stderr,
|
|
|
|
"Error couldn't get an RGB, Double-buffered, Depth visual\n");
|
2000-10-28 05:05:17 +00:00
|
|
|
exit (1);
|
2000-05-10 11:29:38 +00:00
|
|
|
}
|
2000-09-24 03:43:06 +00:00
|
|
|
x_vis = x_visinfo->visual;
|
2000-05-23 06:36:33 +00:00
|
|
|
|
2001-04-23 03:52:20 +00:00
|
|
|
X11_SetVidMode (scr_width, scr_height);
|
|
|
|
X11_CreateWindow (scr_width, scr_height);
|
2000-07-27 03:37:41 +00:00
|
|
|
/* Invisible cursor */
|
2001-04-23 03:52:20 +00:00
|
|
|
X11_CreateNullCursor ();
|
2000-07-27 03:37:41 +00:00
|
|
|
|
2001-04-23 03:52:20 +00:00
|
|
|
X11_GrabKeyboard ();
|
2000-05-10 11:29:38 +00:00
|
|
|
|
2000-10-28 05:05:17 +00:00
|
|
|
XSync (x_disp, 0);
|
2000-05-10 11:29:38 +00:00
|
|
|
|
2000-10-28 05:05:17 +00:00
|
|
|
ctx = glXCreateContext (x_disp, x_visinfo, NULL, True);
|
2000-05-10 11:29:38 +00:00
|
|
|
|
2000-10-28 05:05:17 +00:00
|
|
|
glXMakeCurrent (x_disp, x_win, ctx);
|
2000-05-10 11:29:38 +00:00
|
|
|
|
2000-10-28 05:05:17 +00:00
|
|
|
vid.height = vid.conheight = min (vid.conheight, scr_height);
|
|
|
|
vid.width = vid.conwidth = min (vid.conwidth, scr_width);
|
2000-05-10 11:29:38 +00:00
|
|
|
|
2000-10-28 05:05:17 +00:00
|
|
|
vid.aspect = ((float) vid.height / (float) vid.width) * (320.0 / 240.0);
|
2000-05-10 11:29:38 +00:00
|
|
|
vid.numpages = 2;
|
|
|
|
|
2000-12-08 06:51:37 +00:00
|
|
|
// InitSig (); // trap evil signals
|
2000-05-10 11:29:38 +00:00
|
|
|
|
2000-10-28 05:05:17 +00:00
|
|
|
GL_Init ();
|
2000-05-10 11:29:38 +00:00
|
|
|
|
2001-04-23 04:16:17 +00:00
|
|
|
VID_InitGamma (palette);
|
2000-05-31 17:46:59 +00:00
|
|
|
VID_SetPalette (palette);
|
2000-05-10 11:29:38 +00:00
|
|
|
|
2000-10-28 05:05:17 +00:00
|
|
|
// Check for 8-bit extension and initialize if present
|
|
|
|
VID_Init8bitPalette ();
|
2000-05-10 11:29:38 +00:00
|
|
|
|
2000-10-28 05:05:17 +00:00
|
|
|
Con_Printf ("Video mode %dx%d initialized.\n", scr_width, scr_height);
|
2000-05-10 11:29:38 +00:00
|
|
|
|
2000-05-23 06:36:33 +00:00
|
|
|
vid_initialized = true;
|
2000-05-10 11:29:38 +00:00
|
|
|
|
2000-12-08 06:51:37 +00:00
|
|
|
vid.recalc_refdef = 1; // force a surface cache flush
|
2000-05-10 11:29:38 +00:00
|
|
|
}
|
|
|
|
|
2000-10-29 15:35:24 +00:00
|
|
|
void
|
|
|
|
VID_Init_Cvars ()
|
|
|
|
{
|
2001-04-23 03:52:20 +00:00
|
|
|
X11_Init_Cvars ();
|
2000-10-29 15:35:24 +00:00
|
|
|
}
|
|
|
|
|
2000-10-03 07:10:48 +00:00
|
|
|
void
|
|
|
|
VID_SetCaption (char *text)
|
2000-07-14 16:09:35 +00:00
|
|
|
{
|
2000-10-04 05:45:48 +00:00
|
|
|
if (text && *text) {
|
2000-12-08 06:51:37 +00:00
|
|
|
char *temp = strdup (text);
|
|
|
|
|
2001-04-23 03:52:20 +00:00
|
|
|
X11_SetCaption (va ("%s %s: %s", PROGRAM, VERSION, temp));
|
2000-10-14 07:10:56 +00:00
|
|
|
free (temp);
|
2000-10-04 05:45:48 +00:00
|
|
|
} else {
|
2001-04-23 03:52:20 +00:00
|
|
|
X11_SetCaption (va ("%s %s", PROGRAM, VERSION));
|
2000-10-04 05:45:48 +00:00
|
|
|
}
|
2000-07-14 16:09:35 +00:00
|
|
|
}
|
2001-04-23 03:52:20 +00:00
|
|
|
|
|
|
|
double
|
|
|
|
VID_GetGamma (void)
|
|
|
|
{
|
|
|
|
return (double) X11_GetGamma ();
|
|
|
|
}
|
|
|
|
|
|
|
|
qboolean
|
|
|
|
VID_SetGamma (double gamma)
|
|
|
|
{
|
|
|
|
return X11_SetGamma (gamma);
|
|
|
|
}
|