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
|
|
|
|
|
|
|
|
*/
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
# include "config.h"
|
|
|
|
#endif
|
2003-01-15 15:31:36 +00:00
|
|
|
|
|
|
|
static __attribute__ ((unused)) const char rcsid[] =
|
|
|
|
"$Id$";
|
|
|
|
|
2001-04-15 04:18:22 +00:00
|
|
|
#ifdef HAVE_STRING_H
|
|
|
|
# include <string.h>
|
|
|
|
#endif
|
|
|
|
#ifdef HAVE_STRINGS_H
|
|
|
|
# include <strings.h>
|
|
|
|
#endif
|
|
|
|
|
2002-08-21 00:05:27 +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"
|
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"
|
2003-01-06 18:28:13 +00:00
|
|
|
#include "QF/GL/qf_vid.h"
|
2001-04-15 04:18:22 +00:00
|
|
|
|
2001-08-25 02:47:11 +00:00
|
|
|
#include "compat.h"
|
2003-01-06 18:28:13 +00:00
|
|
|
#include "context_sdl.h"
|
2002-08-16 07:53:11 +00:00
|
|
|
#include "r_cvar.h"
|
2001-05-31 03:41:35 +00:00
|
|
|
#include "sbar.h"
|
|
|
|
|
2002-08-16 07:53:11 +00:00
|
|
|
#ifdef WIN32 // FIXME: evil hack to get full DirectSound support with SDL
|
2001-04-15 04:18:22 +00:00
|
|
|
# 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;
|
2002-08-21 00:05:27 +00:00
|
|
|
|
|
|
|
SDL_Surface *screen = NULL;
|
|
|
|
|
2001-04-15 04:18:22 +00:00
|
|
|
|
2002-06-24 21:35:37 +00:00
|
|
|
void *
|
2002-08-16 18:29:21 +00:00
|
|
|
QFGL_GetProcAddress (void *handle, const char *name)
|
2002-06-24 21:35:37 +00:00
|
|
|
{
|
2002-08-16 18:29:21 +00:00
|
|
|
return SDL_GL_GetProcAddress (name);
|
2002-06-24 21:35:37 +00:00
|
|
|
}
|
|
|
|
|
2002-08-16 07:53:11 +00:00
|
|
|
void *
|
|
|
|
QFGL_LoadLibrary (void)
|
|
|
|
{
|
|
|
|
if (SDL_GL_LoadLibrary (gl_driver->string) != 0)
|
|
|
|
Sys_Error ("Couldn't load OpenGL library %s!", gl_driver->string);
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
2001-11-02 06:35:32 +00:00
|
|
|
|
2003-01-06 18:28:13 +00:00
|
|
|
static void
|
2001-04-15 04:18:22 +00:00
|
|
|
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;
|
2003-02-09 10:15:20 +00:00
|
|
|
int i, j;
|
2001-04-15 04:18:22 +00:00
|
|
|
|
2002-08-16 07:53:11 +00:00
|
|
|
// Initialize the SDL library
|
|
|
|
if (SDL_Init (SDL_INIT_VIDEO) < 0)
|
|
|
|
Sys_Error ("Couldn't initialize SDL: %s", SDL_GetError ());
|
2001-10-15 19:06:22 +00:00
|
|
|
|
2002-08-16 07:53:11 +00:00
|
|
|
GL_Pre_Init ();
|
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");
|
2002-08-21 06:00:08 +00:00
|
|
|
if (i != 0) // Set console height, no smaller than 200
|
2001-04-15 04:18:22 +00:00
|
|
|
vid.conheight = max (atoi (com_argv[i + 1]), 200);
|
|
|
|
|
|
|
|
// Check if we want fullscreen
|
2002-09-30 03:31:22 +00:00
|
|
|
if (vid_fullscreen->int_val) {
|
2001-04-15 04:18:22 +00:00
|
|
|
flags |= SDL_FULLSCREEN;
|
2002-08-16 07:53:11 +00:00
|
|
|
#ifndef WIN32 // Don't annoy Mesa/3dfx folks
|
2001-04-15 04:18:22 +00:00
|
|
|
// 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.
|
2003-02-09 10:15:20 +00:00
|
|
|
// Cvar_SetValue (in_grab, 1); // Needs #include "QF/input.h"
|
2003-01-06 18:28:13 +00:00
|
|
|
putenv ((char *)"MESA_GLX_FX=fullscreen");
|
2001-04-15 04:18:22 +00:00
|
|
|
} else {
|
2003-01-06 18:28:13 +00:00
|
|
|
putenv ((char *)"MESA_GLX_FX=window");
|
2001-04-15 04:18:22 +00:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
// Setup GL Attributes
|
|
|
|
SDL_GL_SetAttribute (SDL_GL_DOUBLEBUFFER, 1);
|
2003-02-09 10:15:20 +00:00
|
|
|
// SDL_GL_SetAttribute (SDL_GL_STENCIL_SIZE, 0); // Try for 0, 8
|
|
|
|
// SDL_GL_SetAttribute (SDL_GL_STEREO, 1); // Someday...
|
|
|
|
|
|
|
|
for (j = 0; j < 5; j++) {
|
|
|
|
int rgba[5][4] = {
|
2003-02-10 03:19:54 +00:00
|
|
|
{8, 8, 8, 0},
|
|
|
|
{8, 8, 8, 8},
|
|
|
|
{5, 6, 5, 0},
|
|
|
|
{5, 5, 5, 0},
|
|
|
|
{5, 5, 5, 1},
|
|
|
|
};
|
2003-02-09 10:15:20 +00:00
|
|
|
|
|
|
|
SDL_GL_SetAttribute (SDL_GL_RED_SIZE, rgba[j][0]);
|
|
|
|
SDL_GL_SetAttribute (SDL_GL_GREEN_SIZE, rgba[j][1]);
|
|
|
|
SDL_GL_SetAttribute (SDL_GL_BLUE_SIZE, rgba[j][2]);
|
|
|
|
SDL_GL_SetAttribute (SDL_GL_ALPHA_SIZE, rgba[j][3]);
|
|
|
|
|
|
|
|
for (i = 32; i >= 16; i -= 8) {
|
|
|
|
SDL_GL_SetAttribute (SDL_GL_DEPTH_SIZE, i);
|
2003-02-10 03:19:54 +00:00
|
|
|
if ((screen = SDL_SetVideoMode (scr_width, scr_height, 0, flags)))
|
2003-02-09 10:15:20 +00:00
|
|
|
goto success;
|
|
|
|
}
|
2001-04-15 04:18:22 +00:00
|
|
|
}
|
2003-02-09 10:15:20 +00:00
|
|
|
Sys_Error ("Couldn't set video mode: %s", SDL_GetError ());
|
|
|
|
SDL_Quit ();
|
|
|
|
success:
|
2001-04-15 04:18:22 +00:00
|
|
|
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;
|
|
|
|
|
|
|
|
GL_Init ();
|
|
|
|
|
|
|
|
VID_SDL_GammaCheck ();
|
|
|
|
VID_InitGamma (palette);
|
2002-09-10 06:35:32 +00:00
|
|
|
VID_SetPalette (vid.palette);
|
2001-04-15 04:18:22 +00:00
|
|
|
|
2002-08-21 06:00:08 +00:00
|
|
|
VID_Init8bitPalette (); // Check for 3DFX Extensions and initialize them.
|
2001-04-15 04:18:22 +00:00
|
|
|
|
|
|
|
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
|
|
|
|
2002-08-21 06:00:08 +00:00
|
|
|
SDL_ShowCursor (0); // hide the mouse pointer
|
|
|
|
|
2001-04-15 04:18:22 +00:00
|
|
|
#ifdef WIN32
|
2002-08-21 06:00:08 +00:00
|
|
|
// FIXME: EVIL thing - but needed for win32 until
|
|
|
|
// SDL_sound works better - without this DirectSound fails.
|
2001-04-15 04:18:22 +00:00
|
|
|
|
2002-06-27 18:50:26 +00:00
|
|
|
// SDL_GetWMInfo(&info);
|
|
|
|
// mainwindow=info.window;
|
|
|
|
mainwindow=GetActiveWindow();
|
2001-04-15 04:18:22 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
vid.recalc_refdef = 1; // force a surface cache flush
|
|
|
|
}
|