qboolean vid_supportrefreshrate = false;
-#if SDL_MAJOR_VERSION == 1 && SDL_MINOR_VERSION == 2
-# define SETVIDEOMODE 1
-#else
-# ifdef USE_GLES2
-# define SETVIDEOMODE 0
-# else
-// LordHavoc: SDL 1.3's SDL_CreateWindow API is not finished enough to use yet, but you can set this to 0 if you want to try it...
-# ifndef SETVIDEOMODE
-# define SETVIDEOMODE 1
-# endif
-# endif
-# endif
-
static qboolean vid_usingmouse = false;
static qboolean vid_usinghidecursor = false;
static qboolean vid_hasfocus = false;
static qboolean vid_isfullscreen;
-#if SDL_MAJOR_VERSION == 1 && SDL_MINOR_VERSION == 2
-#else
+#if SDL_MAJOR_VERSION != 1
static qboolean vid_usingvsync = false;
#endif
static SDL_Joystick *vid_sdljoystick = NULL;
static int win_half_height = 50;
static int video_bpp;
-#if SETVIDEOMODE
+#if SDL_MAJOR_VERSION == 1
static SDL_Surface *screen;
static int video_flags;
#else
case SDLK_F10: return K_F10;
case SDLK_F11: return K_F11;
case SDLK_F12: return K_F12;
+#if SDL_MAJOR_VERSION == 1
case SDLK_PRINTSCREEN: return K_PRINTSCREEN;
case SDLK_SCROLLLOCK: return K_SCROLLOCK;
+#endif
case SDLK_PAUSE: return K_PAUSE;
case SDLK_INSERT: return K_INS;
case SDLK_HOME: return K_HOME;
case SDLK_LEFT: return K_LEFTARROW;
case SDLK_DOWN: return K_DOWNARROW;
case SDLK_UP: return K_UPARROW;
+#if SDL_MAJOR_VERSION == 1
case SDLK_NUMLOCKCLEAR: return K_NUMLOCK;
+#endif
case SDLK_KP_DIVIDE: return K_KP_DIVIDE;
case SDLK_KP_MULTIPLY: return K_KP_MULTIPLY;
case SDLK_KP_MINUS: return K_KP_MINUS;
case SDLK_KP_PLUS: return K_KP_PLUS;
case SDLK_KP_ENTER: return K_KP_ENTER;
+#if SDL_MAJOR_VERSION == 1
case SDLK_KP_1: return K_KP_1;
case SDLK_KP_2: return K_KP_2;
case SDLK_KP_3: return K_KP_3;
case SDLK_KP_8: return K_KP_8;
case SDLK_KP_9: return K_KP_9;
case SDLK_KP_0: return K_KP_0;
+#endif
case SDLK_KP_PERIOD: return K_KP_PERIOD;
// case SDLK_APPLICATION: return K_APPLICATION;
// case SDLK_POWER: return K_POWER;
{
vid_usingmouse = relative;
cl_ignoremousemoves = 2;
-#if SETVIDEOMODE
+#if SDL_MAJOR_VERSION == 1
SDL_WM_GrabInput( relative ? SDL_GRAB_ON : SDL_GRAB_OFF );
#else
SDL_SetRelativeMouseMode(relative ? SDL_TRUE : SDL_FALSE);
// we need 2 frames to initialize the center position
if(!stuck)
{
-#if SETVIDEOMODE
+#if SDL_MAJOR_VERSION == 1
SDL_WarpMouse(win_half_width, win_half_height);
#else
SDL_WarpMouseInWindow(window, win_half_width, win_half_height);
SDL_GetMouseState(&x, &y);
old_x = x - win_half_width;
old_y = y - win_half_height;
-#if SETVIDEOMODE
+#if SDL_MAJOR_VERSION == 1
SDL_WarpMouse(win_half_width, win_half_height);
#else
SDL_WarpMouseInWindow(window, win_half_width, win_half_height);
};
#endif
-#if SETVIDEOMODE
-// SDL 1.2
+#if SDL_MAJOR_VERSION == 1
+// SDL
void Sys_SendKeyEvents( void )
{
static qboolean sound_active = true;
#endif
}
break;
-#if SDL_MAJOR_VERSION == 1 && SDL_MINOR_VERSION == 2
-#else
+#if SDL_MAJOR_VERSION != 1
case SDL_TEXTEDITING:
- // unused when SETVIDEOMODE API is used
break;
case SDL_TEXTINPUT:
- // this occurs with SETVIDEOMODE but we are not using it
break;
#endif
case SDL_MOUSEMOTION:
#else
-// SDL 1.3
+// SDL2
void Sys_SendKeyEvents( void )
{
static qboolean sound_active = true;
- static qboolean missingunicodehack = true;
int keycode;
int i;
int j;
case SDL_JOYBALLMOTION:
case SDL_JOYHATMOTION:
break;
- case SDL_VIDEOEXPOSE:
- break;
case SDL_WINDOWEVENT:
//if (event.window.windowID == window) // how to compare?
{
SDL_FreeSurface(vid_softsurface);
vid_softsurface = SDL_CreateRGBSurface(SDL_SWSURFACE, vid.width, vid.height, 32, 0x00FF0000, 0x0000FF00, 0x000000FF, 0xFF000000);
vid.softpixels = (unsigned int *)vid_softsurface->pixels;
- SDL_SetAlpha(vid_softsurface, 0, 255);
if (vid.softdepthpixels)
free(vid.softdepthpixels);
vid.softdepthpixels = (unsigned int*)calloc(1, vid.width * vid.height * 4);
break;
case SDL_TEXTINPUT:
// we have some characters to parse
- missingunicodehack = false;
{
unicode = 0;
for (i = 0;event.text.text[i];)
void wrapglGetVertexAttribPointerv(GLuint index, GLenum pname, GLvoid **pointer) {PRECALL;glGetVertexAttribPointerv(index, pname, pointer);POSTCALL;}
#endif
-#if SDL_MAJOR_VERSION == 1 && SDL_MINOR_VERSION == 2
+#if SDL_MAJOR_VERSION == 1
#define SDL_GL_ExtensionSupported(x) (strstr(gl_extensions, x) || strstr(gl_platformextensions, x))
#endif
Cvar_SetValueQuick(&joy_active, success ? 1 : 0);
}
-#if SETVIDEOMODE
+#if SDL_MAJOR_VERSION == 1
// set the icon (we dont use SDL here since it would be too much a PITA)
#ifdef WIN32
#include "resource.h"
SDL_WM_SetCaption( gamename, NULL );
screen = SDL_SetVideoMode(screenwidth, screenheight, screenbpp, screenflags);
-#if SDL_MAJOR_VERSION == 1 && SDL_MINOR_VERSION == 2
+#if SDL_MAJOR_VERSION == 1
// LordHavoc: info.info.x11.lock_func and accompanying code do not seem to compile with SDL 1.3
#if SDL_VIDEO_DRIVER_X11 && !SDL_VIDEO_DRIVER_QUARTZ
static void VID_OutputVersion(void)
{
- const SDL_version *version;
- version = SDL_Linked_Version();
+ SDL_version version;
+#if SDL_MAJOR_VERSION == 1
+ version = *SDL_Linked_Version();
+#else
+ SDL_GetVersion(&version);
+#endif
Con_Printf( "Linked against SDL version %d.%d.%d\n"
"Using SDL library version %d.%d.%d\n",
SDL_MAJOR_VERSION, SDL_MINOR_VERSION, SDL_PATCHLEVEL,
- version->major, version->minor, version->patch );
+ version.major, version.minor, version.patch );
}
static qboolean VID_InitModeGL(viddef_mode_t *mode)
{
int i;
-#if SETVIDEOMODE
+#if SDL_MAJOR_VERSION == 1
static int notfirstvideomode = false;
int flags = SDL_OPENGL;
#else
win_half_height = mode->height>>1;
if(vid_resizable.integer)
-#if SETVIDEOMODE
+#if SDL_MAJOR_VERSION == 1
flags |= SDL_RESIZABLE;
#else
windowflags |= SDL_WINDOW_RESIZABLE;
VID_OutputVersion();
-#if SETVIDEOMODE
+#if SDL_MAJOR_VERSION == 1
/*
SDL 1.2 Hack
We cant switch from one OpenGL video mode to another.
vid_isfullscreen = false;
if (mode->fullscreen) {
-#if SETVIDEOMODE
+#if SDL_MAJOR_VERSION == 1
flags |= SDL_FULLSCREEN;
#else
windowflags |= SDL_WINDOW_FULLSCREEN;
SDL_GL_SetAttribute (SDL_GL_MULTISAMPLESAMPLES, mode->samples);
}
-#if SDL_MAJOR_VERSION == 1 && SDL_MINOR_VERSION == 2
+#if SDL_MAJOR_VERSION == 1
if (vid_vsync.integer)
SDL_GL_SetAttribute (SDL_GL_SWAP_CONTROL, 1);
else
#endif
video_bpp = mode->bitsperpixel;
-#if SETVIDEOMODE
+#if SDL_MAJOR_VERSION == 1
video_flags = flags;
screen = VID_WrapSDL_SetVideoMode(mode->width, mode->height, mode->bitsperpixel, flags);
if (screen == NULL)
vid_softsurface = NULL;
vid.softpixels = NULL;
+#if SDL_MAJOR_VERSION == 1
// init keyboard
SDL_EnableUNICODE( SDL_ENABLE );
// enable key repeat since everyone expects it
SDL_EnableKeyRepeat(SDL_DEFAULT_REPEAT_DELAY, SDL_DEFAULT_REPEAT_INTERVAL);
+#endif
-#if !(SDL_MAJOR_VERSION == 1 && SDL_MINOR_VERSION == 2)
+#if SDL_MAJOR_VERSION != 1
SDL_GL_SetSwapInterval(vid_vsync.integer != 0);
vid_usingvsync = (vid_vsync.integer != 0);
#endif
vid_usingmouse = false;
vid_usinghidecursor = false;
-#if SETVIDEOMODE
+#if SDL_MAJOR_VERSION == 1
SDL_WM_GrabInput(SDL_GRAB_OFF);
#endif
return true;
static qboolean VID_InitModeSoft(viddef_mode_t *mode)
{
-#if SETVIDEOMODE
+#if SDL_MAJOR_VERSION == 1
int flags = SDL_HWSURFACE;
if(!COM_CheckParm("-noasyncblit")) flags |= SDL_ASYNCBLIT;
#else
win_half_height = mode->height>>1;
if(vid_resizable.integer)
-#if SETVIDEOMODE
+#if SDL_MAJOR_VERSION == 1
flags |= SDL_RESIZABLE;
#else
windowflags |= SDL_WINDOW_RESIZABLE;
vid_isfullscreen = false;
if (mode->fullscreen) {
-#if SETVIDEOMODE
+#if SDL_MAJOR_VERSION == 1
flags |= SDL_FULLSCREEN;
#else
windowflags |= SDL_WINDOW_FULLSCREEN;
}
video_bpp = mode->bitsperpixel;
-#if SETVIDEOMODE
+#if SDL_MAJOR_VERSION == 1
video_flags = flags;
screen = VID_WrapSDL_SetVideoMode(mode->width, mode->height, mode->bitsperpixel, flags);
if (screen == NULL)
VID_Shutdown();
return false;
}
+#if SDL_MAJOR_VERSION == 1
SDL_SetAlpha(vid_softsurface, 0, 255);
+#endif
vid.softpixels = (unsigned int *)vid_softsurface->pixels;
vid.softdepthpixels = (unsigned int *)calloc(1, mode->width * mode->height * 4);
return false;
}
+#if SDL_MAJOR_VERSION == 1
// init keyboard
SDL_EnableUNICODE( SDL_ENABLE );
// enable key repeat since everyone expects it
SDL_EnableKeyRepeat(SDL_DEFAULT_REPEAT_DELAY, SDL_DEFAULT_REPEAT_INTERVAL);
+#endif
VID_Soft_SharedSetup();
vid_usingmouse = false;
vid_usinghidecursor = false;
-#if SETVIDEOMODE
+#if SDL_MAJOR_VERSION == 1
SDL_WM_GrabInput(SDL_GRAB_OFF);
#endif
return true;
VID_SetMouse(false, false, false);
VID_RestoreSystemGamma();
-#if SETVIDEOMODE
+#if SDL_MAJOR_VERSION == 1
#ifndef WIN32
#ifndef MACOSX
if (icon)
free(vid.softdepthpixels);
vid.softdepthpixels = NULL;
-#if SETVIDEOMODE
-#else
+#if SDL_MAJOR_VERSION != 1
SDL_DestroyWindow(window);
window = NULL;
#endif
int VID_SetGamma (unsigned short *ramps, int rampsize)
{
+#if SDL_MAJOR_VERSION == 1
return !SDL_SetGammaRamp (ramps, ramps + rampsize, ramps + rampsize*2);
+#else
+ return !SDL_SetWindowGammaRamp (window, ramps, ramps + rampsize, ramps + rampsize*2);
+#endif
}
int VID_GetGamma (unsigned short *ramps, int rampsize)
{
+#if SDL_MAJOR_VERSION == 1
return !SDL_GetGammaRamp (ramps, ramps + rampsize, ramps + rampsize*2);
+#else
+ return !SDL_GetWindowGammaRamp (window, ramps, ramps + rampsize, ramps + rampsize*2);
+#endif
}
void VID_Finish (void)
{
-#if SETVIDEOMODE
+#if SDL_MAJOR_VERSION == 1
Uint8 appstate;
//react on appstate changes
CHECKGLERROR
if (r_speeds.integer == 2 || gl_finish.integer)
GL_Finish();
-#if SDL_MAJOR_VERSION == 1 && SDL_MINOR_VERSION == 2
-#else
+#if SDL_MAJOR_VERSION != 1
{
qboolean vid_usevsync;
vid_usevsync = (vid_vsync.integer && !cls.timedemo);
}
}
#endif
-#if SETVIDEOMODE
+#if SDL_MAJOR_VERSION == 1
SDL_GL_SwapBuffers();
#else
SDL_GL_SwapWindow(window);
break;
case RENDERPATH_SOFT:
DPSOFTRAST_Finish();
-#if SETVIDEOMODE
+#if SDL_MAJOR_VERSION == 1
// if (!r_test.integer)
{
SDL_BlitSurface(vid_softsurface, NULL, screen, NULL);
size_t VID_ListModes(vid_mode_t *modes, size_t maxcount)
{
- size_t k;
+ size_t k = 0;
+#if SDL_MAJOR_VERSION == 1
SDL_Rect **vidmodes;
int bpp = SDL_GetVideoInfo()->vfmt->BitsPerPixel;
- k = 0;
for(vidmodes = SDL_ListModes(NULL, SDL_FULLSCREEN|SDL_HWSURFACE); vidmodes && vidmodes != (SDL_Rect**)(-1) && *vidmodes; ++vidmodes)
{
if(k >= maxcount)
modes[k].pixelheight_denom = 1; // SDL does not provide this
++k;
}
+#else
+ int modenum;
+ int nummodes = SDL_GetNumDisplayModes(0);
+ SDL_DisplayMode mode;
+ for (modenum = 0;modenum < nummodes;modenum++)
+ {
+ if (k >= maxcount)
+ break;
+ if (SDL_GetDisplayMode(0, modenum, &mode))
+ continue;
+ modes[k].width = mode.w;
+ modes[k].height = mode.h;
+ modes[k].refreshrate = mode.refresh_rate;
+ modes[k].pixelheight_num = 1;
+ modes[k].pixelheight_num = 1;
+ modes[k].pixelheight_denom = 1; // SDL does not provide this
+ k++;
+ }
+#endif
return k;
}