Index: /trunk/nv/gl/gl_context.hh
===================================================================
--- /trunk/nv/gl/gl_context.hh	(revision 325)
+++ /trunk/nv/gl/gl_context.hh	(revision 326)
@@ -24,8 +24,7 @@
 	class gl_context : public context
 	{
-	protected:
-		gl_context( device* a_device );
 	public:
-		~gl_context();
+		gl_context( device* a_device, void* a_handle );
+		virtual ~gl_context();
 
 		virtual vertex_array create_vertex_array();
@@ -48,4 +47,6 @@
 		virtual void apply_render_state( const render_state& state );
 		virtual void apply_engine_uniforms( program p, const scene_state& s );
+		// TODO: remove
+		void* get_native_handle() { return m_handle; }
 
 	protected:
@@ -79,26 +80,8 @@
 		float m_clear_depth;
 		int   m_clear_stencil;
+		void* m_handle;
 
 		entity_store< vertex_array_info, vertex_array >  m_vertex_arrays;
 		entity_store< gl_framebuffer_info, framebuffer > m_framebuffers;
-	};
-
-	class sdl_gl_context : public gl_context
-	{
-	public:
-		sdl_gl_context( device* a_device, void* a_sdl_win_handle );
-		~sdl_gl_context();
-	private:
-		void* m_handle;
-	};
-
-	class native_gl_context : public gl_context
-	{
-	public:
-		native_gl_context( device* a_device, void* a_native_win_handle );
-		void* get_native_handle() { return m_handle; }
-		~native_gl_context();
-	private:
-		void* m_handle;
 	};
 
Index: /trunk/nv/gl/gl_device.hh
===================================================================
--- /trunk/nv/gl/gl_device.hh	(revision 325)
+++ /trunk/nv/gl/gl_device.hh	(revision 326)
@@ -40,6 +40,4 @@
 
 		gl_device();
-		virtual window* create_window( uint16 width, uint16 height, bool fullscreen );
-		virtual window* adopt_window( void* sys_w_handle, void* sys_dc );
 		virtual image_data* create_image_data( const std::string& filename ); // temporary
 
@@ -47,6 +45,4 @@
 		virtual buffer create_buffer( buffer_type type, buffer_hint hint, size_t size, const void* source = nullptr );
 		virtual texture create_texture( ivec2 size, image_format aformat, sampler asampler, void* data = nullptr );
-		virtual uint32 get_ticks();
-		virtual void delay( uint32 ms );
 
 		virtual void release( buffer b );
@@ -71,5 +67,4 @@
 		bool compile( uint32 sh_type, const std::string& shader_code, unsigned& glid );
 		std::string m_shader_header;
-		const void* m_info;
 		entity_store< gl_texture_info, texture >         m_textures;
 		entity_store< gl_buffer_info,  buffer >          m_buffers;
Index: /trunk/nv/gl/gl_window.hh
===================================================================
--- /trunk/nv/gl/gl_window.hh	(revision 325)
+++ /trunk/nv/gl/gl_window.hh	(revision 326)
@@ -14,4 +14,6 @@
 
 #include <nv/interface/window.hh>
+#include <nv/interface/window_manager.hh>
+#include <nv/interface/input.hh>
 #include <nv/gl/gl_context.hh>
 
@@ -22,24 +24,23 @@
 	{
 	public:
-		gl_window( device* dev, uint16 width, uint16 height, bool fullscreen = false );
-		gl_window( device* dev, void* handle, void* dc );
-		uint16 get_width() const;
-		uint16 get_height() const;
-		string get_title() const;
-		void set_title( const string& title );
-		virtual bool is_event_pending();
-		virtual bool poll_event( io_event& event );
-		virtual context* get_context() { return m_context; }
-		virtual device* get_device() { return m_device; }
+		gl_window( device* dev, window_manager* wm, input* a_input, void* handle, void* dc );
+		virtual void set_title( const string& ) {}
+		virtual context* get_context()    { return m_context; }
+		virtual device* get_device()      { return m_device; }
+		virtual uint16 get_width() const  { return m_width; }
+		virtual uint16 get_height() const { return m_height; }
+		virtual string get_title() const  { return std::string(); }
+		virtual bool is_event_pending()            { return m_input->is_event_pending(); }
+		virtual bool poll_event( io_event& event ) { return m_input->poll_event( event ); }
+
 		virtual void swap_buffers();
 		virtual ~gl_window();
 	private:
+		input*      m_input;
 		device*     m_device;
 		uint16      m_width;
 		uint16      m_height;
-		string      m_title;
 		void*       m_handle;
 		void*       m_hwnd;
-		bool        m_adopted;
 		gl_context* m_context;
 
Index: /trunk/nv/interface/device.hh
===================================================================
--- /trunk/nv/interface/device.hh	(revision 325)
+++ /trunk/nv/interface/device.hh	(revision 326)
@@ -130,10 +130,8 @@
 			initialize_engine_uniforms();
 		}
-		virtual window* create_window( uint16 width, uint16 height, bool fullscreen ) = 0;
-		virtual window* adopt_window( void* sys_w_handle, void* sys_dc ) = 0;
 		virtual program create_program( const string& vs_source, const string& fs_source ) = 0;
 		virtual buffer create_buffer( buffer_type type, buffer_hint hint, size_t size, const void* source = nullptr ) = 0;
+		virtual texture create_texture( ivec2 size, image_format aformat, sampler asampler, void* data = nullptr ) = 0;
 		virtual image_data* create_image_data( const std::string& filename ) = 0; // temporary
-		virtual texture create_texture( ivec2 size, image_format aformat, sampler asampler, void* data = nullptr ) = 0;
 		virtual void release( texture ) = 0;
 		virtual void release( buffer ) = 0;
@@ -141,6 +139,4 @@
 		virtual const texture_info* get_texture_info( texture ) const = 0;
 		virtual const buffer_info* get_buffer_info( buffer ) const = 0;
-		virtual uint32 get_ticks() = 0;
-		virtual void delay( uint32 ms ) = 0;
 		virtual const string& get_shader_header() const = 0;
 
Index: /trunk/nv/interface/input.hh
===================================================================
--- /trunk/nv/interface/input.hh	(revision 326)
+++ /trunk/nv/interface/input.hh	(revision 326)
@@ -0,0 +1,31 @@
+// Copyright (C) 2014 ChaosForge Ltd
+// http://chaosforge.org/
+//
+// This file is part of NV Libraries.
+// For conditions of distribution and use, see copyright notice in nv.hh
+/**
+ * @file input.hh
+ * @author Kornel Kisielewicz epyon@chaosforge.org
+ * @brief input interface
+ */
+
+#ifndef NV_INPUT_HH
+#define NV_INPUT_HH
+
+#include <nv/core/common.hh>
+#include <nv/core/io_event.hh>
+
+namespace nv
+{
+
+	class input
+	{
+	public:
+		virtual bool is_event_pending() = 0;
+		virtual bool poll_event( io_event& event ) = 0;
+		virtual ~input() {};
+	};
+
+}
+
+#endif // NV_INPUT_HH
Index: /trunk/nv/interface/window.hh
===================================================================
--- /trunk/nv/interface/window.hh	(revision 325)
+++ /trunk/nv/interface/window.hh	(revision 326)
@@ -10,6 +10,6 @@
  */
 
-#ifndef NV_GUI_WINDOW_HH
-#define NV_GUI_WINDOW_HH
+#ifndef NV_WINDOW_HH
+#define NV_WINDOW_HH
 
 #include <nv/core/common.hh>
@@ -21,4 +21,5 @@
 	class context;
 	class device;
+
 	class window
 	{
@@ -39,3 +40,3 @@
 
 
-#endif // NV_GUI_WINDOW_HH
+#endif // NV_WINDOW_HH
Index: /trunk/nv/interface/window_manager.hh
===================================================================
--- /trunk/nv/interface/window_manager.hh	(revision 326)
+++ /trunk/nv/interface/window_manager.hh	(revision 326)
@@ -0,0 +1,36 @@
+// Copyright (C) 2014 ChaosForge Ltd
+// http://chaosforge.org/
+//
+// This file is part of NV Libraries.
+// For conditions of distribution and use, see copyright notice in nv.hh
+/**
+ * @file window_manager.hh
+ * @author Kornel Kisielewicz epyon@chaosforge.org
+ * @brief Window Manager interface
+ */
+
+#ifndef NV_WINDOW_MANAGER_HH
+#define NV_WINDOW_MANAGER_HH
+
+#include <nv/core/common.hh>
+#include <nv/core/string.hh>
+
+namespace nv
+{
+	class context;
+	class device;
+	class window;
+	class image_data;
+
+	class window_manager
+	{
+	public:
+		virtual window* create_window( device* dev, uint16 width, uint16 height, bool fullscreen ) = 0;
+		virtual void* adopt_window( void* sys_w_handle ) = 0;
+		virtual void sleep( uint32 ms ) = 0;
+		virtual uint32 get_ticks() = 0;
+	};
+
+}
+
+#endif // NV_WINDOW_MANAGER_HH
Index: /trunk/nv/lib/detail/sdl_image_functions.inc
===================================================================
--- /trunk/nv/lib/detail/sdl_image_functions.inc	(revision 325)
+++ /trunk/nv/lib/detail/sdl_image_functions.inc	(revision 326)
@@ -21,5 +21,4 @@
 NV_SDL_FUN( SDL_Surface *, IMG_LoadTIF_RW, (SDL_RWops *src) );
 
-#if NV_SDL_VERSION == NV_SDL_20 
 NV_SDL_FUN( int , IMG_SavePNG,(SDL_Surface *surface, const char *file) );
 NV_SDL_FUN( int , IMG_SavePNG_RW,(SDL_Surface *surface, SDL_RWops *dst, int freedst) );
@@ -28,5 +27,2 @@
 NV_SDL_FUN( SDL_Texture *, IMG_LoadTextureTyped_RW,(SDL_Renderer *renderer, SDL_RWops *src, int freesrc, const char *type) );
 NV_SDL_FUN( SDL_Surface *, IMG_LoadTyped_RW, (SDL_RWops *src, int freesrc, const char *etype) );
-#else
-NV_SDL_FUN( SDL_Surface *, IMG_LoadTyped_RW, (SDL_RWops *src, int freesrc, char *etype) );
-#endif
Index: /trunk/nv/lib/wx.hh
===================================================================
--- /trunk/nv/lib/wx.hh	(revision 325)
+++ /trunk/nv/lib/wx.hh	(revision 326)
@@ -22,4 +22,7 @@
 #include <nv/lib/gl.hh>
 #include <nv/gl/gl_device.hh>
+#include <nv/gl/gl_window.hh>
+#include <nv/sdl/sdl_input.hh>
+#include <nv/sdl/sdl_window_manager.hh>
 #include <nv/interface/context.hh>
 #include <nv/interface/window.hh>
@@ -56,9 +59,10 @@
 		void OnPaint( wxPaintEvent& event );
 
-		nv::device*  m_device;
-		nv::context* m_context;
-		nv::window*  m_window;
+		nv::window_manager* m_wm;
+		nv::device*         m_device;
+		nv::context*        m_context;
+		nv::window*         m_window;
 		//wxTimer*     m_update_timer;
-		bool         m_render;
+		bool                m_render;
 		wxDECLARE_EVENT_TABLE();
 	};
@@ -84,6 +88,7 @@
 		nv::load_gl_no_context();
 		wxClientDC dc(this);
+		m_wm     = new nv::sdl::window_manager;
 		m_device = new nv::gl_device();
-		m_window = m_device->adopt_window( GetHWND(), dc.GetHDC() );
+		m_window  = new nv::gl_window( m_device, m_wm, new nv::sdl::input(), GetHWND(), dc.GetHDC() );
 		m_context = m_window->get_context();
 	}
Index: /trunk/nv/sdl/sdl_input.hh
===================================================================
--- /trunk/nv/sdl/sdl_input.hh	(revision 326)
+++ /trunk/nv/sdl/sdl_input.hh	(revision 326)
@@ -0,0 +1,35 @@
+// Copyright (C) 2014 ChaosForge Ltd
+// http://chaosforge.org/
+//
+// This file is part of NV Libraries.
+// For conditions of distribution and use, see copyright notice in nv.hh
+/**
+ * @file sdl_input.hh
+ * @author Kornel Kisielewicz epyon@chaosforge.org
+ * @brief SDL Input interface 
+ */
+
+#ifndef NV_SDL_INPUT_HH
+#define NV_SDL_INPUT_HH
+
+#include <nv/core/common.hh>
+#include <nv/interface/input.hh>
+
+namespace nv
+{
+
+	namespace sdl
+	{
+		class input : public nv::input
+		{
+		public:
+			input();
+			virtual bool is_event_pending();
+			virtual bool poll_event( io_event& event );
+			virtual ~input() {}
+		};
+	}
+
+}
+
+#endif // NV_SDL_INPUT_HH
Index: /trunk/nv/sdl/sdl_window.hh
===================================================================
--- /trunk/nv/sdl/sdl_window.hh	(revision 326)
+++ /trunk/nv/sdl/sdl_window.hh	(revision 326)
@@ -0,0 +1,53 @@
+// Copyright (C) 2014 ChaosForge Ltd
+// http://chaosforge.org/
+//
+// This file is part of NV Libraries.
+// For conditions of distribution and use, see copyright notice in nv.hh
+/**
+ * @file sdl_window.hh
+ * @author Kornel Kisielewicz epyon@chaosforge.org
+ * @brief SDL Window implementation
+ */
+
+#ifndef NV_SDL_WINDOW_HH
+#define NV_SDL_WINDOW_HH
+
+#include <nv/interface/window.hh>
+#include <nv/interface/input.hh>
+#include <nv/gl/gl_context.hh>
+
+namespace nv
+{
+
+	namespace sdl
+	{
+		class window : public nv::window
+		{
+		public:
+			window( device* dev, uint16 width, uint16 height, bool fullscreen = false );
+			virtual void set_title( const string& title );
+			virtual void swap_buffers();
+
+			virtual context* get_context()    { return m_context; }
+			virtual device* get_device()      { return m_device; }
+			virtual uint16 get_width() const  { return m_width; }
+			virtual uint16 get_height() const { return m_height; }
+			virtual string get_title() const  { return m_title; }
+			virtual bool is_event_pending()            { return m_input->is_event_pending(); }
+			virtual bool poll_event( io_event& event ) { return m_input->poll_event( event ); }
+
+			virtual ~window();
+		private:
+			nv::input*  m_input;
+			device*     m_device;
+			uint16      m_width;
+			uint16      m_height;
+			string      m_title;
+			void*       m_handle;
+			gl_context* m_context;
+		};
+	}
+
+}
+
+#endif // NV_SDL_WINDOW_HH
Index: /trunk/nv/sdl/sdl_window_manager.hh
===================================================================
--- /trunk/nv/sdl/sdl_window_manager.hh	(revision 326)
+++ /trunk/nv/sdl/sdl_window_manager.hh	(revision 326)
@@ -0,0 +1,37 @@
+// Copyright (C) 2014 ChaosForge Ltd
+// http://chaosforge.org/
+//
+// This file is part of Nova Libraries.
+// For conditions of distribution and use, see copyright notice in nv.hh
+/**
+ * @file sdl_window_manager.hh
+ * @author Kornel Kisielewicz epyon@chaosforge.org
+ * @brief SDL Window manager implementation
+ */
+
+#ifndef NV_SDL_WINDOW_MANAGER_HH
+#define NV_SDL_WINDOW_MANAGER_HH
+
+#include <nv/interface/window_manager.hh>
+#include <nv/interface/input.hh>
+
+namespace nv
+{
+
+	namespace sdl
+	{
+		class window_manager : public nv::window_manager
+		{
+		public:
+			window_manager();
+			virtual nv::window* create_window( device* dev, uint16 width, uint16 height, bool fullscreen );
+			virtual void* adopt_window( void* sys_w_handle );
+			virtual void sleep( uint32 ms );
+			virtual uint32 get_ticks();
+			virtual ~window_manager();
+		};
+	}
+
+}
+
+#endif // NV_SDL_WINDOW_MANAGER_HH
Index: /trunk/src/gl/gl_context.cc
===================================================================
--- /trunk/src/gl/gl_context.cc	(revision 325)
+++ /trunk/src/gl/gl_context.cc	(revision 326)
@@ -7,5 +7,4 @@
 #include "nv/gl/gl_enum.hh"
 #include "nv/lib/gl.hh"
-#include "nv/lib/sdl.hh"
 #include "nv/gl/gl_device.hh"
 
@@ -577,7 +576,8 @@
 
 
-gl_context::gl_context( device* a_device )
-	: context( a_device )
-{
+gl_context::gl_context( device* a_device, void* a_handle )
+	: context( a_device ), m_handle( a_handle )
+{
+	force_apply_render_state( m_render_state );
 }
 
@@ -623,112 +623,2 @@
 	}
 }
-
-nv::sdl_gl_context::sdl_gl_context( device* a_device, void* a_sdl_win_handle )
-	: gl_context( a_device ), m_handle( nullptr )
-{
-#if NV_SDL_VERSION == NV_SDL_20
-	m_handle = SDL_GL_CreateContext( static_cast<SDL_Window*>( a_sdl_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 );
-	NV_UNUSED( m_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::sdl_gl_context::~sdl_gl_context()
-{
-#if NV_SDL_VERSION == NV_SDL_20
-	SDL_GL_DeleteContext(static_cast<SDL_GLContext>( m_handle ) );
-#endif
-}
-
-nv::native_gl_context::native_gl_context( device* a_device, void* a_native_win_handle )
-	: gl_context( a_device ), m_handle( nullptr )
-{
-#if NV_PLATFORM == NV_WINDOWS
-
-// TODO: error checking
-	HDC hdc = (HDC)a_native_win_handle;
-
-	const int wgl_attrib_list[] =
-	{
-		WGL_DRAW_TO_WINDOW_ARB, GL_TRUE,
-		WGL_SUPPORT_OPENGL_ARB, GL_TRUE,
-		WGL_ACCELERATION_ARB,   WGL_FULL_ACCELERATION_ARB,
-		WGL_DOUBLE_BUFFER_ARB,  GL_TRUE,
-		WGL_PIXEL_TYPE_ARB,     WGL_TYPE_RGBA_ARB,
-		WGL_COLOR_BITS_ARB,     32,
-		WGL_DEPTH_BITS_ARB,     24,
-		WGL_STENCIL_BITS_ARB,   8,
-		0, 0  //End
-	};
-
-	unsigned int num_formats;
-	int pixel_format;
-	PIXELFORMATDESCRIPTOR pfd;
-
-	if ( FALSE == wglChoosePixelFormatARB(hdc, wgl_attrib_list, NULL, 1, &pixel_format, &num_formats) )
-	{
-		return;
-	}
-
-	if ( FALSE == SetPixelFormat(hdc, pixel_format, &pfd) )
-	{
-		//int err = GetLastError();
-		return;
-	}
-
-	int attribs[] =
-	{
-		WGL_CONTEXT_MAJOR_VERSION_ARB,   2,
-		WGL_CONTEXT_MINOR_VERSION_ARB,   1,
-		WGL_CONTEXT_PROFILE_MASK_ARB,  WGL_CONTEXT_CORE_PROFILE_BIT_ARB, 
-		//WGL_CONTEXT_PROFILE_MASK_ARB, WGL_CONTEXT_COMPATIBILITY_PROFILE_BIT_ARB,
-		0, 0  //End
-	};
-
-	HGLRC handle;
-	if ( 0 == (handle = wglCreateContextAttribsARB(hdc, 0, attribs) ) )
-	{
-		return;
-	}
-
-	if ( FALSE == dynwglMakeCurrent( hdc, handle ) )
-	{
-		return;
-	}     
-
-	load_gl_library( NV_GL_PATH, true );
-	load_wgl_library( NV_GL_PATH, true );
-	m_handle = (void*)handle;
-#else
-	NV_ASSERT( false, "Native GL context not implemented for this platform!" );
-#endif
-	force_apply_render_state( m_render_state );
-}
-
-nv::native_gl_context::~native_gl_context()
-{
-#if NV_PLATFORM == NV_WINDOWS
-	dynwglDeleteContext( (HGLRC)m_handle );
-#endif
-}
Index: /trunk/src/gl/gl_device.cc
===================================================================
--- /trunk/src/gl/gl_device.cc	(revision 325)
+++ /trunk/src/gl/gl_device.cc	(revision 326)
@@ -7,5 +7,4 @@
 #include "nv/gl/gl_window.hh"
 #include "nv/core/logging.hh"
-#include "nv/lib/sdl.hh"
 #include "nv/lib/sdl_image.hh"
 #include "nv/gl/gl_enum.hh"
@@ -14,37 +13,6 @@
 using namespace nv;
 
-window* gl_device::create_window( uint16 width, uint16 height, bool fullscreen )
-{
-	return new gl_window( this, width, height, fullscreen );
-}
-
-window* nv::gl_device::adopt_window( void* sys_w_handle, void* sys_dc )
-{
-	return new gl_window( this, sys_w_handle, sys_dc );
-}
-
-
-
 gl_device::gl_device()
 {
-	nv::load_sdl_library();
-	m_info = NULL;
-
-	if ( SDL_Init( SDL_INIT_VIDEO | SDL_INIT_JOYSTICK ) < 0 )
-	{
-		NV_LOG( LOG_CRITICAL, "Video initialization failed: " << SDL_GetError( ) );
-		return; // TODO: Error report
-	}
-
-#if NV_SDL_VERSION == NV_SDL_12
-	m_info = SDL_GetVideoInfo( );
-
-	if ( !m_info )
-	{
-		NV_LOG( LOG_CRITICAL, "Video query failed: " << SDL_GetError( ) );
-		return; // TODO: Error report
-	}
-#endif
-
 	m_shader_header  = "#version 120\n";
 	for ( auto& i : get_uniform_factory() ) 
@@ -67,5 +35,5 @@
 // this is a temporary function that will be removed once we find a way to 
 // pass binary file data around
-image_data* nv::gl_device::create_image_data( const std::string& filename )
+image_data* gl_device::create_image_data( const std::string& filename )
 {
 	load_sdl_image_library();
@@ -83,13 +51,4 @@
 }
 
-uint32 gl_device::get_ticks()
-{
-	return SDL_GetTicks();
-}
-
-void gl_device::delay( uint32 ms )
-{
-	return SDL_Delay( ms );
-}
 
 gl_device::~gl_device()
@@ -101,5 +60,4 @@
 	while ( m_programs.size() > 0 )
 		release( m_programs.get_handle(0) );
-	SDL_Quit();
 }
 
Index: /trunk/src/gl/gl_window.cc
===================================================================
--- /trunk/src/gl/gl_window.cc	(revision 325)
+++ /trunk/src/gl/gl_window.cc	(revision 326)
@@ -7,331 +7,13 @@
 #include "nv/core/logging.hh"
 #include "nv/lib/gl.hh"
-#include "nv/lib/sdl.hh"
 
 using namespace nv;
 
-static bool sdl_key_event_to_io_event( const SDL_KeyboardEvent& ke, io_event& kevent )
-{
-	kevent.type        = EV_KEY;
-	kevent.key.pressed = ( ke.state != SDL_RELEASED );
-	kevent.key.ascii   = 0;
-	kevent.key.code    = KEY_NONE;
-
-#if NV_SDL_VERSION == NV_SDL_20
-	uint32 ucode = (uint32)ke.keysym.sym;
-#else
-	uint32 ucode = (uint32)ke.keysym.unicode;
-#endif
-
-	// if result is a typable char place it into the structure
-	if (ucode >= 32 && ucode < 128 )
-	{
-		kevent.key.ascii = static_cast<char8>( ucode );
-#if NV_SDL_VERSION == NV_SDL_20
-		if (ucode >= 'a' && ucode <= 'z')
-		{
-			int shifted = !!(ke.keysym.mod & KMOD_SHIFT);
-			int capslock = !!(ke.keysym.mod & KMOD_CAPS);
-			if ((shifted ^ capslock) != 0) {
-				kevent.key.ascii = (char8)SDL_toupper((int)ucode);
-			}
-		}
-#endif
-	}
-
-	// Get the Key value from the SDL Keyboard event
-	int result = ke.keysym.sym;
-
-	// Check the control and shift states
-	kevent.key.alt     = (ke.keysym.mod & KMOD_ALT ) != 0;
-	kevent.key.control = (ke.keysym.mod & KMOD_CTRL ) != 0;
-	kevent.key.shift   = (ke.keysym.mod & KMOD_SHIFT ) != 0;
-
-	// if result is a typable char from the directly transformable ranges
-	if ( ( result >= KEY_A && result <= KEY_Z ) || 
-		( result >= KEY_0 && result <= KEY_9 ) ||
-		result == ' ' )
-	{
-		kevent.key.code = static_cast<key_code>(result);
-	}
-
-	// if result is a typable char from the a..z range
-	if ( result >= KEY_A + 32 && result <= KEY_Z + 32 )
-	{
-		kevent.key.code = static_cast<key_code>(result - 32);
-	}
-
-	if ( result >= SDLK_F1 && result <= SDLK_F12 )
-	{
-		kevent.key.code = static_cast<key_code>(result - SDLK_F1 + KEY_F1 );
-	}
-
-	// other recognized codes
-	switch ( result ) 
-	{
-	case SDLK_BACKSPACE    : kevent.key.code = KEY_BACK; break;
-	case SDLK_TAB          : kevent.key.code = KEY_TAB; break;
-	case SDLK_RETURN       : kevent.key.code = KEY_ENTER; break;
-	case SDLK_PAGEUP       : kevent.key.code = KEY_PGUP; break;
-	case SDLK_PAGEDOWN     : kevent.key.code = KEY_PGDOWN; break;
-	case SDLK_END          : kevent.key.code = KEY_END; break;
-	case SDLK_HOME         : kevent.key.code = KEY_HOME; break;
-	case SDLK_LEFT         : kevent.key.code = KEY_LEFT; break;
-	case SDLK_UP           : kevent.key.code = KEY_UP; break;
-	case SDLK_RIGHT        : kevent.key.code = KEY_RIGHT; break;
-	case SDLK_DOWN         : kevent.key.code = KEY_DOWN; break;
-	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_ESCAPE       : kevent.key.code = KEY_ESCAPE; break;
-	case SDLK_QUOTE        : kevent.key.code = KEY_QUOTE; break;
-	case SDLK_COMMA        : kevent.key.code = KEY_COMMA; break;
-	case SDLK_MINUS        : kevent.key.code = KEY_MINUS; break;
-	case SDLK_PERIOD       : kevent.key.code = KEY_PERIOD; break;
-	case SDLK_SLASH        : kevent.key.code = KEY_SLASH; break;
-	case SDLK_SEMICOLON    : kevent.key.code = KEY_SCOLON; break;
-	case SDLK_LEFTBRACKET  : kevent.key.code = KEY_LBRACKET; break;
-	case SDLK_BACKSLASH    : kevent.key.code = KEY_BSLASH; break;
-	case SDLK_RIGHTBRACKET : kevent.key.code = KEY_RBRACKET; break;
-	case SDLK_BACKQUOTE    : kevent.key.code = KEY_BQUOTE; break;
-	default : break;
-	}
-
-	// If key was understood by nv, then it's valid, otherwise ignored
-	return kevent.key.ascii != 0 || kevent.key.code != 0;
-}
-
-static bool sdl_mouse_button_to_io_event( const SDL_MouseButtonEvent& mb, io_event& mevent )
-{
-	mevent.type            = EV_MOUSE_BUTTON;
-	mevent.mbutton.button  = MOUSE_NONE;
-	mevent.mbutton.pressed = (mb.state != SDL_RELEASED);
-	mevent.mbutton.x       = static_cast< uint16 >( mb.x );
-	mevent.mbutton.y       = static_cast< uint16 >( mb.y );
-
-	switch ( mb.button )
-	{
-	case SDL_BUTTON_LEFT      : mevent.mbutton.button = MOUSE_LEFT; break;
-	case SDL_BUTTON_MIDDLE    : mevent.mbutton.button = MOUSE_MIDDLE; break;
-	case SDL_BUTTON_RIGHT     : mevent.mbutton.button = MOUSE_RIGHT; break;
-#if NV_SDL_VERSION == NV_SDL_12
-	case SDL_BUTTON_WHEELUP   : 
-		mevent.type           = EV_MOUSE_WHEEL;
-		mevent.mwheel.x       = 0;
-		mevent.mwheel.y       = 3;
-		return true;
-	case SDL_BUTTON_WHEELDOWN : 
-		mevent.type           = EV_MOUSE_WHEEL;
-		mevent.mwheel.x       = 0;
-		mevent.mwheel.y       = -3;
-		return true;
-#endif
-	default : break;
-	}
-
-	return mevent.mbutton.button != MOUSE_NONE;
-}
-
-#if NV_SDL_VERSION == NV_SDL_20
-static bool sdl_mouse_wheel_to_io_event( const SDL_MouseWheelEvent& mm, io_event& mevent )
-{
-	mevent.type          = EV_MOUSE_WHEEL;
-	mevent.mwheel.x      = static_cast< sint32 >( mm.x );
-	mevent.mwheel.y      = static_cast< sint32 >( mm.y );
-	return true;
-}
-#endif
-
-static bool sdl_mouse_motion_to_io_event( const SDL_MouseMotionEvent& mm, io_event& mevent )
-{
-	mevent.type          = EV_MOUSE_MOVE;
-	mevent.mmove.pressed = (mm.state != SDL_RELEASED);
-	mevent.mmove.x       = static_cast< uint16 >( mm.x );
-	mevent.mmove.y       = static_cast< uint16 >( mm.y );
-	mevent.mmove.rx      = static_cast< sint16 >( mm.xrel );
-	mevent.mmove.ry      = static_cast< sint16 >( mm.yrel );
-	return true;
-}
-
-static bool sdl_joy_button_event_to_io_event( const SDL_JoyButtonEvent& jb, io_event& jevent )
-{
-	jevent.type            = EV_JOY_BUTTON;
-	jevent.jbutton.id      = jb.which;
-	jevent.jbutton.button  = jb.button;
-	jevent.jbutton.pressed = (jb.type == SDL_PRESSED);
-	return true;
-}
-
-static bool sdl_joy_axis_event_to_io_event( const SDL_JoyAxisEvent& ja, io_event& jevent )
-{
-	jevent.type          = EV_JOY_AXIS;
-	jevent.jaxis.id      = ja.which;
-	jevent.jaxis.axis    = ja.axis;
-	jevent.jaxis.value   = ja.value;
-	return true;
-}
-
-static bool sdl_joy_hat_event_to_io_event( const SDL_JoyHatEvent& jh, io_event& jevent )
-{
-	jevent.type          = EV_JOY_HAT;
-	jevent.jhat.id       = jh.which;
-	jevent.jhat.hat      = jh.hat;
-	jevent.jhat.value    = jh.value;
-	return true;
-}
-
-static bool sdl_joy_ball_event_to_io_event( const SDL_JoyBallEvent& jb, io_event& jevent )
-{
-	jevent.type          = EV_JOY_HAT;
-	jevent.jball.id      = jb.which;
-	jevent.jball.ball    = jb.ball;
-	jevent.jball.rx      = jb.xrel;
-	jevent.jball.ry      = jb.yrel;
-	return true;
-}
-
-static bool sdl_event_to_io_event( const SDL_Event& e, io_event& ioevent )
-{
-	switch ( e.type )
-	{
-	case SDL_KEYDOWN         : return sdl_key_event_to_io_event( e.key, ioevent );
-	case SDL_KEYUP           : return sdl_key_event_to_io_event( e.key, ioevent );
-	case SDL_MOUSEMOTION     : return sdl_mouse_motion_to_io_event( e.motion, ioevent );
-	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 );
-#if NV_SDL_VERSION == NV_SDL_20
-	case SDL_MOUSEWHEEL      : return sdl_mouse_wheel_to_io_event( e.wheel, ioevent );
-#endif
-/* // SDL 2.0 incompatible 
-	case SDL_ACTIVEEVENT     : 
-		ioevent.type = EV_ACTIVE; 
-		ioevent.active.gain = (e.active.gain != 0); 
-		return e.active.state == SDL_APPINPUTFOCUS;
-	case SDL_VIDEORESIZE     : 
-		ioevent.type     = EV_RESIZE; 
-		ioevent.resize.x = e.resize.w;
-		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_JOYAXISMOTION   : return sdl_joy_axis_event_to_io_event( e.jaxis, ioevent ); 
-	case SDL_JOYBALLMOTION   : return sdl_joy_ball_event_to_io_event( e.jball, ioevent ); 
-	case SDL_JOYHATMOTION    : return sdl_joy_hat_event_to_io_event( e.jhat, ioevent ); 
-	case SDL_JOYBUTTONDOWN   : return sdl_joy_button_event_to_io_event( e.jbutton, ioevent );
-	case SDL_JOYBUTTONUP     : return sdl_joy_button_event_to_io_event( e.jbutton, ioevent );
-	default : return false;
-	}
-}
-
-
-gl_window::gl_window( device* dev, uint16 width, uint16 height, bool fullscreen )
-	: m_device( dev ), m_width( width ), m_height( height ), m_title("NV Engine"), m_handle( nullptr ), m_hwnd( 0 ), m_adopted( false )
-{
-	//	bpp = m_info->vfmt->BitsPerPixel;
-
-	SDL_GL_SetAttribute( SDL_GL_RED_SIZE, 8 );
-	SDL_GL_SetAttribute( SDL_GL_GREEN_SIZE, 8 );
-	SDL_GL_SetAttribute( SDL_GL_BLUE_SIZE, 8 );
-	SDL_GL_SetAttribute( SDL_GL_DEPTH_SIZE, 24 );
-	SDL_GL_SetAttribute( SDL_GL_DOUBLEBUFFER, 1 );
-
-	//	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
-
-
-#if NV_SDL_VERSION == NV_SDL_12
-	uint32 flags = SDL_OPENGL;
-	if (fullscreen) flags |= SDL_FULLSCREEN;
-	m_handle = SDL_SetVideoMode( width, height, 32, flags );
-#elif NV_SDL_VERSION == NV_SDL_20
-	uint32 flags = SDL_WINDOW_OPENGL | SDL_WINDOW_SHOWN;
-	if (fullscreen) flags |= SDL_WINDOW_FULLSCREEN;
-	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( ) );
-		return; // TODO: Error report
-	}
-
-// 	NV_LOG( LOG_INFO, "Joystick count : " << SDL_NumJoysticks() );
-// 	SDL_Joystick* j = SDL_JoystickOpen(0);
-// 	if (j)
-// 	{
-// 		NV_LOG( LOG_INFO, "Joystick Name: " << SDL_JoystickNameForIndex(0) );
-// 		NV_LOG( LOG_INFO, "Joystick Number of Axes: " << SDL_JoystickNumAxes(j));
-// 		NV_LOG( LOG_INFO, "Joystick Number of Buttons: " << SDL_JoystickNumButtons(j));
-// 		NV_LOG( LOG_INFO, "Joystick Number of Balls: " << SDL_JoystickNumBalls(j));
-// 	}
-
-
-	m_context = new sdl_gl_context( m_device, m_handle );
-	m_context->set_viewport( nv::ivec4( 0, 0, m_width, m_height ) );
-}
-
-uint16 gl_window::get_width() const
-{
-	return m_width;
-}
-
-uint16 gl_window::get_height() const
-{
-	return m_height;
-}
-
-string gl_window::get_title() const
-{
-	return m_title;
-}
-
-void gl_window::set_title( const string& title )
-{
-	if ( m_adopted ) return;
-#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;
-}
-
-bool gl_window::is_event_pending()
-{
-	return SDL_PollEvent( nullptr ) != 0;
-}
-
-bool gl_window::poll_event( io_event& event )
-{
-	SDL_Event sdl_event;
-	if ( SDL_PollEvent( &sdl_event ) == 0 ) return false;
-	return sdl_event_to_io_event( sdl_event, event );
-}
-
 void gl_window::swap_buffers()
 {
-	if ( m_adopted )
-	{
 #if NV_PLATFORM == NV_WINDOWS
 		::SwapBuffers( (HDC)m_hwnd );
 #else
-	NV_ASSERT( false, "Native GL context only working with SDL 2.0!" );
-#endif
-
-	}
-#if NV_SDL_VERSION == NV_SDL_20
-	SDL_GL_SwapWindow( static_cast<SDL_Window*>( m_handle ) );
-#else
-	SDL_GL_SwapBuffers();
+	NV_ASSERT( false, "Native GL context currently only working on Windows!" );
 #endif
 }
@@ -339,17 +21,78 @@
 gl_window::~gl_window()
 {
+	if ( m_context )
+	{
+#if NV_PLATFORM == NV_WINDOWS
+			dynwglDeleteContext( (HGLRC)m_context->get_native_handle() );
+#endif
+	}
 	delete m_context;
-#if NV_SDL_VERSION == NV_SDL_20
-	if ( !m_adopted ) SDL_DestroyWindow( static_cast<SDL_Window*>( m_handle ) );
-#endif
+	m_context = nullptr;
+	delete m_input;
 }
 
-nv::gl_window::gl_window( device* dev, void* handle, void* dc )
-	: m_device( dev ), m_width( 0 ), m_height( 0 ), m_title(), m_handle( nullptr ), m_adopted( true )
+nv::gl_window::gl_window( device* dev, window_manager* wm, input* a_input, void* handle, void* dc )
+	: m_device( dev ), m_width( 0 ), m_height( 0 ), m_handle( nullptr )
 {
 #if NV_PLATFORM == NV_WINDOWS
-#if NV_SDL_VERSION == NV_SDL_20
-	m_context = new native_gl_context( m_device, dc );
-	SDL_Window* window = SDL_CreateWindowFrom( handle );
+	m_input = a_input;
+
+	m_handle = (void*)handle;
+
+	// TODO: error checking
+	HDC hdc = (HDC)dc;
+
+	const int wgl_attrib_list[] =
+	{
+		WGL_DRAW_TO_WINDOW_ARB, GL_TRUE,
+		WGL_SUPPORT_OPENGL_ARB, GL_TRUE,
+		WGL_ACCELERATION_ARB,   WGL_FULL_ACCELERATION_ARB,
+		WGL_DOUBLE_BUFFER_ARB,  GL_TRUE,
+		WGL_PIXEL_TYPE_ARB,     WGL_TYPE_RGBA_ARB,
+		WGL_COLOR_BITS_ARB,     32,
+		WGL_DEPTH_BITS_ARB,     24,
+		WGL_STENCIL_BITS_ARB,   8,
+		0, 0  //End
+	};
+
+	unsigned int num_formats;
+	int pixel_format;
+	PIXELFORMATDESCRIPTOR pfd;
+
+	if ( FALSE == wglChoosePixelFormatARB(hdc, wgl_attrib_list, NULL, 1, &pixel_format, &num_formats) )
+	{
+		return;
+	}
+
+	if ( FALSE == SetPixelFormat(hdc, pixel_format, &pfd) )
+	{
+		//int err = GetLastError();
+		return;
+	}
+
+	int attribs[] =
+	{
+		WGL_CONTEXT_MAJOR_VERSION_ARB,   2,
+		WGL_CONTEXT_MINOR_VERSION_ARB,   1,
+		WGL_CONTEXT_PROFILE_MASK_ARB,  WGL_CONTEXT_CORE_PROFILE_BIT_ARB, 
+		//WGL_CONTEXT_PROFILE_MASK_ARB, WGL_CONTEXT_COMPATIBILITY_PROFILE_BIT_ARB,
+		0, 0  //End
+	};
+
+	HGLRC ctx_handle;
+	if ( 0 == (ctx_handle = wglCreateContextAttribsARB(hdc, 0, attribs) ) )
+	{
+		return;
+	}
+
+	if ( FALSE == dynwglMakeCurrent( hdc, ctx_handle ) )
+	{
+		return;
+	}     
+
+	load_gl_library( NV_GL_PATH, true );
+	load_wgl_library( NV_GL_PATH, true );
+
+	m_context = new gl_context( m_device, ctx_handle );
 	// Doesn't work :/
 // 	RECT rect;
@@ -357,12 +100,10 @@
 //  	m_width   = (uint16)rect.right;
 //  	m_height  = (uint16)rect.bottom;
-	m_handle  = window;
+	m_handle  = wm->adopt_window( handle );
 	m_hwnd    = ::GetDC( (HWND)handle );
 	m_context->set_viewport( nv::ivec4( 0, 0, m_width, m_height ) );
-#else
-	NV_ASSERT( false, "Native GL context only working with SDL 2.0!" );
-#endif
 #else
 	NV_ASSERT( false, "Native GL context adoption not implemented for this platform!" );
 #endif
 }
+
Index: /trunk/src/lib/sdl.cc
===================================================================
--- /trunk/src/lib/sdl.cc	(revision 325)
+++ /trunk/src/lib/sdl.cc	(revision 326)
@@ -13,12 +13,5 @@
 #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 )
@@ -29,9 +22,4 @@
 #	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;
