2000-07-11 00:22:52 +00:00
|
|
|
/*
|
2000-07-11 05:05:27 +00:00
|
|
|
vid_sgl.c
|
2000-07-11 00:22:52 +00:00
|
|
|
|
2000-07-11 05:05:27 +00:00
|
|
|
Video driver for OpenGL-using versions of SDL
|
2000-07-11 00:22:52 +00:00
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
|
$Id$
|
|
|
|
*/
|
|
|
|
|
2000-10-26 16:29:45 +00:00
|
|
|
#ifdef HAVE_CONFIG_H
|
2000-12-08 06:51:37 +00:00
|
|
|
# include "config.h"
|
2000-10-26 16:29:45 +00:00
|
|
|
#endif
|
|
|
|
#ifdef HAVE_STRING_H
|
|
|
|
#include <string.h>
|
|
|
|
#endif
|
2000-10-29 08:38:43 +00:00
|
|
|
#ifndef WIN32
|
2000-10-26 16:29:45 +00:00
|
|
|
#include <sys/signal.h>
|
2000-10-29 08:38:43 +00:00
|
|
|
#endif
|
2000-10-26 06:08:09 +00:00
|
|
|
#include <SDL.h>
|
2000-10-26 16:29:45 +00:00
|
|
|
|
|
|
|
#include "console.h"
|
2000-12-05 06:58:01 +00:00
|
|
|
#include "host.h"
|
2000-10-26 16:29:45 +00:00
|
|
|
#include "qargs.h"
|
|
|
|
#include "qendian.h"
|
|
|
|
#include "sys.h"
|
|
|
|
#include "va.h"
|
2000-10-13 06:16:27 +00:00
|
|
|
#include "glquake.h"
|
2000-07-11 00:22:52 +00:00
|
|
|
|
|
|
|
#define WARP_WIDTH 320
|
|
|
|
#define WARP_HEIGHT 200
|
|
|
|
|
2000-12-08 06:51:37 +00:00
|
|
|
static qboolean vid_initialized = false;
|
2000-07-11 00:22:52 +00:00
|
|
|
|
2000-12-08 06:51:37 +00:00
|
|
|
cvar_t *vid_fullscreen;
|
2000-07-11 00:22:52 +00:00
|
|
|
|
2000-12-08 06:51:37 +00:00
|
|
|
int VID_options_items = 1;
|
|
|
|
int modestate;
|
2000-07-11 00:22:52 +00:00
|
|
|
|
2000-12-05 06:58:01 +00:00
|
|
|
extern void GL_Init_Common (void);
|
|
|
|
extern void VID_Init8bitPalette (void);
|
2000-12-08 06:51:37 +00:00
|
|
|
|
|
|
|
/*-----------------------------------------------------------------------*/
|
2000-07-11 00:22:52 +00:00
|
|
|
|
2000-08-02 01:18:37 +00:00
|
|
|
void
|
|
|
|
VID_Shutdown (void)
|
2000-07-11 00:22:52 +00:00
|
|
|
{
|
|
|
|
if (!vid_initialized)
|
|
|
|
return;
|
|
|
|
|
2000-08-02 01:18:37 +00:00
|
|
|
Con_Printf ("VID_Shutdown\n");
|
2000-07-11 00:22:52 +00:00
|
|
|
|
2000-08-02 01:18:37 +00:00
|
|
|
SDL_Quit ();
|
2000-07-11 00:22:52 +00:00
|
|
|
}
|
2000-10-26 06:08:09 +00:00
|
|
|
|
2000-07-11 14:42:05 +00:00
|
|
|
#ifndef WIN32
|
2000-07-11 00:22:52 +00:00
|
|
|
static void
|
2000-12-08 06:51:37 +00:00
|
|
|
signal_handler (int sig)
|
2000-07-11 00:22:52 +00:00
|
|
|
{
|
2000-12-08 06:51:37 +00:00
|
|
|
printf ("Received signal %d, exiting...\n", sig);
|
|
|
|
Sys_Quit ();
|
|
|
|
exit (sig);
|
2000-07-11 00:22:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2000-12-08 06:51:37 +00:00
|
|
|
InitSig (void)
|
2000-07-11 00:22:52 +00:00
|
|
|
{
|
2000-12-08 06:51:37 +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-07-11 00:22:52 +00:00
|
|
|
}
|
2000-07-11 14:42:05 +00:00
|
|
|
#endif
|
2000-08-02 01:18:37 +00:00
|
|
|
|
|
|
|
void
|
|
|
|
GL_Init (void)
|
2000-07-11 00:22:52 +00:00
|
|
|
{
|
2000-12-08 06:51:37 +00:00
|
|
|
GL_Init_Common ();
|
2000-07-11 00:22:52 +00:00
|
|
|
}
|
|
|
|
|
2000-08-02 01:18:37 +00:00
|
|
|
void
|
|
|
|
GL_EndRendering (void)
|
2000-07-11 00:22:52 +00:00
|
|
|
{
|
2000-10-28 07:11:37 +00:00
|
|
|
glFlush ();
|
2000-07-11 00:22:52 +00:00
|
|
|
SDL_GL_SwapBuffers ();
|
|
|
|
}
|
|
|
|
|
2000-08-02 01:18:37 +00:00
|
|
|
void
|
|
|
|
VID_Init (unsigned char *palette)
|
2000-07-11 00:22:52 +00:00
|
|
|
{
|
2000-12-08 06:51:37 +00:00
|
|
|
Uint32 flags = SDL_OPENGL;
|
|
|
|
int i;
|
2000-10-21 07:15:30 +00:00
|
|
|
|
|
|
|
VID_GetWindowSize (640, 480);
|
2000-07-11 00:22:52 +00:00
|
|
|
|
|
|
|
vid.maxwarpwidth = WARP_WIDTH;
|
|
|
|
vid.maxwarpheight = WARP_HEIGHT;
|
|
|
|
vid.colormap = host_colormap;
|
2000-12-08 06:51:37 +00:00
|
|
|
vid.fullbright = 256 - LittleLong (*((int *) vid.colormap + 2048));
|
2000-07-11 00:22:52 +00:00
|
|
|
|
|
|
|
// Interpret command-line params
|
|
|
|
|
|
|
|
// Set vid parameters
|
2000-08-02 01:18:37 +00:00
|
|
|
if ((i = COM_CheckParm ("-conwidth")) != 0)
|
2000-12-08 06:51:37 +00:00
|
|
|
vid.conwidth = atoi (com_argv[i + 1]);
|
2000-07-11 00:22:52 +00:00
|
|
|
else
|
2000-10-21 21:14:12 +00:00
|
|
|
vid.conwidth = scr_width;
|
2000-07-11 00:22:52 +00:00
|
|
|
|
2000-12-08 06:51:37 +00:00
|
|
|
vid.conwidth &= 0xfff8; // make it a multiple of eight
|
2000-07-11 00:22:52 +00:00
|
|
|
if (vid.conwidth < 320)
|
|
|
|
vid.conwidth = 320;
|
|
|
|
|
|
|
|
// pick a conheight that matches with correct aspect
|
|
|
|
vid.conheight = vid.conwidth * 3 / 4;
|
|
|
|
|
|
|
|
i = COM_CheckParm ("-conheight");
|
2000-12-08 06:51:37 +00:00
|
|
|
if (i != 0) // Set console height, but no smaller
|
|
|
|
// than 200 px
|
|
|
|
vid.conheight = max (atoi (com_argv[i + 1]), 200);
|
2000-07-11 00:22:52 +00:00
|
|
|
|
|
|
|
// Initialize the SDL library
|
2000-12-08 06:51:37 +00:00
|
|
|
if (SDL_Init (SDL_INIT_VIDEO) < 0)
|
|
|
|
Sys_Error ("Couldn't initialize SDL: %s\n", SDL_GetError ());
|
2000-07-11 00:22:52 +00:00
|
|
|
|
|
|
|
// Check if we want fullscreen
|
2000-10-26 06:08:09 +00:00
|
|
|
if (vid_fullscreen->value) {
|
2000-07-11 00:22:52 +00:00
|
|
|
flags |= SDL_FULLSCREEN;
|
|
|
|
// Don't annoy Mesa/3dfx folks
|
2000-07-11 14:42:05 +00:00
|
|
|
#ifndef WIN32
|
2000-12-08 06:51:37 +00:00
|
|
|
// FIXME: Maybe this could be put in a different spot, but I don't
|
|
|
|
// know where.
|
2000-08-02 01:18:37 +00:00
|
|
|
// Anyway, it's to work around a 3Dfx Glide bug.
|
|
|
|
SDL_ShowCursor (0);
|
|
|
|
SDL_WM_GrabInput (SDL_GRAB_ON);
|
|
|
|
setenv ("MESA_GLX_FX", "fullscreen", 1);
|
2000-07-11 00:22:52 +00:00
|
|
|
} else {
|
2000-08-02 01:18:37 +00:00
|
|
|
setenv ("MESA_GLX_FX", "window", 1);
|
2000-07-11 14:42:05 +00:00
|
|
|
#endif
|
2000-07-11 00:22:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Setup GL Attributes
|
2000-08-02 01:18:37 +00:00
|
|
|
SDL_GL_SetAttribute (SDL_GL_RED_SIZE, 1);
|
|
|
|
SDL_GL_SetAttribute (SDL_GL_GREEN_SIZE, 1);
|
|
|
|
SDL_GL_SetAttribute (SDL_GL_BLUE_SIZE, 1);
|
|
|
|
SDL_GL_SetAttribute (SDL_GL_DOUBLEBUFFER, 1);
|
|
|
|
SDL_GL_SetAttribute (SDL_GL_DEPTH_SIZE, 1);
|
2000-12-08 06:51:37 +00:00
|
|
|
|
2000-10-21 21:14:12 +00:00
|
|
|
if (SDL_SetVideoMode (scr_width, scr_height, 8, flags) == NULL) {
|
2000-12-08 06:51:37 +00:00
|
|
|
Sys_Error ("Couldn't set video mode: %s\n", SDL_GetError ());
|
|
|
|
SDL_Quit ();
|
2000-07-11 00:22:52 +00:00
|
|
|
}
|
|
|
|
|
2000-10-21 21:14:12 +00:00
|
|
|
vid.height = vid.conheight = min (vid.conheight, scr_height);
|
|
|
|
vid.width = vid.conwidth = min (vid.conwidth, scr_width);
|
2000-07-11 00:22:52 +00:00
|
|
|
|
2000-08-02 01:18:37 +00:00
|
|
|
vid.aspect = ((float) vid.height / (float) vid.width) * (320.0 / 240.0);
|
2000-07-11 00:22:52 +00:00
|
|
|
vid.numpages = 2;
|
2000-10-28 07:11:37 +00:00
|
|
|
|
2000-07-11 14:42:05 +00:00
|
|
|
#ifndef WIN32
|
2000-12-08 06:51:37 +00:00
|
|
|
InitSig (); // trap evil signals
|
2000-07-11 14:42:05 +00:00
|
|
|
#endif
|
2000-07-11 00:22:52 +00:00
|
|
|
|
2000-12-08 06:51:37 +00:00
|
|
|
GL_Init ();
|
2000-07-11 00:22:52 +00:00
|
|
|
|
2000-10-28 07:11:37 +00:00
|
|
|
GL_CheckBrightness (palette);
|
2000-07-11 00:22:52 +00:00
|
|
|
VID_SetPalette (palette);
|
|
|
|
|
|
|
|
// Check for 3DFX Extensions and initialize them.
|
2000-12-08 06:51:37 +00:00
|
|
|
VID_Init8bitPalette ();
|
2000-07-11 00:22:52 +00:00
|
|
|
|
2000-12-08 06:51:37 +00:00
|
|
|
Con_Printf ("Video mode %dx%d initialized.\n", scr_width, scr_height);
|
2000-07-11 00:22:52 +00:00
|
|
|
|
|
|
|
vid_initialized = true;
|
2000-10-28 07:11:37 +00:00
|
|
|
|
2000-12-08 06:51:37 +00:00
|
|
|
vid.recalc_refdef = 1; // force a surface cache flush
|
2000-07-11 00:22:52 +00:00
|
|
|
}
|
|
|
|
|
2000-10-29 15:35:24 +00:00
|
|
|
void
|
|
|
|
VID_Init_Cvars ()
|
|
|
|
{
|
2000-12-08 06:51:37 +00:00
|
|
|
vid_fullscreen = Cvar_Get ("vid_fullscreen", "0", 0, "None");
|
2000-10-29 15:35:24 +00:00
|
|
|
}
|
|
|
|
|
2000-07-14 17:04:18 +00:00
|
|
|
void
|
|
|
|
VID_SetCaption (char *text)
|
|
|
|
{
|
2000-10-04 05:45:48 +00:00
|
|
|
if (text && *text) {
|
2000-12-08 06:51:37 +00:00
|
|
|
char *temp = strdup (text);
|
|
|
|
|
2000-10-28 07:11:37 +00:00
|
|
|
SDL_WM_SetCaption (va ("%s %s: %s", PROGRAM, VERSION, temp), NULL);
|
2000-10-14 07:10:56 +00:00
|
|
|
free (temp);
|
2000-10-04 05:45:48 +00:00
|
|
|
} else {
|
2000-10-28 07:11:37 +00:00
|
|
|
SDL_WM_SetCaption (va ("%s %s", PROGRAM, VERSION), NULL);
|
2000-10-04 05:45:48 +00:00
|
|
|
}
|
2000-07-14 17:04:18 +00:00
|
|
|
}
|