Index: trunk/src/gl/gl_context.cc
===================================================================
--- trunk/src/gl/gl_context.cc	(revision 170)
+++ trunk/src/gl/gl_context.cc	(revision 171)
@@ -7,4 +7,5 @@
 #include "nv/gl/gl_enum.hh"
 #include "nv/lib/gl.hh"
+#include "nv/lib/sdl.hh"
 
 using namespace nv;
@@ -349,11 +350,42 @@
 
 
-gl_context::gl_context( device* a_device )
-	: context( a_device )
-{
+gl_context::gl_context( device* a_device, void* a_win_handle )
+	: context( a_device ), m_handle( nullptr )
+{
+#if NV_SDL_VERSION == NV_SDL_20
+	m_handle = SDL_GL_CreateContext( static_cast<SDL_Window*>( a_win_handle ) );
+
+	if ( m_handle == 0 )
+	{
+		NV_LOG( LOG_CRITICAL, "GL Context creation failed: " << SDL_GetError( ) );
+		return; // TODO: Error report
+	}
+#else
+	NV_UNUSED( a_win_handle );
+#endif
+
+	nv::load_gl_library();
+	NV_LOG( LOG_INFO, "OpenGL Vendor       : " << glGetString(GL_VENDOR) );
+	NV_LOG( LOG_INFO, "OpenGL Renderer     : " << glGetString(GL_RENDERER) );
+	NV_LOG( LOG_INFO, "OpenGL Version      : " << glGetString(GL_VERSION) );
+	NV_LOG( LOG_INFO, "OpenGL GLSL Version : " << glGetString(GL_SHADING_LANGUAGE_VERSION) );
+#if NV_SDL_VERSION == NV_SDL_20
+//	SDL_GL_SetSwapInterval(1);
+#endif
+
 	// TODO: do we really need this?
 	glPixelStorei( GL_UNPACK_ALIGNMENT, 1 );
+
 	force_apply_render_state( m_render_state );
 }
+
+
+nv::gl_context::~gl_context()
+{
+#if NV_SDL_VERSION == NV_SDL_20
+	SDL_GL_DeleteContext(static_cast<SDL_GLContext>( m_handle ) );
+#endif
+}
+
 
 void gl_context::draw( primitive prim, const render_state& rs, program* p, vertex_array* va, size_t count )
Index: trunk/src/gl/gl_device.cc
===================================================================
--- trunk/src/gl/gl_device.cc	(revision 170)
+++ trunk/src/gl/gl_device.cc	(revision 171)
@@ -31,4 +31,5 @@
 	}
 
+#if NV_SDL_VERSION == NV_SDL_12
 	m_info = SDL_GetVideoInfo( );
 
@@ -38,4 +39,5 @@
 		return; // TODO: Error report
 	}
+#endif
 
 //	bpp = m_info->vfmt->BitsPerPixel;
@@ -49,4 +51,11 @@
 	SDL_GL_SetAttribute( SDL_GL_MULTISAMPLEBUFFERS, 1 );
 	SDL_GL_SetAttribute( SDL_GL_MULTISAMPLESAMPLES, 4 );
+
+#if NV_SDL_VERSION == NV_SDL_20
+	SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 2);
+	SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 1);
+	SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
+	SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 24);
+#endif
 
 }
Index: trunk/src/gl/gl_window.cc
===================================================================
--- trunk/src/gl/gl_window.cc	(revision 170)
+++ trunk/src/gl/gl_window.cc	(revision 171)
@@ -18,8 +18,14 @@
 	kevent.key.code    = KEY_NONE;
 
+#if NV_SDL_VERSION == NV_SDL_20
+	uint32 ucode = ke.keysym.sym;
+#else
+	uint32 ucode = ke.keysym.unicode;
+#endif
+
 	// if result is a typable char place it into the structure
-	if (ke.keysym.unicode >= 32 && ke.keysym.unicode < 128 )
-	{
-		kevent.key.ascii = static_cast<char8>( ke.keysym.unicode );
+	if (ucode >= 32 && ucode < 128 )
+	{
+		kevent.key.ascii = static_cast<char8>( ucode );
 	}
 
@@ -67,5 +73,5 @@
 	case SDLK_DELETE       : kevent.key.code = KEY_DELETE; break;
 	case SDLK_INSERT       : kevent.key.code = KEY_INSERT; break;
-	case SDLK_KP5          : kevent.key.code = KEY_CENTER; break;
+	//case SDLK_KP5          : kevent.key.code = KEY_CENTER; break;
 	case SDLK_ESCAPE       : kevent.key.code = KEY_ESCAPE; break;
 	case SDLK_QUOTE        : kevent.key.code = KEY_QUOTE; break;
@@ -91,6 +97,6 @@
 	mevent.mbutton.button  = MOUSE_NONE;
 	mevent.mbutton.pressed = (mb.state != SDL_RELEASED);
-	mevent.mbutton.x       = mb.x;
-	mevent.mbutton.y       = mb.y;
+	mevent.mbutton.x       = static_cast< uint16 >( mb.x );
+	mevent.mbutton.y       = static_cast< uint16 >( mb.y );
 
 	switch ( mb.button )
@@ -99,6 +105,6 @@
 	case SDL_BUTTON_MIDDLE    : mevent.mbutton.button = MOUSE_MIDDLE; break;
 	case SDL_BUTTON_RIGHT     : mevent.mbutton.button = MOUSE_RIGHT; break;
-	case SDL_BUTTON_WHEELUP   : mevent.mbutton.button = MOUSE_WHEEL_UP; break;
-	case SDL_BUTTON_WHEELDOWN : mevent.mbutton.button = MOUSE_WHEEL_DOWN; break;
+	//case SDL_BUTTON_WHEELUP   : mevent.mbutton.button = MOUSE_WHEEL_UP; break;
+	//case SDL_BUTTON_WHEELDOWN : mevent.mbutton.button = MOUSE_WHEEL_DOWN; break;
 	default : break;
 	}
@@ -111,6 +117,6 @@
 	mevent.type          = EV_MOUSE_MOVE;
 	mevent.mmove.pressed = (mm.state != SDL_RELEASED);
-	mevent.mmove.x       = mm.x;
-	mevent.mmove.y       = mm.y;
+	mevent.mmove.x       = static_cast< uint16 >( mm.x );
+	mevent.mmove.y       = static_cast< uint16 >( mm.y );
 	return true;
 }
@@ -125,4 +131,5 @@
 	case SDL_MOUSEBUTTONDOWN : return sdl_mouse_button_to_io_event( e.button, ioevent );
 	case SDL_MOUSEBUTTONUP   : return sdl_mouse_button_to_io_event( e.button, ioevent );
+/* // SDL 2.0 incompatible 
 	case SDL_ACTIVEEVENT     : 
 		ioevent.type = EV_ACTIVE; 
@@ -134,8 +141,9 @@
 		ioevent.resize.y = e.resize.h;
 		return true;
+	case SDL_NOEVENT         : return false;
+	case SDL_VIDEOEXPOSE     : return false;
+*/
 	case SDL_SYSWMEVENT      : ioevent.type = EV_SYSTEM; return true;
 	case SDL_QUIT            : ioevent.type = EV_QUIT;   return true;
-	case SDL_NOEVENT         : return false;
-	case SDL_VIDEOEXPOSE     : return false;
 	case SDL_JOYAXISMOTION   : return false;
 	case SDL_JOYBALLMOTION   : return false;
@@ -149,11 +157,15 @@
 
 gl_window::gl_window( device* dev, uint16 width, uint16 height )
-	: m_device( dev ), m_width( width ), m_height( height ), m_title("NV Engine"), m_screen( nullptr )
-{
+	: m_device( dev ), m_width( width ), m_height( height ), m_title("NV Engine"), m_handle( nullptr )
+{
+#if NV_SDL_VERSION == NV_SDL_12
 	uint32 flags = SDL_OPENGL;
-	
-	m_screen = SDL_SetVideoMode( width, height, 32, flags );
-	
-	if ( m_screen == 0 )
+	m_handle = SDL_SetVideoMode( width, height, 32, flags );
+#elif NV_SDL_VERSION == NV_SDL_20
+	uint32 flags = SDL_WINDOW_OPENGL | SDL_WINDOW_SHOWN;
+	m_handle = SDL_CreateWindow("Nova Engine", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED,
+		width, height, flags );
+#endif
+	if ( m_handle == 0 )
 	{
 		NV_LOG( LOG_CRITICAL, "Video mode set failed: " << SDL_GetError( ) );
@@ -161,11 +173,5 @@
 	}
 
-	nv::load_gl_library();
-	NV_LOG( LOG_INFO, "OpenGL Vendor       : " << glGetString(GL_VENDOR) );
-	NV_LOG( LOG_INFO, "OpenGL Renderer     : " << glGetString(GL_RENDERER) );
-	NV_LOG( LOG_INFO, "OpenGL Version      : " << glGetString(GL_VERSION) );
-	NV_LOG( LOG_INFO, "OpenGL GLSL Version : " << glGetString(GL_SHADING_LANGUAGE_VERSION) );
-
-	m_context = new gl_context( m_device );
+	m_context = new gl_context( m_device, m_handle );
 	m_context->set_viewport( nv::ivec4( 0, 0, m_width, m_height ) );
 }
@@ -188,5 +194,9 @@
 void gl_window::set_title( const string& title )
 {
+#if NV_SDL_VERSION == NV_SDL_20
+	SDL_SetWindowTitle( static_cast<SDL_Window*>( m_handle ), title.c_str() );
+#else
 	SDL_WM_SetCaption( title.c_str(), title.c_str() );
+#endif
 	m_title = title;
 }
@@ -206,5 +216,9 @@
 void gl_window::swap_buffers()
 {
+#if NV_SDL_VERSION == NV_SDL_20
+	SDL_GL_SwapWindow( static_cast<SDL_Window*>( m_handle ) );
+#else
 	SDL_GL_SwapBuffers();
+#endif
 }
 
@@ -212,3 +226,6 @@
 {
 	delete m_context;
-}
+#if NV_SDL_VERSION == NV_SDL_20
+	SDL_DestroyWindow( static_cast<SDL_Window*>( m_handle ) );
+#endif
+}
Index: trunk/src/lib/sdl.cc
===================================================================
--- trunk/src/lib/sdl.cc	(revision 170)
+++ trunk/src/lib/sdl.cc	(revision 171)
@@ -13,5 +13,12 @@
 #define NV_SDL_FUN( rtype, fname, fparams ) rtype (NV_SDL_APIENTRY *fname) fparams = nullptr;
 #include <nv/lib/detail/sdl_functions.inc>
+#if NV_SDL_VERSION == NV_SDL_12
+#	include <nv/lib/detail/sdl_functions_12.inc>
+#elif NV_SDL_VERSION == NV_SDL_20
+#	include <nv/lib/detail/sdl_functions_20.inc>
+#endif
 #undef NV_SDL_FUN
+
+
 
 bool nv::load_sdl_library( const char* path )
@@ -22,4 +29,9 @@
 #	define NV_SDL_FUN( rtype, fname, fparams ) *(void **) (&fname) = sdl_library.get(#fname);
 #	include <nv/lib/detail/sdl_functions.inc>
+#	if NV_SDL_VERSION == NV_SDL_12
+#		include <nv/lib/detail/sdl_functions_12.inc>
+#	elif NV_SDL_VERSION == NV_SDL_20
+#		include <nv/lib/detail/sdl_functions_20.inc>
+#	endif
 #	undef NV_SDL_FUN
 	return true;
