Index: trunk/src/gl/gl_context.cc
===================================================================
--- trunk/src/gl/gl_context.cc	(revision 243)
+++ trunk/src/gl/gl_context.cc	(revision 245)
@@ -362,9 +362,40 @@
 
 
-gl_context::gl_context( device* a_device, void* a_win_handle )
-	: context( a_device ), m_handle( nullptr )
+gl_context::gl_context( device* a_device )
+	: context( a_device )
+{
+}
+
+
+nv::gl_context::~gl_context()
+{
+}
+
+
+void gl_context::draw( primitive prim, const render_state& rs, program* p, vertex_array* va, size_t count )
+{
+	apply_render_state( rs );
+	if ( count > 0 )
+	{
+		p->bind();
+		va->bind();
+		if ( va->has_index_buffer() )
+		{
+			glDrawElements( primitive_to_enum(prim), static_cast<GLsizei>( count ), datatype_to_gl_enum( va->get_index_buffer_type() ), 0 );
+		}
+		else
+		{
+			glDrawArrays( primitive_to_enum(prim), 0, static_cast<GLsizei>( count ) );
+		}
+		va->unbind();
+		p->unbind();
+	}
+}
+
+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_win_handle ) );
+	m_handle = SDL_GL_CreateContext( static_cast<SDL_Window*>( a_sdl_win_handle ) );
 
 	if ( m_handle == 0 )
@@ -384,5 +415,5 @@
 	NV_LOG( LOG_INFO, "OpenGL GLSL Version : " << glGetString(GL_SHADING_LANGUAGE_VERSION) );
 #if NV_SDL_VERSION == NV_SDL_20
-//	SDL_GL_SetSwapInterval(1);
+	//	SDL_GL_SetSwapInterval(1);
 #endif
 
@@ -393,6 +424,5 @@
 }
 
-
-nv::gl_context::~gl_context()
+nv::sdl_gl_context::~sdl_gl_context()
 {
 #if NV_SDL_VERSION == NV_SDL_20
@@ -401,22 +431,71 @@
 }
 
-
-void gl_context::draw( primitive prim, const render_state& rs, program* p, vertex_array* va, size_t count )
-{
-	apply_render_state( rs );
-	if ( count > 0 )
-	{
-		p->bind();
-		va->bind();
-		if ( va->has_index_buffer() )
-		{
-			glDrawElements( primitive_to_enum(prim), static_cast<GLsizei>( count ), datatype_to_gl_enum( va->get_index_buffer_type() ), 0 );
-		}
-		else
-		{
-			glDrawArrays( primitive_to_enum(prim), 0, static_cast<GLsizei>( count ) );
-		}
-		va->unbind();
-		p->unbind();
-	}
-}
+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;
+	}     
+
+	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 243)
+++ trunk/src/gl/gl_device.cc	(revision 245)
@@ -20,4 +20,11 @@
 }
 
+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()
 {
@@ -39,22 +46,4 @@
 		return; // TODO: Error report
 	}
-#endif
-
-//	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
 
Index: trunk/src/gl/gl_window.cc
===================================================================
--- trunk/src/gl/gl_window.cc	(revision 243)
+++ trunk/src/gl/gl_window.cc	(revision 245)
@@ -34,5 +34,5 @@
 			int capslock = !!(ke.keysym.mod & KMOD_CAPS);
 			if ((shifted ^ capslock) != 0) {
-				kevent.key.ascii = SDL_toupper(ucode);
+				kevent.key.ascii = (char8)SDL_toupper(ucode);
 			}
 		}
@@ -204,6 +204,25 @@
 
 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_device( dev ), m_width( width ), m_height( height ), m_title("NV Engine"), m_handle( nullptr ), 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;
@@ -233,5 +252,5 @@
 
 
-	m_context = new gl_context( m_device, m_handle );
+	m_context = new sdl_gl_context( m_device, m_handle );
 	m_context->set_viewport( nv::ivec4( 0, 0, m_width, m_height ) );
 }
@@ -254,4 +273,5 @@
 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() );
@@ -276,4 +296,5 @@
 void gl_window::swap_buffers()
 {
+	if ( m_adopted ) return; // NOT SURE
 #if NV_SDL_VERSION == NV_SDL_20
 	SDL_GL_SwapWindow( static_cast<SDL_Window*>( m_handle ) );
@@ -287,5 +308,28 @@
 	delete m_context;
 #if NV_SDL_VERSION == NV_SDL_20
-	SDL_DestroyWindow( static_cast<SDL_Window*>( m_handle ) );
-#endif
-}
+	if ( !m_adopted ) SDL_DestroyWindow( static_cast<SDL_Window*>( m_handle ) );
+#endif
+}
+
+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 )
+{
+#if NV_PLATFORM == NV_WINDOWS
+#if NV_SDL_VERSION == NV_SDL_20
+	nv::load_gl_no_context();
+	m_context = new native_gl_context( m_device, dc );
+	SDL_Window* window = SDL_CreateWindowFrom( handle );
+	// Doesn't work :/
+// 	RECT rect;
+// 	GetClientRect( (HWND)handle, &rect );
+//  	m_width   = (uint16)rect.right;
+//  	m_height  = (uint16)rect.bottom;
+	m_handle  = window;
+	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
+}
