2000-07-11 07:51:36 +00:00
|
|
|
/*
|
2000-10-04 05:45:48 +00:00
|
|
|
vid_sdl.c
|
2000-07-11 07:51:36 +00:00
|
|
|
|
|
|
|
Video driver for Sam Lantinga's Simple DirectMedia Layer
|
|
|
|
|
|
|
|
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-07-16 21:48:16 +00:00
|
|
|
#ifdef HAVE_CONFIG_H
|
2000-12-08 06:51:37 +00:00
|
|
|
# include "config.h"
|
2000-07-16 21:48:16 +00:00
|
|
|
#endif
|
2000-10-26 16:29:45 +00:00
|
|
|
#ifdef HAVE_STRING_H
|
2000-12-30 18:26:29 +00:00
|
|
|
# include <string.h>
|
2000-10-26 16:29:45 +00:00
|
|
|
#endif
|
2000-12-30 02:16:36 +00:00
|
|
|
#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-12-30 18:26:29 +00:00
|
|
|
|
2000-10-13 06:16:27 +00:00
|
|
|
#include <SDL.h>
|
2000-07-11 07:51:36 +00:00
|
|
|
|
2001-01-09 00:03:08 +00:00
|
|
|
#include "console.h"
|
2000-10-13 06:16:27 +00:00
|
|
|
#include "cvar.h"
|
2000-07-16 21:48:16 +00:00
|
|
|
#include "d_local.h"
|
2000-12-05 06:58:01 +00:00
|
|
|
#include "host.h"
|
2000-10-13 06:16:27 +00:00
|
|
|
#include "qendian.h"
|
2000-10-26 16:29:45 +00:00
|
|
|
#include "sys.h"
|
2000-10-26 06:08:09 +00:00
|
|
|
#include "va.h"
|
2000-10-26 16:29:45 +00:00
|
|
|
#include "vid.h"
|
2000-07-16 21:48:16 +00:00
|
|
|
|
2000-12-30 18:26:29 +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
|
|
|
|
|
2000-07-16 21:48:16 +00:00
|
|
|
// static float oldin_grab = 0;
|
2000-07-11 07:51:36 +00:00
|
|
|
|
2000-12-08 06:51:37 +00:00
|
|
|
cvar_t *vid_fullscreen;
|
|
|
|
extern viddef_t vid; // global video state
|
|
|
|
unsigned short d_8to16table[256];
|
|
|
|
|
|
|
|
int modestate; // fixme: just to avoid cross-comp.
|
2000-12-29 16:20:38 +00:00
|
|
|
// errors - remove later
|
2000-12-08 06:51:37 +00:00
|
|
|
|
2000-07-11 07:51:36 +00:00
|
|
|
// The original defaults
|
2000-10-28 05:08:55 +00:00
|
|
|
#define BASEWIDTH 320
|
|
|
|
#define BASEHEIGHT 200
|
2000-07-11 07:51:36 +00:00
|
|
|
|
2000-12-08 06:51:37 +00:00
|
|
|
int VGA_width, VGA_height, VGA_rowbytes, VGA_bufferrowbytes = 0;
|
|
|
|
byte *VGA_pagebase;
|
2000-07-11 07:51:36 +00:00
|
|
|
|
|
|
|
static SDL_Surface *screen = NULL;
|
|
|
|
|
2000-10-18 10:16:11 +00:00
|
|
|
void
|
|
|
|
VID_InitBuffers (int width, int height)
|
|
|
|
{
|
2000-12-08 06:51:37 +00:00
|
|
|
int tbuffersize, tcachesize;
|
|
|
|
void *vid_surfcache;
|
2000-10-18 10:16:11 +00:00
|
|
|
|
|
|
|
// Calculate the sizes we want first
|
|
|
|
tbuffersize = vid.width * vid.height * sizeof (*d_pzbuffer);
|
2000-12-08 06:51:37 +00:00
|
|
|
tcachesize = D_SurfaceCacheForRes (width, height);
|
2000-10-18 10:16:11 +00:00
|
|
|
|
|
|
|
// Free the old z-buffer
|
|
|
|
if (d_pzbuffer) {
|
|
|
|
free (d_pzbuffer);
|
|
|
|
d_pzbuffer = NULL;
|
|
|
|
}
|
|
|
|
// Free the old surface cache
|
|
|
|
vid_surfcache = D_SurfaceCacheAddress ();
|
|
|
|
if (vid_surfcache) {
|
|
|
|
D_FlushCaches ();
|
|
|
|
free (vid_surfcache);
|
|
|
|
vid_surfcache = NULL;
|
|
|
|
}
|
|
|
|
// Allocate the new z-buffer
|
|
|
|
d_pzbuffer = calloc (tbuffersize, 1);
|
|
|
|
if (!d_pzbuffer) {
|
|
|
|
Sys_Error ("Not enough memory for video mode\n");
|
|
|
|
}
|
|
|
|
// Allocate the new surface cache; free the z-buffer if we fail
|
|
|
|
vid_surfcache = calloc (tcachesize, 1);
|
|
|
|
if (!vid_surfcache) {
|
|
|
|
free (d_pzbuffer);
|
|
|
|
d_pzbuffer = NULL;
|
|
|
|
Sys_Error ("Not enough memory for video mode\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
D_InitCaches (vid_surfcache, tcachesize);
|
|
|
|
}
|
|
|
|
|
2000-10-13 05:36:46 +00:00
|
|
|
void
|
|
|
|
VID_SetPalette (unsigned char *palette)
|
2000-07-11 07:51:36 +00:00
|
|
|
{
|
2000-12-08 06:51:37 +00:00
|
|
|
int i;
|
|
|
|
SDL_Color colors[256];
|
|
|
|
|
|
|
|
for (i = 0; i < 256; ++i) {
|
|
|
|
colors[i].r = *palette++;
|
|
|
|
colors[i].g = *palette++;
|
|
|
|
colors[i].b = *palette++;
|
|
|
|
}
|
|
|
|
SDL_SetColors (screen, colors, 0, 256);
|
2000-07-11 07:51:36 +00:00
|
|
|
}
|
|
|
|
|
2000-10-13 05:36:46 +00:00
|
|
|
void
|
|
|
|
VID_ShiftPalette (unsigned char *palette)
|
2000-07-11 07:51:36 +00:00
|
|
|
{
|
2000-12-08 06:51:37 +00:00
|
|
|
VID_SetPalette (palette);
|
2000-07-11 07:51:36 +00:00
|
|
|
}
|
|
|
|
|
2000-10-13 05:36:46 +00:00
|
|
|
void
|
|
|
|
VID_Init (unsigned char *palette)
|
2000-07-11 07:51:36 +00:00
|
|
|
{
|
2000-12-08 06:51:37 +00:00
|
|
|
// Uint8 video_bpp;
|
|
|
|
// Uint16 video_w, video_h;
|
|
|
|
Uint32 flags;
|
|
|
|
|
|
|
|
// Load the SDL library
|
|
|
|
if (SDL_Init (SDL_INIT_VIDEO) < 0) // |SDL_INIT_AUDIO|SDL_INIT_CDROM) <
|
|
|
|
// 0)
|
|
|
|
Sys_Error ("VID: Couldn't load SDL: %s", SDL_GetError ());
|
|
|
|
|
|
|
|
// Set up display mode (width and height)
|
|
|
|
VID_GetWindowSize (BASEWIDTH, BASEHEIGHT);
|
2001-01-09 00:03:08 +00:00
|
|
|
Con_CheckResize (); // Now that we have a window size, fix console
|
|
|
|
|
2000-12-08 06:51:37 +00:00
|
|
|
vid.maxwarpwidth = WARP_WIDTH;
|
|
|
|
vid.maxwarpheight = WARP_HEIGHT;
|
|
|
|
|
|
|
|
// Set video width, height and flags
|
|
|
|
flags = (SDL_SWSURFACE | SDL_HWPALETTE);
|
|
|
|
if (vid_fullscreen->int_val)
|
|
|
|
flags |= SDL_FULLSCREEN;
|
|
|
|
|
|
|
|
// Initialize display
|
|
|
|
if (!(screen = SDL_SetVideoMode (vid.width, vid.height, 8, flags)))
|
|
|
|
Sys_Error ("VID: Couldn't set video mode: %s\n", SDL_GetError ());
|
2001-04-23 04:16:17 +00:00
|
|
|
VID_InitGamma (palette);
|
2000-12-08 06:51:37 +00:00
|
|
|
VID_SetPalette (palette);
|
|
|
|
VID_SetCaption ("");
|
|
|
|
|
|
|
|
// now know everything we need to know about the buffer
|
|
|
|
VGA_width = vid.conwidth = vid.width;
|
|
|
|
VGA_height = vid.conheight = vid.height;
|
|
|
|
vid.aspect = ((float) vid.height / (float) vid.width) * (320.0 / 240.0);
|
|
|
|
vid.numpages = 1;
|
|
|
|
vid.colormap = host_colormap;
|
|
|
|
vid.fullbright = 256 - LittleLong (*((int *) vid.colormap + 2048));
|
|
|
|
VGA_pagebase = vid.buffer = screen->pixels;
|
|
|
|
VGA_rowbytes = vid.rowbytes = screen->pitch;
|
|
|
|
vid.conbuffer = vid.buffer;
|
|
|
|
vid.conrowbytes = vid.rowbytes;
|
|
|
|
vid.direct = 0;
|
|
|
|
|
|
|
|
// allocate z buffer and surface cache
|
|
|
|
VID_InitBuffers (vid.width, vid.height);
|
|
|
|
|
|
|
|
// initialize the mouse
|
|
|
|
SDL_ShowCursor (0);
|
2000-07-30 10:17:18 +00:00
|
|
|
|
2000-12-29 16:20:38 +00:00
|
|
|
#ifdef WIN32
|
|
|
|
// fixme: EVIL thing - but needed for win32 until
|
|
|
|
// SDL_sound works better - without this DirectSound fails.
|
|
|
|
|
|
|
|
// SDL_GetWMInfo(&info);
|
|
|
|
// mainwindow=info.window;
|
|
|
|
mainwindow=GetActiveWindow();
|
|
|
|
#endif
|
|
|
|
|
2000-07-11 07:51:36 +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", CVAR_ROM,
|
|
|
|
"Toggles fullscreen game mode");
|
2000-10-29 15:35:24 +00:00
|
|
|
}
|
|
|
|
|
2000-10-13 05:36:46 +00:00
|
|
|
void
|
|
|
|
VID_Shutdown (void)
|
2000-07-11 07:51:36 +00:00
|
|
|
{
|
2000-12-08 06:51:37 +00:00
|
|
|
SDL_Quit ();
|
2000-07-11 07:51:36 +00:00
|
|
|
}
|
|
|
|
|
2000-10-13 05:36:46 +00:00
|
|
|
void
|
|
|
|
VID_Update (vrect_t *rects)
|
2000-07-11 07:51:36 +00:00
|
|
|
{
|
2000-12-08 06:51:37 +00:00
|
|
|
SDL_Rect *sdlrects;
|
|
|
|
int n, i;
|
|
|
|
vrect_t *rect;
|
|
|
|
|
|
|
|
// Two-pass system, since Quake doesn't do it the SDL way...
|
|
|
|
|
|
|
|
// First, count the number of rectangles
|
|
|
|
n = 0;
|
|
|
|
for (rect = rects; rect; rect = rect->pnext)
|
|
|
|
++n;
|
|
|
|
|
|
|
|
// Second, copy them to SDL rectangles and update
|
|
|
|
if (!(sdlrects = (SDL_Rect *) calloc (1, n * sizeof (SDL_Rect))))
|
|
|
|
Sys_Error ("Out of memory!");
|
|
|
|
i = 0;
|
|
|
|
for (rect = rects; rect; rect = rect->pnext) {
|
|
|
|
sdlrects[i].x = rect->x;
|
|
|
|
sdlrects[i].y = rect->y;
|
|
|
|
sdlrects[i].w = rect->width;
|
|
|
|
sdlrects[i].h = rect->height;
|
|
|
|
++i;
|
|
|
|
}
|
|
|
|
SDL_UpdateRects (screen, n, sdlrects);
|
2000-07-11 07:51:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2001-02-09 02:53:09 +00:00
|
|
|
D_BeginDirectRect
|
2000-07-11 07:51:36 +00:00
|
|
|
*/
|
2000-10-13 05:36:46 +00:00
|
|
|
void
|
2000-12-08 06:51:37 +00:00
|
|
|
D_BeginDirectRect (int x, int y, byte * pbitmap, int width, int height)
|
2000-07-11 07:51:36 +00:00
|
|
|
{
|
2000-12-08 06:51:37 +00:00
|
|
|
Uint8 *offset;
|
|
|
|
|
|
|
|
|
|
|
|
if (!screen)
|
|
|
|
return;
|
|
|
|
if (x < 0)
|
|
|
|
x = screen->w + x - 1;
|
|
|
|
offset = (Uint8 *) screen->pixels + y * screen->pitch + x;
|
|
|
|
while (height--) {
|
|
|
|
memcpy (offset, pbitmap, width);
|
|
|
|
offset += screen->pitch;
|
|
|
|
pbitmap += width;
|
|
|
|
}
|
2000-07-11 07:51:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2001-02-09 02:53:09 +00:00
|
|
|
D_EndDirectRect
|
2000-07-11 07:51:36 +00:00
|
|
|
*/
|
2000-10-13 05:36:46 +00:00
|
|
|
void
|
|
|
|
D_EndDirectRect (int x, int y, int width, int height)
|
2000-07-11 07:51:36 +00:00
|
|
|
{
|
2000-12-08 06:51:37 +00:00
|
|
|
if (!screen)
|
|
|
|
return;
|
|
|
|
if (x < 0)
|
|
|
|
x = screen->w + x - 1;
|
|
|
|
SDL_UpdateRect (screen, x, y, width, height);
|
2000-07-11 07:51:36 +00:00
|
|
|
}
|
|
|
|
|
2000-12-08 06:51:37 +00:00
|
|
|
void
|
|
|
|
VID_LockBuffer (void)
|
2000-07-11 07:51:36 +00:00
|
|
|
{
|
2000-12-08 06:51:37 +00:00
|
|
|
}
|
2000-07-11 07:51:36 +00:00
|
|
|
|
2000-10-14 07:10:56 +00:00
|
|
|
void
|
2000-12-08 06:51:37 +00:00
|
|
|
VID_UnlockBuffer (void)
|
2000-07-11 07:51:36 +00:00
|
|
|
{
|
2000-12-08 06:51:37 +00:00
|
|
|
}
|
2000-07-11 07:51:36 +00:00
|
|
|
|
2000-07-14 17:16:08 +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);
|
|
|
|
|
|
|
|
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-12-08 06:51:37 +00:00
|
|
|
SDL_WM_SetCaption (va ("%s %s", PROGRAM, VERSION), NULL);
|
2000-10-04 05:45:48 +00:00
|
|
|
}
|
2000-07-14 17:16:08 +00:00
|
|
|
}
|
2001-04-23 03:52:20 +00:00
|
|
|
|
|
|
|
qboolean
|
|
|
|
VID_SetGamma (double gamma)
|
|
|
|
{
|
|
|
|
// return SDL_SetGamma ((float) gamma, (float) gamma, (float) gamma);
|
|
|
|
return false; // FIXME
|
|
|
|
}
|