2001-04-15 04:18:22 +00:00
|
|
|
/*
|
|
|
|
vid_sdl.c
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
|
*/
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
# include "config.h"
|
|
|
|
#endif
|
2003-01-15 15:31:36 +00:00
|
|
|
|
2005-08-04 15:27:09 +00:00
|
|
|
static __attribute__ ((used)) const char rcsid[] =
|
2003-01-15 15:31:36 +00:00
|
|
|
"$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
|
|
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <SDL.h>
|
|
|
|
|
|
|
|
#include "QF/console.h"
|
|
|
|
#include "QF/cvar.h"
|
|
|
|
#include "QF/qendian.h"
|
|
|
|
#include "QF/sys.h"
|
|
|
|
#include "QF/vid.h"
|
|
|
|
|
2003-01-06 18:28:13 +00:00
|
|
|
#include "d_iface.h"
|
2012-02-17 07:13:56 +00:00
|
|
|
#include "vid_internal.h"
|
2003-01-06 18:28:13 +00:00
|
|
|
|
2004-01-20 03:47:27 +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
|
|
|
|
|
|
|
|
// The original defaults
|
2002-08-21 00:05:27 +00:00
|
|
|
#define BASEWIDTH 320
|
|
|
|
#define BASEHEIGHT 200
|
2001-04-15 04:18:22 +00:00
|
|
|
|
|
|
|
byte *VGA_pagebase;
|
2001-11-02 06:35:32 +00:00
|
|
|
int VGA_width, VGA_height, VGA_rowbytes, VGA_bufferrowbytes = 0;
|
2001-04-15 04:18:22 +00:00
|
|
|
|
2002-08-21 00:05:27 +00:00
|
|
|
SDL_Surface *screen = NULL;
|
2001-04-15 04:18:22 +00:00
|
|
|
|
2001-11-02 06:35:32 +00:00
|
|
|
|
2001-04-15 04:18:22 +00:00
|
|
|
void
|
2012-02-26 05:00:15 +00:00
|
|
|
VID_SetPalette (const byte *palette)
|
2001-04-15 04:18:22 +00:00
|
|
|
{
|
|
|
|
SDL_Color colors[256];
|
2002-08-21 06:00:08 +00:00
|
|
|
int i;
|
2001-04-15 04:18:22 +00:00
|
|
|
|
|
|
|
for (i = 0; i < 256; ++i) {
|
|
|
|
colors[i].r = *palette++;
|
|
|
|
colors[i].g = *palette++;
|
|
|
|
colors[i].b = *palette++;
|
|
|
|
}
|
|
|
|
SDL_SetColors (screen, colors, 0, 256);
|
|
|
|
}
|
|
|
|
|
2001-10-21 03:48:02 +00:00
|
|
|
static void
|
|
|
|
do_screen_buffer (void)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2001-04-15 04:18:22 +00:00
|
|
|
void
|
2012-02-01 10:52:13 +00:00
|
|
|
VID_Init (byte *palette, byte *colormap)
|
2001-04-15 04:18:22 +00:00
|
|
|
{
|
|
|
|
Uint32 flags;
|
|
|
|
|
|
|
|
// Load the SDL library
|
2001-08-25 05:54:21 +00:00
|
|
|
if (SDL_Init (SDL_INIT_VIDEO) < 0)
|
2001-04-15 04:18:22 +00:00
|
|
|
Sys_Error ("VID: Couldn't load SDL: %s", SDL_GetError ());
|
|
|
|
|
2012-04-10 04:27:53 +00:00
|
|
|
R_LoadModule ();
|
|
|
|
|
2001-04-15 04:18:22 +00:00
|
|
|
// Set up display mode (width and height)
|
|
|
|
VID_GetWindowSize (BASEWIDTH, BASEHEIGHT);
|
|
|
|
|
|
|
|
// Set video width, height and flags
|
|
|
|
flags = (SDL_SWSURFACE | SDL_HWPALETTE);
|
|
|
|
if (vid_fullscreen->int_val)
|
|
|
|
flags |= SDL_FULLSCREEN;
|
|
|
|
|
|
|
|
// Initialize display
|
2012-02-14 10:47:02 +00:00
|
|
|
if (!(screen = SDL_SetVideoMode (viddef.width, viddef.height, 8, flags)))
|
2002-05-14 06:12:29 +00:00
|
|
|
Sys_Error ("VID: Couldn't set video mode: %s", SDL_GetError ());
|
2012-02-01 10:52:13 +00:00
|
|
|
|
2001-04-15 04:18:22 +00:00
|
|
|
VID_InitGamma (palette);
|
2012-02-14 10:47:02 +00:00
|
|
|
VID_SetPalette (viddef.palette);
|
2001-04-15 04:18:22 +00:00
|
|
|
|
|
|
|
// now know everything we need to know about the buffer
|
2012-02-14 10:47:02 +00:00
|
|
|
VGA_width = viddef.width;
|
|
|
|
VGA_height = viddef.height;
|
|
|
|
viddef.numpages = 1;
|
2012-02-17 07:13:56 +00:00
|
|
|
viddef.colormap8 = colormap;
|
2012-02-14 10:47:02 +00:00
|
|
|
viddef.fullbright = 256 - viddef.colormap8[256 * VID_GRADES];
|
|
|
|
viddef.do_screen_buffer = do_screen_buffer;
|
|
|
|
VGA_pagebase = viddef.buffer = screen->pixels;
|
|
|
|
VGA_rowbytes = viddef.rowbytes = screen->pitch;
|
|
|
|
viddef.conbuffer = viddef.buffer;
|
|
|
|
viddef.conrowbytes = viddef.rowbytes;
|
|
|
|
viddef.direct = 0;
|
2001-04-15 04:18:22 +00:00
|
|
|
|
2002-08-21 06:00:08 +00:00
|
|
|
VID_InitBuffers (); // allocate z buffer and surface cache
|
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
|
|
|
|
2004-01-20 03:47:27 +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-08-21 06:00:08 +00:00
|
|
|
// SDL_GetWMInfo(&info);
|
|
|
|
// mainwindow=info.window;
|
|
|
|
mainwindow=GetActiveWindow();
|
2001-04-15 04:18:22 +00:00
|
|
|
#endif
|
|
|
|
|
2012-02-14 10:47:02 +00:00
|
|
|
viddef.initialized = true;
|
2001-04-15 04:18:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
VID_Update (vrect_t *rects)
|
|
|
|
{
|
2012-02-15 12:49:13 +00:00
|
|
|
static SDL_Rect *sdlrects;
|
|
|
|
static int num_sdlrects;
|
2002-08-21 06:00:08 +00:00
|
|
|
int i, n;
|
2001-04-15 04:18:22 +00:00
|
|
|
vrect_t *rect;
|
|
|
|
|
|
|
|
// Two-pass system, since Quake doesn't do it the SDL way...
|
|
|
|
|
|
|
|
// First, count the number of rectangles
|
|
|
|
n = 0;
|
2012-01-06 00:52:14 +00:00
|
|
|
for (rect = rects; rect; rect = rect->next)
|
2001-04-15 04:18:22 +00:00
|
|
|
++n;
|
|
|
|
|
2012-02-15 12:49:13 +00:00
|
|
|
if (n > num_sdlrects) {
|
|
|
|
num_sdlrects = n;
|
|
|
|
sdlrects = realloc (sdlrects, n * sizeof (SDL_Rect));
|
|
|
|
if (!sdlrects)
|
|
|
|
Sys_Error ("Out of memory!");
|
|
|
|
}
|
|
|
|
|
2001-04-15 04:18:22 +00:00
|
|
|
// Second, copy them to SDL rectangles and update
|
|
|
|
i = 0;
|
2012-01-06 00:52:14 +00:00
|
|
|
for (rect = rects; rect; rect = rect->next) {
|
2001-04-15 04:18:22 +00:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2012-02-15 12:49:13 +00:00
|
|
|
D_BeginDirectRect (int x, int y, byte *pbitmap, int width, int height)
|
2001-04-15 04:18:22 +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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
D_EndDirectRect (int x, int y, int width, int height)
|
|
|
|
{
|
|
|
|
if (!screen)
|
|
|
|
return;
|
|
|
|
if (x < 0)
|
|
|
|
x = screen->w + x - 1;
|
|
|
|
SDL_UpdateRect (screen, x, y, width, height);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
VID_LockBuffer (void)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
VID_UnlockBuffer (void)
|
|
|
|
{
|
|
|
|
}
|