2001-04-15 04:18:22 +00:00
|
|
|
/*
|
|
|
|
vid_sgl.c
|
|
|
|
|
|
|
|
Video driver for OpenGL-using versions of SDL
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
|
*/
|
2001-09-28 06:26:31 +00:00
|
|
|
static const char rcsid[] =
|
|
|
|
"$Id$";
|
2001-04-15 04:18:22 +00:00
|
|
|
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
# include "config.h"
|
|
|
|
#endif
|
|
|
|
#ifdef HAVE_STRING_H
|
|
|
|
# include <string.h>
|
|
|
|
#endif
|
|
|
|
#ifdef HAVE_STRINGS_H
|
|
|
|
# include <strings.h>
|
|
|
|
#endif
|
|
|
|
#ifndef WIN32
|
2002-04-07 04:45:02 +00:00
|
|
|
# include <signal.h>
|
2001-04-15 04:18:22 +00:00
|
|
|
#endif
|
2002-04-07 04:45:02 +00:00
|
|
|
#include <stdlib.h>
|
2001-04-15 04:18:22 +00:00
|
|
|
|
|
|
|
#include <SDL.h>
|
|
|
|
|
|
|
|
#include "QF/console.h"
|
2001-05-31 03:41:35 +00:00
|
|
|
#include "QF/cvar.h"
|
2001-04-15 04:18:22 +00:00
|
|
|
#include "QF/qargs.h"
|
|
|
|
#include "QF/qendian.h"
|
|
|
|
#include "QF/sys.h"
|
|
|
|
#include "QF/va.h"
|
2001-04-16 03:55:44 +00:00
|
|
|
#include "QF/vid.h"
|
2001-08-25 02:47:11 +00:00
|
|
|
#include "QF/GL/funcs.h"
|
2001-04-15 04:18:22 +00:00
|
|
|
|
2001-08-25 02:47:11 +00:00
|
|
|
#include "compat.h"
|
2001-05-31 03:41:35 +00:00
|
|
|
#include "sbar.h"
|
|
|
|
|
2001-04-15 04:18:22 +00:00
|
|
|
#ifdef WIN32
|
|
|
|
/* FIXME: this is evil hack to get full DirectSound support with SDL */
|
|
|
|
# include <windows.h>
|
|
|
|
# include <SDL_syswm.h>
|
|
|
|
HWND mainwindow;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#define WARP_WIDTH 320
|
|
|
|
#define WARP_HEIGHT 200
|
|
|
|
|
2002-06-24 21:35:37 +00:00
|
|
|
int VID_options_items = 1;
|
|
|
|
int modestate;
|
2001-04-15 04:18:22 +00:00
|
|
|
|
2001-11-02 06:11:32 +00:00
|
|
|
static SDL_Surface *screen = NULL;
|
2001-04-15 04:18:22 +00:00
|
|
|
|
2002-06-24 21:35:37 +00:00
|
|
|
void * (* glGetProcAddress) (const char *symbol) = NULL; // FIXME
|
|
|
|
//# error "Cannot load libraries: %s was not configured with DSO support"
|
|
|
|
|
|
|
|
// the following is to avoid other compiler errors
|
2002-06-27 16:37:16 +00:00
|
|
|
#ifdef _WIN32
|
|
|
|
void *(*getProcAddress) (HINSTANCE, LPCSTR);
|
|
|
|
#else
|
|
|
|
void *(*getProcAddress) (void *, const char *);
|
|
|
|
#endif
|
2002-06-24 21:35:37 +00:00
|
|
|
|
|
|
|
void *
|
|
|
|
QFGL_LoadLibrary (void)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
//#endif
|
|
|
|
|
2001-11-02 06:35:32 +00:00
|
|
|
|
2001-04-15 04:18:22 +00:00
|
|
|
void
|
|
|
|
VID_SDL_GammaCheck (void)
|
|
|
|
{
|
|
|
|
Uint16 redtable[256], greentable[256], bluetable[256];
|
|
|
|
|
|
|
|
if (SDL_GetGammaRamp(redtable, greentable, bluetable) < 0)
|
|
|
|
vid_gamma_avail = false;
|
|
|
|
else
|
|
|
|
vid_gamma_avail = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
VID_Shutdown (void)
|
|
|
|
{
|
|
|
|
SDL_Quit ();
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifndef WIN32
|
|
|
|
static void
|
|
|
|
signal_handler (int sig)
|
|
|
|
{
|
|
|
|
printf ("Received signal %d, exiting...\n", sig);
|
|
|
|
Sys_Quit ();
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
InitSig (void)
|
|
|
|
{
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
void
|
|
|
|
GL_Init (void)
|
|
|
|
{
|
|
|
|
GL_Init_Common ();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
GL_EndRendering (void)
|
|
|
|
{
|
2002-02-27 05:22:21 +00:00
|
|
|
qfglFinish ();
|
2001-04-15 04:18:22 +00:00
|
|
|
SDL_GL_SwapBuffers ();
|
|
|
|
Sbar_Changed ();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
VID_Init (unsigned char *palette)
|
|
|
|
{
|
|
|
|
Uint32 flags = SDL_OPENGL;
|
|
|
|
int i;
|
|
|
|
|
2001-10-15 19:06:22 +00:00
|
|
|
GL_Pre_Init ();
|
|
|
|
|
2001-08-25 02:47:11 +00:00
|
|
|
// SDL_SysWMinfo info;
|
2001-04-15 04:18:22 +00:00
|
|
|
|
|
|
|
VID_GetWindowSize (640, 480);
|
|
|
|
|
|
|
|
vid.maxwarpwidth = WARP_WIDTH;
|
|
|
|
vid.maxwarpheight = WARP_HEIGHT;
|
2001-08-25 02:47:11 +00:00
|
|
|
vid.colormap8 = vid_colormap;
|
|
|
|
vid.fullbright = 256 - LittleLong (*((int *) vid.colormap8 + 2048));
|
2001-04-15 04:18:22 +00:00
|
|
|
|
|
|
|
// Interpret command-line params
|
|
|
|
|
|
|
|
// Set vid parameters
|
|
|
|
if ((i = COM_CheckParm ("-conwidth")) != 0)
|
|
|
|
vid.conwidth = atoi (com_argv[i + 1]);
|
|
|
|
else
|
|
|
|
vid.conwidth = scr_width;
|
|
|
|
|
|
|
|
vid.conwidth &= 0xfff8; // make it a multiple of eight
|
|
|
|
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");
|
|
|
|
if (i != 0) // Set console height, but no smaller
|
|
|
|
// than 200 px
|
|
|
|
vid.conheight = max (atoi (com_argv[i + 1]), 200);
|
|
|
|
|
|
|
|
// Initialize the SDL library
|
|
|
|
if (SDL_Init (SDL_INIT_VIDEO) < 0)
|
2002-05-14 06:12:29 +00:00
|
|
|
Sys_Error ("Couldn't initialize SDL: %s", SDL_GetError ());
|
2001-04-15 04:18:22 +00:00
|
|
|
|
|
|
|
// Check if we want fullscreen
|
|
|
|
if (vid_fullscreen->value) {
|
|
|
|
flags |= SDL_FULLSCREEN;
|
|
|
|
// Don't annoy Mesa/3dfx folks
|
|
|
|
#ifndef WIN32
|
|
|
|
// FIXME: Maybe this could be put in a different spot, but I don't
|
2001-11-02 06:35:32 +00:00
|
|
|
// know where. Anyway, it's to work around a 3Dfx Glide bug.
|
2001-04-15 04:18:22 +00:00
|
|
|
SDL_ShowCursor (0);
|
|
|
|
SDL_WM_GrabInput (SDL_GRAB_ON);
|
2002-04-07 04:45:02 +00:00
|
|
|
putenv ("MESA_GLX_FX=fullscreen");
|
2001-04-15 04:18:22 +00:00
|
|
|
} else {
|
2002-04-07 04:45:02 +00:00
|
|
|
putenv ("MESA_GLX_FX=window");
|
2001-04-15 04:18:22 +00:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
// Setup GL Attributes
|
2001-08-06 00:16:48 +00:00
|
|
|
SDL_GL_SetAttribute (SDL_GL_RED_SIZE, 4);
|
|
|
|
SDL_GL_SetAttribute (SDL_GL_GREEN_SIZE, 4);
|
|
|
|
SDL_GL_SetAttribute (SDL_GL_BLUE_SIZE, 4);
|
2001-04-15 04:18:22 +00:00
|
|
|
SDL_GL_SetAttribute (SDL_GL_DOUBLEBUFFER, 1);
|
|
|
|
SDL_GL_SetAttribute (SDL_GL_DEPTH_SIZE, 1);
|
|
|
|
|
2001-11-02 06:11:32 +00:00
|
|
|
if (!(screen = SDL_SetVideoMode (scr_width, scr_height, 8, flags))) {
|
2002-05-14 06:12:29 +00:00
|
|
|
Sys_Error ("Couldn't set video mode: %s", SDL_GetError ());
|
2001-04-15 04:18:22 +00:00
|
|
|
SDL_Quit ();
|
|
|
|
}
|
|
|
|
|
|
|
|
vid.height = vid.conheight = min (vid.conheight, scr_height);
|
|
|
|
vid.width = vid.conwidth = min (vid.conwidth, scr_width);
|
|
|
|
Con_CheckResize (); // Now that we have a window size, fix console
|
|
|
|
|
2001-08-06 00:16:48 +00:00
|
|
|
vid.aspect = ((float) vid.height / (float) vid.width) * (4.0 / 3.0);
|
2001-04-15 04:18:22 +00:00
|
|
|
vid.numpages = 2;
|
|
|
|
|
|
|
|
#ifndef WIN32
|
|
|
|
InitSig (); // trap evil signals
|
|
|
|
#endif
|
|
|
|
|
|
|
|
GL_Init ();
|
|
|
|
|
|
|
|
VID_SDL_GammaCheck ();
|
|
|
|
|
|
|
|
VID_InitGamma (palette);
|
|
|
|
VID_SetPalette (palette);
|
|
|
|
|
|
|
|
// Check for 3DFX Extensions and initialize them.
|
|
|
|
VID_Init8bitPalette ();
|
|
|
|
|
|
|
|
Con_Printf ("Video mode %dx%d initialized.\n", scr_width, scr_height);
|
|
|
|
|
2001-05-25 04:03:47 +00:00
|
|
|
vid.initialized = true;
|
2001-04-15 04:18:22 +00:00
|
|
|
|
|
|
|
#ifdef WIN32
|
|
|
|
// FIXME: EVIL thing - but needed for win32 until
|
|
|
|
// SDL_sound works better - without this DirectSound fails.
|
|
|
|
|
2001-11-02 06:35:32 +00:00
|
|
|
// SDL_GetWMInfo(&info);
|
|
|
|
// mainwindow=info.window;
|
2001-04-15 04:18:22 +00:00
|
|
|
mainwindow=GetActiveWindow();
|
|
|
|
#endif
|
|
|
|
|
|
|
|
vid.recalc_refdef = 1; // force a surface cache flush
|
|
|
|
}
|
|
|
|
|
2001-11-02 06:11:32 +00:00
|
|
|
void
|
|
|
|
VID_UpdateFullscreen (cvar_t *vid_fullscreen)
|
|
|
|
{
|
|
|
|
if (!vid.initialized)
|
|
|
|
return;
|
|
|
|
if ((vid_fullscreen->int_val && !(screen->flags & SDL_FULLSCREEN))
|
|
|
|
|| (!vid_fullscreen->int_val && screen->flags & SDL_FULLSCREEN))
|
|
|
|
if (!SDL_WM_ToggleFullScreen (screen))
|
|
|
|
Con_Printf ("VID_UpdateFullscreen: error setting fullscreen\n");
|
|
|
|
}
|
|
|
|
|
2001-04-15 04:18:22 +00:00
|
|
|
void
|
|
|
|
VID_Init_Cvars ()
|
|
|
|
{
|
2001-11-02 06:11:32 +00:00
|
|
|
vid_fullscreen = Cvar_Get ("vid_fullscreen", "0", CVAR_ARCHIVE,
|
|
|
|
VID_UpdateFullscreen, "Toggles fullscreen mode");
|
2001-04-15 04:18:22 +00:00
|
|
|
vid_system_gamma = Cvar_Get ("vid_system_gamma", "1", CVAR_ARCHIVE, NULL,
|
|
|
|
"Use system gamma control if available");
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2001-07-15 07:04:17 +00:00
|
|
|
VID_SetCaption (const char *text)
|
2001-04-15 04:18:22 +00:00
|
|
|
{
|
|
|
|
if (text && *text) {
|
|
|
|
char *temp = strdup (text);
|
|
|
|
|
|
|
|
SDL_WM_SetCaption (va ("%s %s: %s", PROGRAM, VERSION, temp), NULL);
|
|
|
|
free (temp);
|
|
|
|
} else {
|
|
|
|
SDL_WM_SetCaption (va ("%s %s", PROGRAM, VERSION), NULL);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
qboolean
|
|
|
|
VID_SetGamma (double gamma)
|
|
|
|
{
|
|
|
|
return SDL_SetGamma((float) gamma, (float) gamma, (float) gamma);
|
|
|
|
}
|