]> git.lizzy.rs Git - irrlicht.git/blobdiff - source/Irrlicht/CIrrDeviceSDL.cpp
Split new GL3/GLES2 drivers
[irrlicht.git] / source / Irrlicht / CIrrDeviceSDL.cpp
index cad7dffb3d2b4c64e8d675894ee45e28fda7bc23..6ebf63b975ff7cb316879b9fca6a632b15f227bb 100644 (file)
@@ -2,13 +2,13 @@
 // This file is part of the "Irrlicht Engine".\r
 // For conditions of distribution and use, see copyright notice in irrlicht.h\r
 \r
-#include "IrrCompileConfig.h"\r
 \r
 #ifdef _IRR_COMPILE_WITH_SDL_DEVICE_\r
 \r
 #include "CIrrDeviceSDL.h"\r
 #include "IEventReceiver.h"\r
-#include "irrList.h"\r
+#include "IGUIElement.h"\r
+#include "IGUIEnvironment.h"\r
 #include "os.h"\r
 #include "CTimer.h"\r
 #include "irrString.h"\r
@@ -17,8 +17,7 @@
 #include <stdio.h>\r
 #include <stdlib.h>\r
 #include "SIrrCreationParameters.h"\r
-#include <SDL/SDL_syswm.h>\r
-#include <SDL/SDL_video.h>\r
+#include <SDL_video.h>\r
 \r
 #ifdef _IRR_EMSCRIPTEN_PLATFORM_\r
 #ifdef _IRR_COMPILE_WITH_OGLES2_\r
@@ -27,9 +26,9 @@
 #include <emscripten.h>\r
 #endif\r
 \r
-#ifdef _MSC_VER\r
-#pragma comment(lib, "SDL.lib")\r
-#endif // _MSC_VER\r
+#ifdef _IRR_COMPILE_WITH_OPENGL_\r
+#include "CSDLManager.h"\r
+#endif\r
 \r
 static int SDLDeviceInstances = 0;\r
 \r
@@ -37,22 +36,44 @@ namespace irr
 {\r
        namespace video\r
        {\r
-               #ifdef _IRR_COMPILE_WITH_DIRECT3D_9_\r
-               IVideoDriver* createDirectX9Driver(const irr::SIrrlichtCreationParameters& params,\r
-                       io::IFileSystem* io, HWND window);\r
+               #ifdef _IRR_COMPILE_WITH_OPENGL_\r
+               IVideoDriver* createOpenGLDriver(const SIrrlichtCreationParameters& params, io::IFileSystem* io, IContextManager* contextManager);\r
+               #else\r
+               static IVideoDriver* createOpenGLDriver(const SIrrlichtCreationParameters& params, io::IFileSystem* io, IContextManager* contextManager)\r
+               {\r
+                       os::Printer::log("No OpenGL support compiled in.", ELL_ERROR);\r
+                       return nullptr;\r
+               }\r
                #endif\r
 \r
-               #ifdef _IRR_COMPILE_WITH_OPENGL_\r
-               IVideoDriver* createOpenGLDriver(const SIrrlichtCreationParameters& params,\r
-                               io::IFileSystem* io, CIrrDeviceSDL* device);\r
+               #ifdef ENABLE_OPENGL3\r
+               IVideoDriver* createOpenGL3Driver(const SIrrlichtCreationParameters& params, io::IFileSystem* io, IContextManager* contextManager);\r
+               #else\r
+               static IVideoDriver* createOpenGL3Driver(const SIrrlichtCreationParameters& params, io::IFileSystem* io, IContextManager* contextManager)\r
+               {\r
+                       os::Printer::log("No OpenGL 3 support compiled in.", ELL_ERROR);\r
+                       return nullptr;\r
+               }\r
                #endif\r
 \r
-               #if defined(_IRR_COMPILE_WITH_OGLES2_) && defined(_IRR_EMSCRIPTEN_PLATFORM_)\r
-               IVideoDriver* createOGLES2Driver(const irr::SIrrlichtCreationParameters& params, io::IFileSystem* io, IContextManager* contextManager);\r
+               #ifdef _IRR_COMPILE_WITH_OGLES2_\r
+               IVideoDriver* createOGLES2Driver(const SIrrlichtCreationParameters& params, io::IFileSystem* io, IContextManager* contextManager);\r
+               #else\r
+               static IVideoDriver* createOGLES2Driver(const SIrrlichtCreationParameters& params, io::IFileSystem* io, IContextManager* contextManager)\r
+               {\r
+                       os::Printer::log("No OpenGL ES 2 support compiled in.", ELL_ERROR);\r
+                       return nullptr;\r
+               }\r
                #endif\r
 \r
-               #if defined(_IRR_COMPILE_WITH_WEBGL1_) && defined(_IRR_EMSCRIPTEN_PLATFORM_)\r
-               IVideoDriver* createWebGL1Driver(const irr::SIrrlichtCreationParameters& params, io::IFileSystem* io, IContextManager* contextManager);\r
+               #ifdef _IRR_COMPILE_WITH_WEBGL1_\r
+               IVideoDriver* createWebGL1Driver(const SIrrlichtCreationParameters& params, io::IFileSystem* io, IContextManager* contextManager);\r
+               #else\r
+               static IVideoDriver* createWebGL1Driver(const SIrrlichtCreationParameters& params, io::IFileSystem* io, IContextManager* contextManager)\r
+               {\r
+                       os::Printer::log("No WebGL 1 support compiled in.", ELL_ERROR);\r
+                       return nullptr;\r
+               }\r
                #endif\r
        } // end namespace video\r
 \r
@@ -111,34 +132,33 @@ EM_BOOL CIrrDeviceSDL::MouseLeaveCallback(int eventType, const EmscriptenMouseEv
 \r
        return EM_FALSE;\r
 }\r
+#endif\r
+\r
 \r
-bool CIrrDeviceSDL::isNoUnicodeKey(EKEY_CODE key) const\r
+bool CIrrDeviceSDL::keyIsKnownSpecial(EKEY_CODE key)\r
 {\r
        switch ( key )\r
        {\r
-               // keys which  should not be mapped to a Unicode char\r
-               case KEY_UNKNOWN:\r
-               case KEY_SHIFT:\r
-               case KEY_CONTROL:\r
-               case KEY_MENU:\r
+               // keys which are known to have safe special character interpretation\r
+               // could need changes over time (removals and additions!)\r
+               case KEY_RETURN:\r
                case KEY_PAUSE:\r
-               case KEY_CAPITAL:\r
                case KEY_ESCAPE:\r
                case KEY_PRIOR:\r
                case KEY_NEXT:\r
-               case KEY_END:\r
                case KEY_HOME:\r
+               case KEY_END:\r
                case KEY_LEFT:\r
                case KEY_UP:\r
                case KEY_RIGHT:\r
                case KEY_DOWN:\r
+               case KEY_TAB:\r
                case KEY_PRINT:\r
                case KEY_SNAPSHOT:\r
                case KEY_INSERT:\r
+               case KEY_BACK:\r
                case KEY_DELETE:\r
                case KEY_HELP:\r
-               case KEY_LWIN:\r
-               case KEY_RWIN:\r
                case KEY_APPS:\r
                case KEY_SLEEP:\r
                case KEY_F1:\r
@@ -167,27 +187,52 @@ bool CIrrDeviceSDL::isNoUnicodeKey(EKEY_CODE key) const
                case KEY_F24:\r
                case KEY_NUMLOCK:\r
                case KEY_SCROLL:\r
-               case KEY_LSHIFT:\r
-               case KEY_RSHIFT:\r
                case KEY_LCONTROL:\r
                case KEY_RCONTROL:\r
-               case KEY_LMENU:\r
-               case KEY_RMENU:\r
-               return true;\r
+                       return true;\r
 \r
-       default:\r
-               return false;\r
+               default:\r
+                       return false;\r
+       }\r
+}\r
+\r
+int CIrrDeviceSDL::findCharToPassToIrrlicht(int assumedChar, EKEY_CODE key) {\r
+       // SDL in-place ORs values with no character representation with 1<<30\r
+       // https://wiki.libsdl.org/SDL2/SDLKeycodeLookup\r
+       if (assumedChar & (1<<30))\r
+               return 0;\r
+\r
+       switch (key) {\r
+               case KEY_PRIOR:\r
+               case KEY_NEXT:\r
+               case KEY_HOME:\r
+               case KEY_END:\r
+               case KEY_LEFT:\r
+               case KEY_UP:\r
+               case KEY_RIGHT:\r
+               case KEY_DOWN:\r
+               case KEY_NUMLOCK:\r
+                       return 0;\r
+               default:\r
+                       return assumedChar;\r
        }\r
 }\r
-#endif\r
+\r
+void CIrrDeviceSDL::resetReceiveTextInputEvents() {\r
+       gui::IGUIElement *elem = GUIEnvironment->getFocus();\r
+       if (elem && elem->acceptsIME())\r
+               SDL_StartTextInput();\r
+       else\r
+               SDL_StopTextInput();\r
+}\r
 \r
 //! constructor\r
 CIrrDeviceSDL::CIrrDeviceSDL(const SIrrlichtCreationParameters& param)\r
        : CIrrDeviceStub(param),\r
-       Screen((SDL_Surface*)param.WindowId), SDL_Flags(SDL_ANYFORMAT),\r
+       Window((SDL_Window*)param.WindowId), SDL_Flags(0),\r
        MouseX(0), MouseY(0), MouseXRel(0), MouseYRel(0), MouseButtonStates(0),\r
        Width(param.WindowSize.Width), Height(param.WindowSize.Height),\r
-       Resizable(param.WindowResizable), WindowMinimized(false)\r
+       Resizable(param.WindowResizable == 1 ? true : false)\r
 {\r
        #ifdef _DEBUG\r
        setDebugName("CIrrDeviceSDL");\r
@@ -195,13 +240,13 @@ CIrrDeviceSDL::CIrrDeviceSDL(const SIrrlichtCreationParameters& param)
 \r
        if ( ++SDLDeviceInstances == 1 )\r
        {\r
-               // Initialize SDL... Timer for sleep, video for the obvious, and\r
-               // noparachute prevents SDL from catching fatal errors.\r
-               if (SDL_Init( SDL_INIT_TIMER|SDL_INIT_VIDEO|\r
+               u32 flags = SDL_INIT_TIMER | SDL_INIT_EVENTS;\r
+               if (CreationParams.DriverType != video::EDT_NULL)\r
+                       flags |= SDL_INIT_VIDEO;\r
 #if defined(_IRR_COMPILE_WITH_JOYSTICK_EVENTS_)\r
-                                       SDL_INIT_JOYSTICK|\r
+               flags |= SDL_INIT_JOYSTICK;\r
 #endif\r
-                                       SDL_INIT_NOPARACHUTE ) < 0)\r
+               if (SDL_Init(flags) < 0)\r
                {\r
                        os::Printer::log( "Unable to initialize SDL!", SDL_GetError());\r
                        Close = true;\r
@@ -210,22 +255,23 @@ CIrrDeviceSDL::CIrrDeviceSDL(const SIrrlichtCreationParameters& param)
                {\r
                        os::Printer::log("SDL initialized", ELL_INFORMATION);\r
                }\r
+       }\r
 \r
-#if defined(_IRR_WINDOWS_)\r
-               SDL_putenv("SDL_VIDEODRIVER=directx");\r
-#elif defined(_IRR_OSX_PLATFORM_)\r
-               SDL_putenv("SDL_VIDEODRIVER=Quartz");\r
-#elif !defined(_IRR_EMSCRIPTEN_PLATFORM_)\r
-               SDL_putenv("SDL_VIDEODRIVER=x11");\r
-#endif\r
+       // create keymap\r
+       createKeyMap();\r
+\r
+       // create window\r
+       if (CreationParams.DriverType != video::EDT_NULL)\r
+       {\r
+               // create the window, only if we do not use the null device\r
+               createWindow();\r
        }\r
 \r
-//     SDL_putenv("SDL_WINDOWID=");\r
 \r
        SDL_VERSION(&Info.version);\r
 \r
 #ifndef _IRR_EMSCRIPTEN_PLATFORM_\r
-       SDL_GetWMInfo(&Info);\r
+       SDL_GetWindowWMInfo(Window,&Info);\r
 #endif //_IRR_EMSCRIPTEN_PLATFORM_\r
        core::stringc sdlversion = "SDL Version ";\r
        sdlversion += Info.version.major;\r
@@ -235,45 +281,20 @@ CIrrDeviceSDL::CIrrDeviceSDL(const SIrrlichtCreationParameters& param)
        sdlversion += Info.version.patch;\r
 \r
        Operator = new COSOperator(sdlversion);\r
-       if ( SDLDeviceInstances == 1 )\r
-       {\r
+       if (SDLDeviceInstances == 1) {\r
                os::Printer::log(sdlversion.c_str(), ELL_INFORMATION);\r
        }\r
 \r
-       // create keymap\r
-       createKeyMap();\r
-       // enable key to character translation\r
-       SDL_EnableUNICODE(1);\r
-\r
-       (void)SDL_EnableKeyRepeat(SDL_DEFAULT_REPEAT_DELAY, SDL_DEFAULT_REPEAT_INTERVAL);\r
-\r
-       if ( CreationParams.Fullscreen )\r
-               SDL_Flags |= SDL_FULLSCREEN;\r
-       else if ( Resizable )\r
-               SDL_Flags |= SDL_RESIZABLE;\r
-       if (CreationParams.DriverType == video::EDT_OPENGL)\r
-               SDL_Flags |= SDL_OPENGL;\r
-       else if (CreationParams.Doublebuffer)\r
-               SDL_Flags |= SDL_DOUBLEBUF;\r
-#ifdef _IRR_EMSCRIPTEN_PLATFORM_\r
-       SDL_Flags |= SDL_OPENGL;\r
-#endif //_IRR_EMSCRIPTEN_PLATFORM_\r
-\r
-       // create window\r
-       if (CreationParams.DriverType != video::EDT_NULL)\r
-       {\r
-               // create the window, only if we do not use the null device\r
-               createWindow();\r
-       }\r
-\r
        // create cursor control\r
        CursorControl = new CCursorControl(this);\r
 \r
        // create driver\r
        createDriver();\r
 \r
-       if (VideoDriver)\r
+       if (VideoDriver) {\r
                createGUIAndScene();\r
+               VideoDriver->OnResize(core::dimension2d<u32>(Width, Height));\r
+       }\r
 }\r
 \r
 \r
@@ -287,6 +308,12 @@ CIrrDeviceSDL::~CIrrDeviceSDL()
                for (u32 i=0; i<numJoysticks; ++i)\r
                        SDL_JoystickClose(Joysticks[i]);\r
 #endif\r
+               if (Window)\r
+               {\r
+                       SDL_GL_MakeCurrent(Window, NULL);\r
+                       SDL_GL_DeleteContext(Context);\r
+                       SDL_DestroyWindow(Window);\r
+               }\r
                SDL_Quit();\r
 \r
                os::Printer::log("Quit SDL", ELL_INFORMATION);\r
@@ -322,6 +349,16 @@ void CIrrDeviceSDL::logAttributes()
 \r
 bool CIrrDeviceSDL::createWindow()\r
 {\r
+       if (CreationParams.Fullscreen) {\r
+               SDL_Flags |= SDL_WINDOW_FULLSCREEN;\r
+       } else  {\r
+               if (Resizable)\r
+                       SDL_Flags |= SDL_WINDOW_RESIZABLE;\r
+               if (CreationParams.WindowMaximized)\r
+                       SDL_Flags |= SDL_WINDOW_MAXIMIZED;\r
+       }\r
+       SDL_Flags |= SDL_WINDOW_OPENGL;\r
+\r
 #ifdef _IRR_EMSCRIPTEN_PLATFORM_\r
        if ( Width != 0 || Height != 0 )\r
                emscripten_set_canvas_size( Width, Height);\r
@@ -353,7 +390,7 @@ bool CIrrDeviceSDL::createWindow()
                SDL_GL_SetAttribute(SDL_GL_MULTISAMPLESAMPLES, 0);\r
        }\r
 \r
-       Screen = SDL_SetVideoMode( 0, 0, 32, SDL_Flags); // 0,0 will use the canvas size\r
+       SDL_CreateWindowAndRenderer(0, 0, SDL_Flags, &Window, &Renderer); // 0,0 will use the canvas size\r
 \r
        logAttributes();\r
 \r
@@ -368,68 +405,91 @@ bool CIrrDeviceSDL::createWindow()
        if ( Close )\r
                return false;\r
 \r
-       if (CreationParams.DriverType == video::EDT_OPENGL)\r
-       {\r
-               if (CreationParams.Bits==16)\r
-               {\r
-                       SDL_GL_SetAttribute( SDL_GL_RED_SIZE, 4 );\r
-                       SDL_GL_SetAttribute( SDL_GL_GREEN_SIZE, 4 );\r
-                       SDL_GL_SetAttribute( SDL_GL_BLUE_SIZE, 4 );\r
-                       SDL_GL_SetAttribute( SDL_GL_ALPHA_SIZE, CreationParams.WithAlphaChannel?1:0 );\r
-               }\r
-               else\r
-               {\r
-                       SDL_GL_SetAttribute( SDL_GL_RED_SIZE, 8 );\r
-                       SDL_GL_SetAttribute( SDL_GL_GREEN_SIZE, 8 );\r
-                       SDL_GL_SetAttribute( SDL_GL_BLUE_SIZE, 8 );\r
-                       SDL_GL_SetAttribute( SDL_GL_ALPHA_SIZE, CreationParams.WithAlphaChannel?8:0 );\r
-               }\r
-               SDL_GL_SetAttribute( SDL_GL_DEPTH_SIZE, CreationParams.ZBufferBits);\r
-               if (CreationParams.Doublebuffer)\r
-                       SDL_GL_SetAttribute( SDL_GL_DOUBLEBUFFER, 1 );\r
-               SDL_GL_SetAttribute( SDL_GL_STENCIL_SIZE, CreationParams.Stencilbuffer ? 8 : 0);\r
-               if (CreationParams.Stereobuffer)\r
-                       SDL_GL_SetAttribute( SDL_GL_STEREO, 1 );\r
-               if (CreationParams.AntiAlias>1)\r
-               {\r
-                       SDL_GL_SetAttribute( SDL_GL_MULTISAMPLEBUFFERS, 1 );\r
-                       SDL_GL_SetAttribute( SDL_GL_MULTISAMPLESAMPLES, CreationParams.AntiAlias );\r
+       switch (CreationParams.DriverType) {\r
+               case video::EDT_OPENGL:\r
+                       SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 2);\r
+                       SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 1);\r
+                       break;\r
+               case video::EDT_OPENGL3:\r
+                       SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 3);\r
+                       SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 2);\r
+                       SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_COMPATIBILITY);\r
+                       break;\r
+               case video::EDT_OGLES1:\r
+                       SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 1);\r
+                       SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 1);\r
+                       SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_ES);\r
+                       break;\r
+               case video::EDT_OGLES2:\r
+               case video::EDT_WEBGL1:\r
+                       SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 2);\r
+                       SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 0);\r
+                       SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_ES);\r
+                       break;\r
+               default:;\r
+       }\r
+\r
+#ifdef _DEBUG\r
+       SDL_GL_SetAttribute(SDL_GL_CONTEXT_FLAGS, SDL_GL_CONTEXT_DEBUG_FLAG | SDL_GL_CONTEXT_ROBUST_ACCESS_FLAG);\r
+#endif\r
+\r
+       if (CreationParams.Bits == 16) {\r
+               SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 5);\r
+               SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 5);\r
+               SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 5);\r
+               SDL_GL_SetAttribute(SDL_GL_ALPHA_SIZE, CreationParams.WithAlphaChannel ? 1 : 0);\r
+       } else {\r
+               SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 8);\r
+               SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 8);\r
+               SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 8);\r
+               SDL_GL_SetAttribute(SDL_GL_ALPHA_SIZE, CreationParams.WithAlphaChannel ? 8 : 0);\r
+       }\r
+       SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, CreationParams.ZBufferBits);\r
+       SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, CreationParams.Doublebuffer);\r
+       SDL_GL_SetAttribute(SDL_GL_STENCIL_SIZE, CreationParams.Stencilbuffer ? 8 : 0);\r
+       SDL_GL_SetAttribute(SDL_GL_STEREO, CreationParams.Stereobuffer);\r
+       if (CreationParams.AntiAlias > 1) {\r
+               SDL_GL_SetAttribute(SDL_GL_MULTISAMPLEBUFFERS, 1);\r
+               SDL_GL_SetAttribute(SDL_GL_MULTISAMPLESAMPLES, CreationParams.AntiAlias);\r
+       }\r
+       if (!Window)\r
+               Window = SDL_CreateWindow("", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, Width, Height, SDL_Flags);\r
+       if (!Window) {\r
+               os::Printer::log("Could not create window...", SDL_GetError(), ELL_WARNING);\r
+       }\r
+       if (!Window && CreationParams.AntiAlias > 1) {\r
+               while (--CreationParams.AntiAlias > 1) {\r
+                       SDL_GL_SetAttribute(SDL_GL_MULTISAMPLESAMPLES, CreationParams.AntiAlias);\r
+                       Window = SDL_CreateWindow("", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, Width, Height, SDL_Flags);\r
+                       if (Window)\r
+                               break;\r
                }\r
-               if ( !Screen )\r
-                       Screen = SDL_SetVideoMode( Width, Height, CreationParams.Bits, SDL_Flags );\r
-               if ( !Screen && CreationParams.AntiAlias>1)\r
-               {\r
-                       while (--CreationParams.AntiAlias>1)\r
-                       {\r
-                               SDL_GL_SetAttribute( SDL_GL_MULTISAMPLESAMPLES, CreationParams.AntiAlias );\r
-                               Screen = SDL_SetVideoMode( Width, Height, CreationParams.Bits, SDL_Flags );\r
-                               if (Screen)\r
-                                       break;\r
-                       }\r
-                       if ( !Screen )\r
-                       {\r
-                               SDL_GL_SetAttribute( SDL_GL_MULTISAMPLEBUFFERS, 0 );\r
-                               SDL_GL_SetAttribute( SDL_GL_MULTISAMPLESAMPLES, 0 );\r
-                               Screen = SDL_SetVideoMode( Width, Height, CreationParams.Bits, SDL_Flags );\r
-                               if (Screen)\r
-                                       os::Printer::log("AntiAliasing disabled due to lack of support!" );\r
-                       }\r
+               if (!Window) {\r
+                       SDL_GL_SetAttribute(SDL_GL_MULTISAMPLEBUFFERS, 0);\r
+                       SDL_GL_SetAttribute(SDL_GL_MULTISAMPLESAMPLES, 0);\r
+                       Window = SDL_CreateWindow("", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, Width, Height, SDL_Flags);\r
+                       if (Window)\r
+                               os::Printer::log("AntiAliasing disabled due to lack of support!", ELL_WARNING);\r
                }\r
        }\r
-       else if ( !Screen )\r
-               Screen = SDL_SetVideoMode( Width, Height, CreationParams.Bits, SDL_Flags );\r
 \r
-       if ( !Screen && CreationParams.Doublebuffer)\r
+       if ( !Window && CreationParams.Doublebuffer)\r
        {\r
                // Try single buffer\r
                if (CreationParams.DriverType == video::EDT_OPENGL)\r
-                       SDL_GL_SetAttribute( SDL_GL_DOUBLEBUFFER, 1 );\r
-               SDL_Flags &= ~SDL_DOUBLEBUF;\r
-               Screen = SDL_SetVideoMode( Width, Height, CreationParams.Bits, SDL_Flags );\r
+                       SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);\r
+               Window = SDL_CreateWindow("", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, Width, Height, SDL_Flags);\r
        }\r
-       if ( !Screen )\r
+       if ( !Window )\r
        {\r
-               os::Printer::log( "Could not initialize display!" );\r
+               os::Printer::log("Could not initialize display", SDL_GetError(), ELL_ERROR);\r
+               return false;\r
+       }\r
+\r
+       Context = SDL_GL_CreateContext(Window);\r
+       if (!Context) {\r
+               os::Printer::log("Could not initialize context", SDL_GetError(), ELL_ERROR);\r
+               SDL_DestroyWindow(Window);\r
                return false;\r
        }\r
 \r
@@ -441,94 +501,22 @@ bool CIrrDeviceSDL::createWindow()
 //! create the driver\r
 void CIrrDeviceSDL::createDriver()\r
 {\r
-       switch(CreationParams.DriverType)\r
-       {\r
-       case video::DEPRECATED_EDT_DIRECT3D8_NO_LONGER_EXISTS:\r
-               os::Printer::log("DIRECT3D8 Driver is no longer supported in Irrlicht. Try another one.", ELL_ERROR);\r
-               break;\r
-\r
-       case video::EDT_DIRECT3D9:\r
-               #ifdef _IRR_COMPILE_WITH_DIRECT3D_9_\r
-               os::Printer::log("SDL device does not support DIRECT3D9 driver. Try another one.", ELL_ERROR);\r
-               #else\r
-               os::Printer::log("DIRECT3D9 Driver was not compiled into this dll. Try another one.", ELL_ERROR);\r
-               #endif // _IRR_COMPILE_WITH_DIRECT3D_9_\r
-\r
-               break;\r
-\r
-       case video::EDT_SOFTWARE:\r
-               #ifdef _IRR_COMPILE_WITH_SOFTWARE_\r
-               VideoDriver = video::createSoftwareDriver(CreationParams.WindowSize, CreationParams.Fullscreen, FileSystem, this);\r
-               #else\r
-               os::Printer::log("No Software driver support compiled in.", ELL_ERROR);\r
-               #endif\r
-               break;\r
-\r
-       case video::EDT_BURNINGSVIDEO:\r
-               #ifdef _IRR_COMPILE_WITH_BURNINGSVIDEO_\r
-               VideoDriver = video::createBurningVideoDriver(CreationParams, FileSystem, this);\r
-               #else\r
-               os::Printer::log("Burning's video driver was not compiled in.", ELL_ERROR);\r
-               #endif\r
-               break;\r
-\r
-       case video::EDT_OPENGL:\r
-               #ifdef _IRR_COMPILE_WITH_OPENGL_\r
-               VideoDriver = video::createOpenGLDriver(CreationParams, FileSystem, this);\r
-               #else\r
-               os::Printer::log("No OpenGL support compiled in.", ELL_ERROR);\r
-               #endif\r
-               break;\r
-\r
-       case video::EDT_OGLES2:\r
-#if defined(_IRR_COMPILE_WITH_OGLES2_) && defined(_IRR_EMSCRIPTEN_PLATFORM_)\r
-               {\r
-                       video::SExposedVideoData data;\r
-\r
-                       ContextManager = new video::CEGLManager();\r
-                       ContextManager->initialize(CreationParams, data);\r
-\r
-                       VideoDriver = video::createOGLES2Driver(CreationParams, FileSystem, ContextManager);\r
-               }\r
-#else\r
-               os::Printer::log("No OpenGL-ES2 support compiled in.", ELL_ERROR);\r
-#endif\r
-               break;\r
-\r
-       case video::EDT_WEBGL1:\r
-#if defined(_IRR_COMPILE_WITH_WEBGL1_) && defined(_IRR_EMSCRIPTEN_PLATFORM_)\r
-               {\r
-                       video::SExposedVideoData data;\r
-\r
-                       ContextManager = new video::CEGLManager();\r
-                       ContextManager->initialize(CreationParams, data);\r
-\r
-                       VideoDriver = video::createWebGL1Driver(CreationParams, FileSystem, ContextManager);\r
-               }\r
-#else\r
-               os::Printer::log("No WebGL1 support compiled in.", ELL_ERROR);\r
-#endif\r
-               break;\r
-\r
-       case video::EDT_NULL:\r
+       if (CreationParams.DriverType == video::EDT_NULL) {\r
                VideoDriver = video::createNullDriver(FileSystem, CreationParams.WindowSize);\r
-               break;\r
-\r
-       default:\r
-               os::Printer::log("Unable to create video driver of unknown type.", ELL_ERROR);\r
-               break;\r
+               return;\r
        }\r
 \r
-       // In case we got the size from the canvas\r
-       if ( VideoDriver && CreationParams.WindowSize.Width == 0 && CreationParams.WindowSize.Height == 0 && Width > 0 && Height > 0 )\r
+       ContextManager = new video::CSDLManager(this);\r
+       switch(CreationParams.DriverType)\r
        {\r
-#ifdef _IRR_EMSCRIPTEN_PLATFORM_\r
-               Screen = SDL_SetVideoMode( Width, Height, 32, SDL_Flags );\r
-#else //_IRR_EMSCRIPTEN_PLATFORM_\r
-               Screen = SDL_SetVideoMode( Width, Height, 0, SDL_Flags );\r
-#endif //_IRR_EMSCRIPTEN_PLATFOR\r
-               VideoDriver->OnResize(core::dimension2d<u32>(Width, Height));\r
+       case video::EDT_OPENGL: VideoDriver = video::createOpenGLDriver(CreationParams, FileSystem, ContextManager); break;\r
+       case video::EDT_OPENGL3: VideoDriver = video::createOpenGL3Driver(CreationParams, FileSystem, ContextManager); break;\r
+       case video::EDT_OGLES2: VideoDriver = video::createOGLES2Driver(CreationParams, FileSystem, ContextManager); break;\r
+       case video::EDT_WEBGL1: VideoDriver = video::createWebGL1Driver(CreationParams, FileSystem, ContextManager); break;\r
+       default:;\r
        }\r
+       if (!VideoDriver)\r
+               os::Printer::log("Could not create video driver", ELL_ERROR);\r
 }\r
 \r
 \r
@@ -546,7 +534,9 @@ bool CIrrDeviceSDL::run()
 \r
                switch ( SDL_event.type )\r
                {\r
-               case SDL_MOUSEMOTION:\r
+               case SDL_MOUSEMOTION: {\r
+                       SDL_Keymod keymod = SDL_GetModState();\r
+\r
                        irrevent.EventType = irr::EET_MOUSE_INPUT_EVENT;\r
                        irrevent.MouseInput.Event = irr::EMIE_MOUSE_MOVED;\r
                        MouseX = irrevent.MouseInput.X = SDL_event.motion.x;\r
@@ -554,16 +544,35 @@ bool CIrrDeviceSDL::run()
                        MouseXRel = SDL_event.motion.xrel;\r
                        MouseYRel = SDL_event.motion.yrel;\r
                        irrevent.MouseInput.ButtonStates = MouseButtonStates;\r
+                       irrevent.MouseInput.Shift = (keymod & KMOD_SHIFT) != 0;\r
+                       irrevent.MouseInput.Control = (keymod & KMOD_CTRL) != 0;\r
 \r
                        postEventFromUser(irrevent);\r
                        break;\r
+               }\r
+               case SDL_MOUSEWHEEL: {\r
+                       SDL_Keymod keymod = SDL_GetModState();\r
+\r
+                       irrevent.EventType = irr::EET_MOUSE_INPUT_EVENT;\r
+                       irrevent.MouseInput.Event = irr::EMIE_MOUSE_WHEEL;\r
+                       irrevent.MouseInput.Wheel = static_cast<float>(SDL_event.wheel.y);\r
+                       irrevent.MouseInput.Shift = (keymod & KMOD_SHIFT) != 0;\r
+                       irrevent.MouseInput.Control = (keymod & KMOD_CTRL) != 0;\r
+                       irrevent.MouseInput.X = MouseX;\r
+                       irrevent.MouseInput.Y = MouseY;\r
 \r
+                       postEventFromUser(irrevent);\r
+                       break;\r
+               }\r
                case SDL_MOUSEBUTTONDOWN:\r
-               case SDL_MOUSEBUTTONUP:\r
+               case SDL_MOUSEBUTTONUP: {\r
+                       SDL_Keymod keymod = SDL_GetModState();\r
 \r
                        irrevent.EventType = irr::EET_MOUSE_INPUT_EVENT;\r
                        irrevent.MouseInput.X = SDL_event.button.x;\r
                        irrevent.MouseInput.Y = SDL_event.button.y;\r
+                       irrevent.MouseInput.Shift = (keymod & KMOD_SHIFT) != 0;\r
+                       irrevent.MouseInput.Control = (keymod & KMOD_CTRL) != 0;\r
 \r
                        irrevent.MouseInput.Event = irr::EMIE_MOUSE_MOVED;\r
 \r
@@ -605,7 +614,7 @@ bool CIrrDeviceSDL::run()
                                else\r
                                {\r
                                        irrevent.MouseInput.Event = irr::EMIE_LMOUSE_LEFT_UP;\r
-                                       MouseButtonStates &= !irr::EMBSM_LEFT;\r
+                                       MouseButtonStates &= ~irr::EMBSM_LEFT;\r
                                }\r
                                break;\r
 \r
@@ -618,7 +627,7 @@ bool CIrrDeviceSDL::run()
                                else\r
                                {\r
                                        irrevent.MouseInput.Event = irr::EMIE_RMOUSE_LEFT_UP;\r
-                                       MouseButtonStates &= !irr::EMBSM_RIGHT;\r
+                                       MouseButtonStates &= ~irr::EMBSM_RIGHT;\r
                                }\r
                                break;\r
 \r
@@ -631,19 +640,9 @@ bool CIrrDeviceSDL::run()
                                else\r
                                {\r
                                        irrevent.MouseInput.Event = irr::EMIE_MMOUSE_LEFT_UP;\r
-                                       MouseButtonStates &= !irr::EMBSM_MIDDLE;\r
+                                       MouseButtonStates &= ~irr::EMBSM_MIDDLE;\r
                                }\r
                                break;\r
-\r
-                       case SDL_BUTTON_WHEELUP:\r
-                               irrevent.MouseInput.Event = irr::EMIE_MOUSE_WHEEL;\r
-                               irrevent.MouseInput.Wheel = 1.0f;\r
-                               break;\r
-\r
-                       case SDL_BUTTON_WHEELDOWN:\r
-                               irrevent.MouseInput.Event = irr::EMIE_MOUSE_WHEEL;\r
-                               irrevent.MouseInput.Wheel = -1.0f;\r
-                               break;\r
                        }\r
 \r
                        irrevent.MouseInput.ButtonStates = MouseButtonStates;\r
@@ -668,6 +667,18 @@ bool CIrrDeviceSDL::run()
                                }\r
                        }\r
                        break;\r
+               }\r
+\r
+               case SDL_TEXTINPUT:\r
+                       {\r
+                               irrevent.EventType = irr::EET_STRING_INPUT_EVENT;\r
+                               irrevent.StringInput.Str = new core::stringw();\r
+                               irr::core::multibyteToWString(*irrevent.StringInput.Str, SDL_event.text.text);\r
+                               postEventFromUser(irrevent);\r
+                               delete irrevent.StringInput.Str;\r
+                               irrevent.StringInput.Str = NULL;\r
+                       }\r
+                       break;\r
 \r
                case SDL_KEYDOWN:\r
                case SDL_KEYUP:\r
@@ -682,6 +693,10 @@ bool CIrrDeviceSDL::run()
                                else\r
                                        key = (EKEY_CODE)KeyMap[idx].Win32Key;\r
 \r
+                               // Make sure to only input special characters if something is in focus, as SDL_TEXTINPUT handles normal unicode already\r
+                               if (SDL_IsTextInputActive() && !keyIsKnownSpecial(key) && (SDL_event.key.keysym.mod & KMOD_CTRL) == 0)\r
+                                       break;\r
+\r
 #ifdef _IRR_WINDOWS_API_\r
                                // handle alt+f4 in Windows, because SDL seems not to\r
                                if ( (SDL_event.key.keysym.mod & KMOD_LALT) && key == KEY_F4)\r
@@ -691,19 +706,11 @@ bool CIrrDeviceSDL::run()
                                }\r
 #endif\r
                                irrevent.EventType = irr::EET_KEY_INPUT_EVENT;\r
-                               irrevent.KeyInput.Char = SDL_event.key.keysym.unicode;\r
                                irrevent.KeyInput.Key = key;\r
-#ifdef _IRR_EMSCRIPTEN_PLATFORM_\r
-                               // On emscripten SDL does not (yet?) return 0 for invalid keysym.unicode's.\r
-                               // Instead it sets keysym.unicode to keysym.sym.\r
-                               // But we need to distinguish control keys from characters here as that info\r
-                               // is necessary in other places like the editbox.\r
-                               if ( isNoUnicodeKey(key) )\r
-                                       irrevent.KeyInput.Char = 0;\r
-#endif\r
                                irrevent.KeyInput.PressedDown = (SDL_event.type == SDL_KEYDOWN);\r
                                irrevent.KeyInput.Shift = (SDL_event.key.keysym.mod & KMOD_SHIFT) != 0;\r
                                irrevent.KeyInput.Control = (SDL_event.key.keysym.mod & KMOD_CTRL ) != 0;\r
+                               irrevent.KeyInput.Char = findCharToPassToIrrlicht(mp.SDLKey, key);\r
                                postEventFromUser(irrevent);\r
                        }\r
                        break;\r
@@ -712,25 +719,19 @@ bool CIrrDeviceSDL::run()
                        Close = true;\r
                        break;\r
 \r
-               case SDL_ACTIVEEVENT:\r
-                       if (SDL_event.active.state == SDL_APPACTIVE)\r
-                               WindowMinimized = (SDL_event.active.gain!=1);\r
-                       break;\r
-\r
-               case SDL_VIDEORESIZE:\r
-                       if ((SDL_event.resize.w != (int)Width) || (SDL_event.resize.h != (int)Height))\r
+               case SDL_WINDOWEVENT:\r
+                       switch (SDL_event.window.event)\r
                        {\r
-                               Width = SDL_event.resize.w;\r
-                               Height = SDL_event.resize.h;\r
-#ifdef _IRR_EMSCRIPTEN_PLATFORM_\r
-                               Screen = SDL_SetVideoMode( 0, 0, 32, SDL_Flags ); // 0,0 will use the canvas size\r
-#else //_IRR_EMSCRIPTEN_PLATFORM_\r
-                               Screen = SDL_SetVideoMode( Width, Height, 0, SDL_Flags );\r
-#endif //_IRR_EMSCRIPTEN_PLATFOR\r
-                               if (VideoDriver)\r
-                                       VideoDriver->OnResize(core::dimension2d<u32>(Width, Height));\r
+                       case SDL_WINDOWEVENT_RESIZED:\r
+                               if ((SDL_event.window.data1 != (int)Width) || (SDL_event.window.data2 != (int)Height))\r
+                               {\r
+                                       Width = SDL_event.window.data1;\r
+                                       Height = SDL_event.window.data2;\r
+                                       if (VideoDriver)\r
+                                               VideoDriver->OnResize(core::dimension2d<u32>(Width, Height));\r
+                               }\r
+                               break;\r
                        }\r
-                       break;\r
 \r
                case SDL_USEREVENT:\r
                        irrevent.EventType = irr::EET_USER_EVENT;\r
@@ -743,7 +744,7 @@ bool CIrrDeviceSDL::run()
                default:\r
                        break;\r
                } // end switch\r
-\r
+       resetReceiveTextInputEvents();\r
        } // end while\r
 \r
 #if defined(_IRR_COMPILE_WITH_JOYSTICK_EVENTS_)\r
@@ -843,13 +844,13 @@ bool CIrrDeviceSDL::activateJoysticks(core::array<SJoystickInfo> & joystickInfo)
        int joystick = 0;\r
        for (; joystick<numJoysticks; ++joystick)\r
        {\r
-               Joysticks.push_back(SDL_JoystickOpen(joystick));\r
+               Joysticks.push_back( SDL_JoystickOpen(joystick));\r
                SJoystickInfo info;\r
 \r
                info.Joystick = joystick;\r
                info.Axes = SDL_JoystickNumAxes(Joysticks[joystick]);\r
                info.Buttons = SDL_JoystickNumButtons(Joysticks[joystick]);\r
-               info.Name = SDL_JoystickName(joystick);\r
+               info.Name = SDL_JoystickName(Joysticks[joystick]);\r
                info.PovHat = (SDL_JoystickNumHats(Joysticks[joystick]) > 0)\r
                                                ? SJoystickInfo::POV_HAT_PRESENT : SJoystickInfo::POV_HAT_ABSENT;\r
 \r
@@ -859,9 +860,9 @@ bool CIrrDeviceSDL::activateJoysticks(core::array<SJoystickInfo> & joystickInfo)
        for(joystick = 0; joystick < (int)joystickInfo.size(); ++joystick)\r
        {\r
                char logString[256];\r
-               (void)sprintf(logString, "Found joystick %d, %d axes, %d buttons '%s'",\r
-               joystick, joystickInfo[joystick].Axes,\r
-               joystickInfo[joystick].Buttons, joystickInfo[joystick].Name.c_str());\r
+               snprintf_irr(logString, sizeof(logString), "Found joystick %d, %d axes, %d buttons '%s'",\r
+                       joystick, joystickInfo[joystick].Axes,\r
+                       joystickInfo[joystick].Buttons, joystickInfo[joystick].Name.c_str());\r
                os::Printer::log(logString, ELL_INFORMATION);\r
        }\r
 \r
@@ -872,6 +873,11 @@ bool CIrrDeviceSDL::activateJoysticks(core::array<SJoystickInfo> & joystickInfo)
        return false;\r
 }\r
 \r
+void CIrrDeviceSDL::SwapWindow()\r
+{\r
+       SDL_GL_SwapWindow(Window);\r
+}\r
+\r
 \r
 \r
 //! pause execution temporarily\r
@@ -898,92 +904,9 @@ void CIrrDeviceSDL::sleep(u32 timeMs, bool pauseTimer)
 //! sets the caption of the window\r
 void CIrrDeviceSDL::setWindowCaption(const wchar_t* text)\r
 {\r
-       core::stringc textc = text;\r
-       SDL_WM_SetCaption( textc.c_str( ), textc.c_str( ) );\r
-}\r
-\r
-\r
-//! presents a surface in the client area\r
-bool CIrrDeviceSDL::present(video::IImage* surface, void* windowId, core::rect<s32>* srcClip)\r
-{\r
-#ifdef _IRR_EMSCRIPTEN_PLATFORM_\r
-       return true;\r
-#else // !_IRR_EMSCRIPTEN_PLATFORM_\r
-       SDL_Surface *sdlSurface = SDL_CreateRGBSurfaceFrom(\r
-                       surface->getData(), surface->getDimension().Width, surface->getDimension().Height,\r
-                       surface->getBitsPerPixel(), surface->getPitch(),\r
-                       surface->getRedMask(), surface->getGreenMask(), surface->getBlueMask(), surface->getAlphaMask());\r
-       if (!sdlSurface)\r
-               return false;\r
-       SDL_SetAlpha(sdlSurface, 0, 0);\r
-       SDL_SetColorKey(sdlSurface, 0, 0);\r
-       sdlSurface->format->BitsPerPixel=surface->getBitsPerPixel();\r
-       sdlSurface->format->BytesPerPixel=surface->getBytesPerPixel();\r
-       if ((surface->getColorFormat()==video::ECF_R8G8B8) ||\r
-                       (surface->getColorFormat()==video::ECF_A8R8G8B8))\r
-       {\r
-               sdlSurface->format->Rloss=0;\r
-               sdlSurface->format->Gloss=0;\r
-               sdlSurface->format->Bloss=0;\r
-               sdlSurface->format->Rshift=16;\r
-               sdlSurface->format->Gshift=8;\r
-               sdlSurface->format->Bshift=0;\r
-               if (surface->getColorFormat()==video::ECF_R8G8B8)\r
-               {\r
-                       sdlSurface->format->Aloss=8;\r
-                       sdlSurface->format->Ashift=32;\r
-               }\r
-               else\r
-               {\r
-                       sdlSurface->format->Aloss=0;\r
-                       sdlSurface->format->Ashift=24;\r
-               }\r
-       }\r
-       else if (surface->getColorFormat()==video::ECF_R5G6B5)\r
-       {\r
-               sdlSurface->format->Rloss=3;\r
-               sdlSurface->format->Gloss=2;\r
-               sdlSurface->format->Bloss=3;\r
-               sdlSurface->format->Aloss=8;\r
-               sdlSurface->format->Rshift=11;\r
-               sdlSurface->format->Gshift=5;\r
-               sdlSurface->format->Bshift=0;\r
-               sdlSurface->format->Ashift=16;\r
-       }\r
-       else if (surface->getColorFormat()==video::ECF_A1R5G5B5)\r
-       {\r
-               sdlSurface->format->Rloss=3;\r
-               sdlSurface->format->Gloss=3;\r
-               sdlSurface->format->Bloss=3;\r
-               sdlSurface->format->Aloss=7;\r
-               sdlSurface->format->Rshift=10;\r
-               sdlSurface->format->Gshift=5;\r
-               sdlSurface->format->Bshift=0;\r
-               sdlSurface->format->Ashift=15;\r
-       }\r
-\r
-       SDL_Surface* scr = (SDL_Surface* )windowId;\r
-       if (!scr)\r
-               scr = Screen;\r
-       if (scr)\r
-       {\r
-               if (srcClip)\r
-               {\r
-                       SDL_Rect sdlsrcClip;\r
-                       sdlsrcClip.x = srcClip->UpperLeftCorner.X;\r
-                       sdlsrcClip.y = srcClip->UpperLeftCorner.Y;\r
-                       sdlsrcClip.w = srcClip->getWidth();\r
-                       sdlsrcClip.h = srcClip->getHeight();\r
-                       SDL_BlitSurface(sdlSurface, &sdlsrcClip, scr, NULL);\r
-               }\r
-               else\r
-                       SDL_BlitSurface(sdlSurface, NULL, scr, NULL);\r
-               SDL_Flip(scr);\r
-       }\r
-\r
-       SDL_FreeSurface(sdlSurface);\r
-       return (scr != 0);\r
-#endif // !_IRR_EMSCRIPTEN_PLATFORM_\r
+       core::stringc textc;\r
+       core::wStringToMultibyte(textc, text);\r
+       SDL_SetWindowTitle(Window, textc.c_str());\r
 }\r
 \r
 \r
@@ -994,53 +917,6 @@ void CIrrDeviceSDL::closeDevice()
 }\r
 \r
 \r
-//! \return Pointer to a list with all video modes supported\r
-video::IVideoModeList* CIrrDeviceSDL::getVideoModeList()\r
-{\r
-#ifdef _IRR_EMSCRIPTEN_PLATFORM_\r
-       os::Printer::log("VideoModeList not available on the web." , ELL_WARNING);\r
-       return VideoModeList;\r
-#else // !_IRR_EMSCRIPTEN_PLATFORM_\r
-       if (!VideoModeList->getVideoModeCount())\r
-       {\r
-               // enumerate video modes.\r
-               const SDL_VideoInfo *vi = SDL_GetVideoInfo();\r
-\r
-               SDL_PixelFormat pixelFormat = *(vi->vfmt);\r
-\r
-               core::array<Uint8> checkBitsPerPixel;\r
-               checkBitsPerPixel.push_back(8);\r
-               checkBitsPerPixel.push_back(16);\r
-               checkBitsPerPixel.push_back(24);\r
-               checkBitsPerPixel.push_back(32);\r
-               if ( pixelFormat.BitsPerPixel > 32 )\r
-                       checkBitsPerPixel.push_back(pixelFormat.BitsPerPixel);\r
-\r
-               for ( u32 i=0; i<checkBitsPerPixel.size(); ++i)\r
-               {\r
-                       pixelFormat.BitsPerPixel = checkBitsPerPixel[i];\r
-                       SDL_Rect **modes = SDL_ListModes(&pixelFormat, SDL_Flags|SDL_FULLSCREEN);\r
-                       if (modes != 0)\r
-                       {\r
-                               if (modes == (SDL_Rect **)-1)\r
-                               {\r
-                                       core::stringc strLog("All modes available for bit-depth ");\r
-                                       strLog += core::stringc(pixelFormat.BitsPerPixel);\r
-                                       os::Printer::log(strLog.c_str());\r
-                               }\r
-                               else\r
-                               {\r
-                                       for (u32 i=0; modes[i]; ++i)\r
-                                               VideoModeList->addMode(core::dimension2d<u32>(modes[i]->w, modes[i]->h), vi->vfmt->BitsPerPixel);\r
-                               }\r
-                       }\r
-               }\r
-       }\r
-\r
-       return VideoModeList;\r
-#endif // !_IRR_EMSCRIPTEN_PLATFORM_\r
-}\r
-\r
 //! Sets if the window should be resizable in windowed mode.\r
 void CIrrDeviceSDL::setResizable(bool resize)\r
 {\r
@@ -1048,24 +924,15 @@ void CIrrDeviceSDL::setResizable(bool resize)
        os::Printer::log("Resizable not available on the web." , ELL_WARNING);\r
        return;\r
 #else // !_IRR_EMSCRIPTEN_PLATFORM_\r
-       if (resize != Resizable)\r
-       {\r
-#if defined(_IRR_COMPILE_WITH_OPENGL_) && defined(_IRR_WINDOWS_)\r
-               if ( SDL_Flags & SDL_OPENGL )\r
-               {\r
-                       // For unknown reasons the hack with sharing resources which was added in Irrlicht 1.8.5 for this no longer works in 1.9\r
-                       // But at least we got a new WindowResizable flag since Irrlicht 1.9.\r
-                       os::Printer::log("setResizable not supported with this device/driver combination. Use SIrrCreationParameters.WindowResizable instead.", ELL_WARNING);\r
-                       return;\r
-               }\r
-#endif\r
-\r
+       if (resize != Resizable) {\r
                if (resize)\r
-                       SDL_Flags |= SDL_RESIZABLE;\r
+                       SDL_Flags |= SDL_WINDOW_RESIZABLE;\r
                else\r
-                       SDL_Flags &= ~SDL_RESIZABLE;\r
+                       SDL_Flags &= ~SDL_WINDOW_RESIZABLE;\r
 \r
-               Screen = SDL_SetVideoMode( 0, 0, 0, SDL_Flags );\r
+               if (Window) {\r
+                       SDL_SetWindowResizable(Window, (SDL_bool)resize);\r
+               }\r
                Resizable = resize;\r
        }\r
 #endif // !_IRR_EMSCRIPTEN_PLATFORM_\r
@@ -1075,14 +942,16 @@ void CIrrDeviceSDL::setResizable(bool resize)
 //! Minimizes window if possible\r
 void CIrrDeviceSDL::minimizeWindow()\r
 {\r
-       SDL_WM_IconifyWindow();\r
+       if (Window)\r
+               SDL_MinimizeWindow(Window);\r
 }\r
 \r
 \r
 //! Maximize window\r
 void CIrrDeviceSDL::maximizeWindow()\r
 {\r
-       // do nothing\r
+       if (Window)\r
+               SDL_MaximizeWindow(Window);\r
 }\r
 \r
 //! Get the position of this window on screen\r
@@ -1095,7 +964,13 @@ core::position2di CIrrDeviceSDL::getWindowPosition()
 //! Restore original window size\r
 void CIrrDeviceSDL::restoreWindow()\r
 {\r
-       // do nothing\r
+       if (Window)\r
+               SDL_RestoreWindow(Window);\r
+}\r
+\r
+bool CIrrDeviceSDL::isWindowMaximized() const\r
+{\r
+       return Window && (SDL_GetWindowFlags(Window) & SDL_WINDOW_MAXIMIZED) != 0;\r
 }\r
 \r
 bool CIrrDeviceSDL::isFullscreen() const\r
@@ -1122,59 +997,41 @@ bool CIrrDeviceSDL::isWindowActive() const
                        return false;\r
        }\r
 #endif\r
-       const Uint8 appState = SDL_GetAppState();\r
-       return (appState&SDL_APPACTIVE && appState&SDL_APPINPUTFOCUS) ? true : false;\r
+       const u32 windowFlags = SDL_GetWindowFlags(Window);\r
+       return windowFlags & SDL_WINDOW_SHOWN && windowFlags & SDL_WINDOW_INPUT_FOCUS;\r
 }\r
 \r
 \r
 //! returns if window has focus.\r
 bool CIrrDeviceSDL::isWindowFocused() const\r
 {\r
-       return (SDL_GetAppState()&SDL_APPINPUTFOCUS) ? true : false;\r
+       return Window && (SDL_GetWindowFlags(Window) & SDL_WINDOW_INPUT_FOCUS) != 0;\r
 }\r
 \r
 \r
 //! returns if window is minimized.\r
 bool CIrrDeviceSDL::isWindowMinimized() const\r
 {\r
-       return WindowMinimized;\r
-}\r
-\r
-\r
-//! Set the current Gamma Value for the Display\r
-bool CIrrDeviceSDL::setGammaRamp( f32 red, f32 green, f32 blue, f32 brightness, f32 contrast )\r
-{\r
-       /*\r
-       // todo: Gamma in SDL takes ints, what does Irrlicht use?\r
-       return (SDL_SetGamma(red, green, blue) != -1);\r
-       */\r
-       return false;\r
+       return Window && (SDL_GetWindowFlags(Window) & SDL_WINDOW_MINIMIZED) != 0;\r
 }\r
 \r
-//! Get the current Gamma Value for the Display\r
-bool CIrrDeviceSDL::getGammaRamp( f32 &red, f32 &green, f32 &blue, f32 &brightness, f32 &contrast )\r
-{\r
-/*     brightness = 0.f;\r
-       contrast = 0.f;\r
-       return (SDL_GetGamma(&red, &green, &blue) != -1);*/\r
-       return false;\r
-}\r
 \r
 //! returns color format of the window.\r
 video::ECOLOR_FORMAT CIrrDeviceSDL::getColorFormat() const\r
 {\r
-       if (Screen)\r
+       if (Window)\r
        {\r
-               if (Screen->format->BitsPerPixel==16)\r
+               SDL_Surface *surface = SDL_GetWindowSurface(Window);\r
+               if (surface->format->BitsPerPixel == 16)\r
                {\r
-                       if (Screen->format->Amask != 0)\r
+                       if (surface->format->Amask != 0)\r
                                return video::ECF_A1R5G5B5;\r
                        else\r
                                return video::ECF_R5G6B5;\r
                }\r
                else\r
                {\r
-                       if (Screen->format->Amask != 0)\r
+                       if (surface->format->Amask != 0)\r
                                return video::ECF_A8R8G8B8;\r
                        else\r
                                return video::ECF_R8G8B8;\r
@@ -1222,9 +1079,9 @@ void CIrrDeviceSDL::createKeyMap()
        KeyMap.push_back(SKeyMap(SDLK_DOWN, KEY_DOWN));\r
 \r
        // select missing\r
-       KeyMap.push_back(SKeyMap(SDLK_PRINT, KEY_PRINT));\r
+       KeyMap.push_back(SKeyMap(SDLK_PRINTSCREEN, KEY_PRINT));\r
        // execute missing\r
-       KeyMap.push_back(SKeyMap(SDLK_PRINT, KEY_SNAPSHOT));\r
+       KeyMap.push_back(SKeyMap(SDLK_PRINTSCREEN, KEY_SNAPSHOT));\r
 \r
        KeyMap.push_back(SKeyMap(SDLK_INSERT, KEY_INSERT));\r
        KeyMap.push_back(SKeyMap(SDLK_DELETE, KEY_DELETE));\r
@@ -1268,21 +1125,21 @@ void CIrrDeviceSDL::createKeyMap()
        KeyMap.push_back(SKeyMap(SDLK_y, KEY_KEY_Y));\r
        KeyMap.push_back(SKeyMap(SDLK_z, KEY_KEY_Z));\r
 \r
-       KeyMap.push_back(SKeyMap(SDLK_LSUPER, KEY_LWIN));\r
-       KeyMap.push_back(SKeyMap(SDLK_RSUPER, KEY_RWIN));\r
+       KeyMap.push_back(SKeyMap(SDLK_LGUI, KEY_LWIN));\r
+       KeyMap.push_back(SKeyMap(SDLK_RGUI, KEY_RWIN));\r
        // apps missing\r
        KeyMap.push_back(SKeyMap(SDLK_POWER, KEY_SLEEP)); //??\r
 \r
-       KeyMap.push_back(SKeyMap(SDLK_KP0, KEY_NUMPAD0));\r
-       KeyMap.push_back(SKeyMap(SDLK_KP1, KEY_NUMPAD1));\r
-       KeyMap.push_back(SKeyMap(SDLK_KP2, KEY_NUMPAD2));\r
-       KeyMap.push_back(SKeyMap(SDLK_KP3, KEY_NUMPAD3));\r
-       KeyMap.push_back(SKeyMap(SDLK_KP4, KEY_NUMPAD4));\r
-       KeyMap.push_back(SKeyMap(SDLK_KP5, KEY_NUMPAD5));\r
-       KeyMap.push_back(SKeyMap(SDLK_KP6, KEY_NUMPAD6));\r
-       KeyMap.push_back(SKeyMap(SDLK_KP7, KEY_NUMPAD7));\r
-       KeyMap.push_back(SKeyMap(SDLK_KP8, KEY_NUMPAD8));\r
-       KeyMap.push_back(SKeyMap(SDLK_KP9, KEY_NUMPAD9));\r
+       KeyMap.push_back(SKeyMap(SDLK_KP_0, KEY_NUMPAD0));\r
+       KeyMap.push_back(SKeyMap(SDLK_KP_1, KEY_NUMPAD1));\r
+       KeyMap.push_back(SKeyMap(SDLK_KP_2, KEY_NUMPAD2));\r
+       KeyMap.push_back(SKeyMap(SDLK_KP_3, KEY_NUMPAD3));\r
+       KeyMap.push_back(SKeyMap(SDLK_KP_4, KEY_NUMPAD4));\r
+       KeyMap.push_back(SKeyMap(SDLK_KP_5, KEY_NUMPAD5));\r
+       KeyMap.push_back(SKeyMap(SDLK_KP_6, KEY_NUMPAD6));\r
+       KeyMap.push_back(SKeyMap(SDLK_KP_7, KEY_NUMPAD7));\r
+       KeyMap.push_back(SKeyMap(SDLK_KP_8, KEY_NUMPAD8));\r
+       KeyMap.push_back(SKeyMap(SDLK_KP_9, KEY_NUMPAD9));\r
        KeyMap.push_back(SKeyMap(SDLK_KP_MULTIPLY, KEY_MULTIPLY));\r
        KeyMap.push_back(SKeyMap(SDLK_KP_PLUS, KEY_ADD));\r
 //     KeyMap.push_back(SKeyMap(SDLK_KP_, KEY_SEPARATOR));\r
@@ -1307,8 +1164,8 @@ void CIrrDeviceSDL::createKeyMap()
        KeyMap.push_back(SKeyMap(SDLK_F15, KEY_F15));\r
        // no higher F-keys\r
 \r
-       KeyMap.push_back(SKeyMap(SDLK_NUMLOCK, KEY_NUMLOCK));\r
-       KeyMap.push_back(SKeyMap(SDLK_SCROLLOCK, KEY_SCROLL));\r
+       KeyMap.push_back(SKeyMap(SDLK_NUMLOCKCLEAR, KEY_NUMLOCK));\r
+       KeyMap.push_back(SKeyMap(SDLK_SCROLLLOCK, KEY_SCROLL));\r
        KeyMap.push_back(SKeyMap(SDLK_LSHIFT, KEY_LSHIFT));\r
        KeyMap.push_back(SKeyMap(SDLK_RSHIFT, KEY_RSHIFT));\r
        KeyMap.push_back(SKeyMap(SDLK_LCTRL,  KEY_LCONTROL));\r
@@ -1326,6 +1183,25 @@ void CIrrDeviceSDL::createKeyMap()
        KeyMap.sort();\r
 }\r
 \r
+void CIrrDeviceSDL::CCursorControl::initCursors()\r
+{\r
+       Cursors.reserve(gui::ECI_COUNT);\r
+\r
+       Cursors.emplace_back(SDL_CreateSystemCursor(SDL_SYSTEM_CURSOR_ARROW));     // ECI_NORMAL\r
+       Cursors.emplace_back(SDL_CreateSystemCursor(SDL_SYSTEM_CURSOR_CROSSHAIR)); // ECI_CROSS\r
+       Cursors.emplace_back(SDL_CreateSystemCursor(SDL_SYSTEM_CURSOR_HAND));      // ECI_HAND\r
+       Cursors.emplace_back(nullptr);                                             // ECI_HELP\r
+       Cursors.emplace_back(SDL_CreateSystemCursor(SDL_SYSTEM_CURSOR_IBEAM));     // ECI_IBEAM\r
+       Cursors.emplace_back(SDL_CreateSystemCursor(SDL_SYSTEM_CURSOR_NO));        // ECI_NO\r
+       Cursors.emplace_back(SDL_CreateSystemCursor(SDL_SYSTEM_CURSOR_WAIT));      // ECI_WAIT\r
+       Cursors.emplace_back(SDL_CreateSystemCursor(SDL_SYSTEM_CURSOR_SIZEALL));   // ECI_SIZEALL\r
+       Cursors.emplace_back(SDL_CreateSystemCursor(SDL_SYSTEM_CURSOR_SIZENESW));  // ECI_SIZENESW\r
+       Cursors.emplace_back(SDL_CreateSystemCursor(SDL_SYSTEM_CURSOR_SIZENWSE));  // ECI_SIZENWSE\r
+       Cursors.emplace_back(SDL_CreateSystemCursor(SDL_SYSTEM_CURSOR_SIZENS));    // ECI_SIZENS\r
+       Cursors.emplace_back(SDL_CreateSystemCursor(SDL_SYSTEM_CURSOR_SIZEWE));    // ECI_SIZEWE\r
+       Cursors.emplace_back(nullptr);                                             // ECI_UP\r
+}\r
+\r
 } // end namespace irr\r
 \r
 #endif // _IRR_COMPILE_WITH_SDL_DEVICE_\r