]> de.git.xonotic.org Git - xonotic/darkplaces.git/blobdiff - vid_sdl.c
only include SDL_syswm.h if really necessary
[xonotic/darkplaces.git] / vid_sdl.c
index 9af5f2c30af66a77b43792f622d553d5c16120ea..aed184b1ff3f10b4f4829becee6da169cd92f735 100644 (file)
--- a/vid_sdl.c
+++ b/vid_sdl.c
@@ -18,7 +18,6 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 */
 #undef WIN32_LEAN_AND_MEAN  //hush a warning, SDL.h redefines this
 #include <SDL.h>
-#include <SDL_syswm.h>
 #include <stdio.h>
 
 #include "quakedef.h"
@@ -66,25 +65,12 @@ int cl_available = true;
 
 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_usingmouse_relativeworks = false; // SDL2 workaround for unimplemented RelativeMouse mode
 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;
@@ -93,7 +79,7 @@ static int win_half_width = 50;
 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
@@ -213,8 +199,10 @@ static int MapKey( unsigned int sdlkey )
        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;
@@ -230,12 +218,15 @@ static int MapKey( unsigned int sdlkey )
        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;
@@ -246,6 +237,7 @@ static int MapKey( unsigned int sdlkey )
        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;
@@ -380,7 +372,7 @@ SDL_bool SDL_iPhoneKeyboardIsShown(SDL_Window * window);  // returns whether or
 int SDL_iPhoneKeyboardToggle(SDL_Window * window); // toggles the visibility of the onscreen keyboard.  Returns 0 on success and -1 on error.
 #endif
 
-void VID_ShowKeyboard(qboolean show)
+static void VID_ShowKeyboard(qboolean show)
 {
 #ifdef __IPHONEOS__
        if (show)
@@ -415,10 +407,11 @@ void VID_SetMouse(qboolean fullscreengrab, qboolean relative, qboolean hidecurso
        {
                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);
+               vid_usingmouse_relativeworks = SDL_SetRelativeMouseMode(relative ? SDL_TRUE : SDL_FALSE) == 0;
+//             Con_Printf("VID_SetMouse(%i, %i, %i) relativeworks = %i\n", (int)fullscreengrab, (int)relative, (int)hidecursor, (int)vid_usingmouse_relativeworks);
 #endif
 #ifdef MACOSX
                if(relative)
@@ -486,7 +479,7 @@ void VID_SetMouse(qboolean fullscreengrab, qboolean relative, qboolean hidecurso
 #define MAXFINGERS 11
 int multitouch[MAXFINGERS][3];
 
-qboolean VID_TouchscreenArea(int corner, float px, float py, float pwidth, float pheight, const char *icon, float *resultmove, qboolean *resultbutton, keynum_t key)
+static qboolean VID_TouchscreenArea(int corner, float px, float py, float pwidth, float pheight, const char *icon, float *resultmove, qboolean *resultbutton, keynum_t key)
 {
        int finger;
        float fx, fy, fwidth, fheight;
@@ -580,7 +573,7 @@ void IN_Move( void )
        scr_numtouchscreenareas = 0;
        if (vid_touchscreen.integer)
        {
-               vec3_t move, aim, click;
+               float move[3], aim[3], click[3];
                static qboolean buttons[16];
                static keydest_t oldkeydest;
                keydest_t keydest = (key_consoleactive & KEY_CONSOLEACTIVE_USER) ? key_console : key_dest;
@@ -667,7 +660,7 @@ void IN_Move( void )
        {
                if (vid_usingmouse)
                {
-                       if (vid_stick_mouse.integer)
+                       if (vid_stick_mouse.integer || !vid_usingmouse_relativeworks)
                        {
                                // have the mouse stuck in the middle, example use: prevent expose effect of beryl during the game when not using
                                // window grabbing. --blub
@@ -675,7 +668,7 @@ void IN_Move( void )
                                // 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);
@@ -690,7 +683,7 @@ void IN_Move( void )
                                        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);
@@ -754,8 +747,8 @@ static keynum_t buttonremap[18] =
 };
 #endif
 
-#if SETVIDEOMODE
-// SDL 1.2
+#if SDL_MAJOR_VERSION == 1
+// SDL
 void Sys_SendKeyEvents( void )
 {
        static qboolean sound_active = true;
@@ -825,13 +818,10 @@ void Sys_SendKeyEvents( void )
 #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:
@@ -862,11 +852,10 @@ void Sys_SendKeyEvents( void )
 
 #else
 
-// SDL 1.3
+// SDL2
 void Sys_SendKeyEvents( void )
 {
        static qboolean sound_active = true;
-       static qboolean missingunicodehack = true;
        int keycode;
        int i;
        int j;
@@ -898,8 +887,6 @@ void Sys_SendKeyEvents( void )
                        case SDL_JOYBALLMOTION:
                        case SDL_JOYHATMOTION:
                                break;
-                       case SDL_VIDEOEXPOSE:
-                               break;
                        case SDL_WINDOWEVENT:
                                //if (event.window.windowID == window) // how to compare?
                                {
@@ -925,7 +912,6 @@ void Sys_SendKeyEvents( void )
                                                                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);
@@ -968,7 +954,6 @@ void Sys_SendKeyEvents( void )
                                break;
                        case SDL_TEXTINPUT:
                                // we have some characters to parse
-                               missingunicodehack = false;
                                {
                                        unicode = 0;
                                        for (i = 0;event.text.text[i];)
@@ -1305,7 +1290,7 @@ void wrapglGetVertexAttribiv(GLuint index, GLenum pname, GLint *params) {PRECALL
 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
 
@@ -1572,6 +1557,15 @@ void GLES_Init(void)
        vid.support.ext_blend_subtract = true;
        vid.support.ext_draw_range_elements = true;
        vid.support.ext_framebuffer_object = false;//true;
+
+       // FIXME remove this workaround once FBO + npot texture mapping is fixed
+       if(!vid.support.arb_texture_non_power_of_two)
+       {
+               vid.support.arb_framebuffer_object = false;
+               vid.support.ext_framebuffer_object = false;
+       }
+
+       vid.support.ext_packed_depth_stencil = false;
        vid.support.ext_stencil_two_side = false;
        vid.support.ext_texture_3d = SDL_GL_ExtensionSupported("GL_OES_texture_3D");
        vid.support.ext_texture_compression_s3tc = SDL_GL_ExtensionSupported("GL_EXT_texture_compression_s3tc");
@@ -1724,7 +1718,7 @@ void VID_EnableJoystick(qboolean enable)
                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"
@@ -1772,6 +1766,11 @@ static SDL_Surface *VID_WrapSDL_SetVideoMode(int screenwidth, int screenheight,
 // Adding the OS independent XPM version --blub
 #include "darkplaces.xpm"
 #include "nexuiz.xpm"
+#if SDL_MAJOR_VERSION == 1
+#if SDL_VIDEO_DRIVER_X11 && !SDL_VIDEO_DRIVER_QUARTZ
+#include <SDL_syswm.h>
+#endif
+#endif
 static SDL_Surface *icon = NULL;
 static SDL_Surface *VID_WrapSDL_SetVideoMode(int screenwidth, int screenheight, int screenbpp, int screenflags)
 {
@@ -1810,7 +1809,7 @@ static SDL_Surface *VID_WrapSDL_SetVideoMode(int screenwidth, int screenheight,
 
                        // reallocate with malloc, as this is in tempmempool (do not want)
                        xpm = data;
-                       data = malloc(width * height * 4);
+                       data = (char *) malloc(width * height * 4);
                        memcpy(data, xpm, width * height * 4);
                        Mem_Free(xpm);
                        xpm = NULL;
@@ -1942,7 +1941,7 @@ static SDL_Surface *VID_WrapSDL_SetVideoMode(int screenwidth, int screenheight,
        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
 
@@ -1964,6 +1963,7 @@ static SDL_Surface *VID_WrapSDL_SetVideoMode(int screenwidth, int screenheight,
                                static long netwm_icon[MAX_NETWM_ICON];
                                int pos = 0;
                                int i = 1;
+                               char vabuf[1024];
 
                                while(data)
                                {
@@ -1981,7 +1981,7 @@ static SDL_Surface *VID_WrapSDL_SetVideoMode(int screenwidth, int screenheight,
                                        }
                                        ++i;
                                        Mem_Free(data);
-                                       data = (char *) loadimagepixelsbgra(va("darkplaces-icon%d", i), false, false, false, NULL);
+                                       data = (char *) loadimagepixelsbgra(va(vabuf, sizeof(vabuf), "darkplaces-icon%d", i), false, false, false, NULL);
                                }
 
                                info.info.x11.lock_func();
@@ -2003,18 +2003,22 @@ static SDL_Surface *VID_WrapSDL_SetVideoMode(int screenwidth, int screenheight,
 
 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 );
 }
 
-qboolean VID_InitModeGL(viddef_mode_t *mode)
+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
@@ -2026,7 +2030,7 @@ qboolean VID_InitModeGL(viddef_mode_t *mode)
        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;
@@ -2034,7 +2038,7 @@ qboolean VID_InitModeGL(viddef_mode_t *mode)
 
        VID_OutputVersion();
 
-#if SETVIDEOMODE
+#if SDL_MAJOR_VERSION == 1
        /*
        SDL 1.2 Hack
                We cant switch from one OpenGL video mode to another.
@@ -2045,6 +2049,7 @@ qboolean VID_InitModeGL(viddef_mode_t *mode)
        notfirstvideomode = true;
 #endif
 
+#ifndef USE_GLES2
        // SDL usually knows best
        drivername = NULL;
 
@@ -2057,6 +2062,7 @@ qboolean VID_InitModeGL(viddef_mode_t *mode)
                Con_Printf("Unable to load GL driver \"%s\": %s\n", drivername, SDL_GetError());
                return false;
        }
+#endif
 
 #ifdef __IPHONEOS__
        // mobile platforms are always fullscreen, we'll get the resolution after opening the window
@@ -2077,7 +2083,7 @@ qboolean VID_InitModeGL(viddef_mode_t *mode)
 
        vid_isfullscreen = false;
        if (mode->fullscreen) {
-#if SETVIDEOMODE
+#if SDL_MAJOR_VERSION == 1
                flags |= SDL_FULLSCREEN;
 #else
                windowflags |= SDL_WINDOW_FULLSCREEN;
@@ -2111,7 +2117,7 @@ qboolean VID_InitModeGL(viddef_mode_t *mode)
                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
@@ -2125,7 +2131,7 @@ qboolean VID_InitModeGL(viddef_mode_t *mode)
 #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)
@@ -2158,12 +2164,14 @@ qboolean VID_InitModeGL(viddef_mode_t *mode)
        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
@@ -2183,7 +2191,7 @@ qboolean VID_InitModeGL(viddef_mode_t *mode)
        vid_usingmouse = false;
        vid_usinghidecursor = false;
                
-#if SETVIDEOMODE
+#if SDL_MAJOR_VERSION == 1
        SDL_WM_GrabInput(SDL_GRAB_OFF);
 #endif
        return true;
@@ -2196,9 +2204,9 @@ extern cvar_t gl_info_version;
 extern cvar_t gl_info_platform;
 extern cvar_t gl_info_driver;
 
-qboolean VID_InitModeSoft(viddef_mode_t *mode)
+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
@@ -2209,7 +2217,7 @@ qboolean VID_InitModeSoft(viddef_mode_t *mode)
        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;
@@ -2219,7 +2227,7 @@ qboolean VID_InitModeSoft(viddef_mode_t *mode)
 
        vid_isfullscreen = false;
        if (mode->fullscreen) {
-#if SETVIDEOMODE
+#if SDL_MAJOR_VERSION == 1
                flags |= SDL_FULLSCREEN;
 #else
                windowflags |= SDL_WINDOW_FULLSCREEN;
@@ -2228,7 +2236,7 @@ qboolean VID_InitModeSoft(viddef_mode_t *mode)
        }
 
        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)
@@ -2259,7 +2267,9 @@ qboolean VID_InitModeSoft(viddef_mode_t *mode)
                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);
@@ -2270,10 +2280,12 @@ qboolean VID_InitModeSoft(viddef_mode_t *mode)
                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();
 
@@ -2283,7 +2295,7 @@ qboolean VID_InitModeSoft(viddef_mode_t *mode)
        vid_usingmouse = false;
        vid_usinghidecursor = false;
 
-#if SETVIDEOMODE
+#if SDL_MAJOR_VERSION == 1
        SDL_WM_GrabInput(SDL_GRAB_OFF);
 #endif
        return true;
@@ -2307,7 +2319,7 @@ void VID_Shutdown (void)
        VID_SetMouse(false, false, false);
        VID_RestoreSystemGamma();
 
-#if SETVIDEOMODE
+#if SDL_MAJOR_VERSION == 1
 #ifndef WIN32
 #ifndef MACOSX
        if (icon)
@@ -2325,8 +2337,7 @@ void VID_Shutdown (void)
                free(vid.softdepthpixels);
        vid.softdepthpixels = NULL;
 
-#if SETVIDEOMODE
-#else
+#if SDL_MAJOR_VERSION != 1
        SDL_DestroyWindow(window);
        window = NULL;
 #endif
@@ -2341,17 +2352,25 @@ void VID_Shutdown (void)
 
 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
@@ -2376,8 +2395,7 @@ void VID_Finish (void)
                        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);
@@ -2390,7 +2408,7 @@ void VID_Finish (void)
        }
 }
 #endif
-#if SETVIDEOMODE
+#if SDL_MAJOR_VERSION == 1
                        SDL_GL_SwapBuffers();
 #else
                        SDL_GL_SwapWindow(window);
@@ -2398,7 +2416,7 @@ void VID_Finish (void)
                        break;
                case RENDERPATH_SOFT:
                        DPSOFTRAST_Finish();
-#if SETVIDEOMODE
+#if SDL_MAJOR_VERSION == 1
 //             if (!r_test.integer)
                {
                        SDL_BlitSurface(vid_softsurface, NULL, screen, NULL);
@@ -2424,11 +2442,11 @@ void VID_Finish (void)
 
 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)
@@ -2441,5 +2459,24 @@ size_t VID_ListModes(vid_mode_t *modes, size_t 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;
 }