Index: trunk/nv/gl/gl_context.hh
===================================================================
--- trunk/nv/gl/gl_context.hh	(revision 244)
+++ trunk/nv/gl/gl_context.hh	(revision 245)
@@ -19,6 +19,7 @@
 	class gl_context : public context
 	{
+	protected:
+		gl_context( device* a_device );
 	public:
-		gl_context( device* a_device, void* a_win_handle );
 		~gl_context();
 		virtual void clear( const clear_state& cs );
@@ -28,7 +29,8 @@
 		virtual void set_viewport( const ivec4& viewport );
 		virtual void apply_render_state( const render_state& state );
-	private:
+	protected:
 		void force_apply_render_state( const render_state& state );
 		void force_apply_stencil_face( unsigned face, const stencil_test_face& stencil );
+	private:
 		void apply_stencil_test( const stencil_test& stencil );
 		void apply_stencil_face( unsigned face, stencil_test_face& stencil, const stencil_test_face& new_stencil );
@@ -47,6 +49,24 @@
 		float m_clear_depth;
 		int   m_clear_stencil;
+	};
+
+	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 );
+		~native_gl_context();
+	private:
+		void* m_handle;
+	};
+
 
 } // namespace nv
Index: trunk/nv/gl/gl_device.hh
===================================================================
--- trunk/nv/gl/gl_device.hh	(revision 244)
+++ trunk/nv/gl/gl_device.hh	(revision 245)
@@ -22,4 +22,5 @@
 		gl_device();
 		virtual window* create_window( uint16 width, uint16 height, bool fullscreen );
+		virtual window* adopt_window( void* sys_w_handle, void* sys_dc );
 		virtual program* create_program( const string& vs_source, const string& fs_source );
 		virtual vertex_buffer* create_vertex_buffer( buffer_hint hint, size_t size, const void* source = nullptr );
Index: trunk/nv/gl/gl_window.hh
===================================================================
--- trunk/nv/gl/gl_window.hh	(revision 244)
+++ trunk/nv/gl/gl_window.hh	(revision 245)
@@ -23,4 +23,5 @@
 	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;
@@ -40,4 +41,5 @@
 		string      m_title;
 		void*       m_handle;
+		bool        m_adopted;
 		gl_context* m_context;
 
Index: trunk/nv/interface/device.hh
===================================================================
--- trunk/nv/interface/device.hh	(revision 244)
+++ trunk/nv/interface/device.hh	(revision 245)
@@ -29,4 +29,5 @@
 	public:
 		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 vertex_buffer* create_vertex_buffer( buffer_hint hint, size_t size, const void* source = nullptr ) = 0;
Index: trunk/nv/lib/detail/wgl_functions.inc
===================================================================
--- trunk/nv/lib/detail/wgl_functions.inc	(revision 245)
+++ trunk/nv/lib/detail/wgl_functions.inc	(revision 245)
@@ -0,0 +1,74 @@
+NV_GL_FUN_REN( BOOL,  wglCopyContext,           dynwglCopyContext, (HGLRC, HGLRC, UINT) );
+NV_GL_FUN_REN( HGLRC, wglCreateContext,         dynwglCreateContext, (HDC) );
+NV_GL_FUN_REN( HGLRC, wglCreateLayerContext,    dynwglCreateLayerContext, (HDC, int) );
+NV_GL_FUN_REN( BOOL,  wglDeleteContext,         dynwglDeleteContext,(HGLRC) );
+NV_GL_FUN_REN( HGLRC, wglGetCurrentContext,     dynwglGetCurrentContext, (VOID) );
+NV_GL_FUN_REN( HDC,   wglGetCurrentDC,          dynwglGetCurrentDC, (VOID) );
+NV_GL_FUN_REN( PROC,  wglGetProcAddress,        dynwglGetProcAddress, (LPCSTR) );
+NV_GL_FUN_REN( BOOL,  wglMakeCurrent,           dynwglMakeCurrent, (HDC, HGLRC) );
+NV_GL_FUN_REN( BOOL,  wglDescribeLayerPlane,    dynwglDescribeLayerPlane, (HDC, int, int, UINT, LPLAYERPLANEDESCRIPTOR) );
+NV_GL_FUN_REN( int,   wglSetLayerPaletteEntries,dynwglSetLayerPaletteEntries,(HDC, int, int, int, CONST COLORREF *) );
+NV_GL_FUN_REN( int,   wglGetLayerPaletteEntries,dynwglGetLayerPaletteEntries,(HDC, int, int, int, COLORREF *) );
+NV_GL_FUN_REN( BOOL,  wglRealizeLayerPalette,   dynwglRealizeLayerPalette,(HDC, int, BOOL) );
+NV_GL_FUN_REN( BOOL,  wglSwapLayerBuffers,      dynwglSwapLayerBuffers, (HDC, UINT) );
+NV_GL_FUN_REN( DWORD, wglSwapMultipleBuffers,   dynwglSwapMultipleBuffers, (UINT, CONST WGLSWAP *) );
+
+// Global
+NV_GL_FUN( int, wglChoosePixelFormat, ( HDC hdc, const PIXELFORMATDESCRIPTOR *ppfd ) );
+NV_GL_FUN( int, wglDescribePixelFormat, ( HDC hdc, int iPixelFormat, UINT nBytes, LPPIXELFORMATDESCRIPTOR ppfd ) );
+NV_GL_FUN( int, wglGetPixelFormat, ( HDC hdc ) );
+NV_GL_FUN( BOOL, wglSetPixelFormat, ( HDC hdc, int iPixelFormat, const PIXELFORMATDESCRIPTOR *ppfd ) );
+NV_GL_FUN( BOOL, wglSwapBuffers, ( HDC hdc ) );
+
+// WGL_ARB_buffer_region 
+
+NV_GL_FUN_EXT( HANDLE , wglCreateBufferRegionARB, ( HDC hDC, int iLayerPlane, UINT uType ) );
+NV_GL_FUN_EXT( VOID , wglDeleteBufferRegionARB, ( HANDLE hRegion ) );
+NV_GL_FUN_EXT( BOOL , wglRestoreBufferRegionARB, ( HANDLE hRegion, int x, int y, int width, int height, int xSrc, int ySrc ) );
+NV_GL_FUN_EXT( BOOL , wglSaveBufferRegionARB, ( HANDLE hRegion, int x, int y, int width, int height ) );
+
+// WGL_ARB_create_context 
+
+NV_GL_FUN_EXT( HGLRC , wglCreateContextAttribsARB, ( HDC hDC, HGLRC hShareContext, const int* attribList ) );
+
+// WGL_ARB_extensions_string 
+
+NV_GL_FUN_EXT( const char* , wglGetExtensionsStringARB, ( HDC hdc ) );
+
+// WGL_ARB_make_current_read 
+
+NV_GL_FUN_EXT( HDC , wglGetCurrentReadDCARB, ( VOID ) );
+NV_GL_FUN_EXT( BOOL , wglMakeContextCurrentARB, ( HDC hDrawDC, HDC hReadDC, HGLRC hglrc ) );
+
+// WGL_ARB_pixel_format 
+
+NV_GL_FUN_EXT( BOOL , wglChoosePixelFormatARB, ( HDC hdc, const int* piAttribIList, const FLOAT *pfAttribFList, UINT nMaxFormats, int *piFormats, UINT *nNumFormats ) );
+NV_GL_FUN_EXT( BOOL , wglGetPixelFormatAttribfvARB, ( HDC hdc, int iPixelFormat, int iLayerPlane, UINT nAttributes, const int* piAttributes, FLOAT *pfValues ) );
+NV_GL_FUN_EXT( BOOL , wglGetPixelFormatAttribivARB, ( HDC hdc, int iPixelFormat, int iLayerPlane, UINT nAttributes, const int* piAttributes, int *piValues ) );
+
+// WGL_EXT_display_color_table 
+
+NV_GL_FUN_EXT( GLboolean , wglBindDisplayColorTableEXT, ( GLushort id ) );
+NV_GL_FUN_EXT( GLboolean , wglCreateDisplayColorTableEXT, ( GLushort id ) );
+NV_GL_FUN_EXT( void , wglDestroyDisplayColorTableEXT, ( GLushort id ) );
+NV_GL_FUN_EXT( GLboolean , wglLoadDisplayColorTableEXT, ( GLushort* table, GLuint length ) );
+
+// WGL_EXT_extensions_string 
+
+NV_GL_FUN_EXT( const char* , wglGetExtensionsStringEXT, ( void ) );
+
+// WGL_EXT_make_current_read 
+
+NV_GL_FUN_EXT( HDC , wglGetCurrentReadDCEXT, ( VOID ) );
+NV_GL_FUN_EXT( BOOL , wglMakeContextCurrentEXT, ( HDC hDrawDC, HDC hReadDC, HGLRC hglrc ) );
+
+// WGL_EXT_pixel_format 
+
+NV_GL_FUN_EXT( BOOL , wglChoosePixelFormatEXT, ( HDC hdc, const int* piAttribIList, const FLOAT *pfAttribFList, UINT nMaxFormats, int *piFormats, UINT *nNumFormats ) );
+NV_GL_FUN_EXT( BOOL , wglGetPixelFormatAttribfvEXT, ( HDC hdc, int iPixelFormat, int iLayerPlane, UINT nAttributes, int* piAttributes, FLOAT *pfValues ) );
+NV_GL_FUN_EXT( BOOL , wglGetPixelFormatAttribivEXT, ( HDC hdc, int iPixelFormat, int iLayerPlane, UINT nAttributes, int* piAttributes, int *piValues ) );
+
+// WGL_EXT_swap_control 
+
+NV_GL_FUN_EXT( int , wglGetSwapIntervalEXT, ( void ) );
+NV_GL_FUN_EXT( BOOL , wglSwapIntervalEXT, ( int interval ) );
Index: trunk/nv/lib/detail/wgl_types.inc
===================================================================
--- trunk/nv/lib/detail/wgl_types.inc	(revision 245)
+++ trunk/nv/lib/detail/wgl_types.inc	(revision 245)
@@ -0,0 +1,174 @@
+// WGL_ARB_buffer_region 
+
+#define WGL_FRONT_COLOR_BUFFER_BIT_ARB 0x00000001
+#define WGL_BACK_COLOR_BUFFER_BIT_ARB 0x00000002
+#define WGL_DEPTH_BUFFER_BIT_ARB 0x00000004
+#define WGL_STENCIL_BUFFER_BIT_ARB 0x00000008
+
+// WGL_ARB_create_context 
+
+#define WGL_CONTEXT_DEBUG_BIT_ARB 0x0001
+#define WGL_CONTEXT_FORWARD_COMPATIBLE_BIT_ARB 0x0002
+#define WGL_CONTEXT_MAJOR_VERSION_ARB 0x2091
+#define WGL_CONTEXT_MINOR_VERSION_ARB 0x2092
+#define WGL_CONTEXT_LAYER_PLANE_ARB 0x2093
+#define WGL_CONTEXT_FLAGS_ARB 0x2094
+#define ERROR_INVALID_VERSION_ARB 0x2095
+#define ERROR_INVALID_PROFILE_ARB 0x2096
+
+// WGL_ARB_create_context_profile
+
+#define WGL_CONTEXT_CORE_PROFILE_BIT_ARB 0x00000001
+#define WGL_CONTEXT_COMPATIBILITY_PROFILE_BIT_ARB 0x00000002
+#define WGL_CONTEXT_PROFILE_MASK_ARB 0x9126
+
+// WGL_ARB_create_context_robustness 
+
+#define WGL_CONTEXT_ROBUST_ACCESS_BIT_ARB 0x00000004
+#define WGL_LOSE_CONTEXT_ON_RESET_ARB 0x8252
+#define WGL_CONTEXT_RESET_NOTIFICATION_STRATEGY_ARB 0x8256
+#define WGL_NO_RESET_NOTIFICATION_ARB 0x8261
+
+// WGL_ARB_framebuffer_sRGB 
+
+#define WGL_FRAMEBUFFER_SRGB_CAPABLE_ARB 0x20A9
+
+// WGL_ARB_make_current_read 
+
+#define ERROR_INVALID_PIXEL_TYPE_ARB 0x2043
+#define ERROR_INCOMPATIBLE_DEVICE_CONTEXTS_ARB 0x2054
+
+// WGL_ARB_multisample 
+
+#define WGL_SAMPLE_BUFFERS_ARB 0x2041
+#define WGL_SAMPLES_ARB 0x2042
+
+// WGL_ARB_pixel_format
+
+#define WGL_NUMBER_PIXEL_FORMATS_ARB 0x2000
+#define WGL_DRAW_TO_WINDOW_ARB 0x2001
+#define WGL_DRAW_TO_BITMAP_ARB 0x2002
+#define WGL_ACCELERATION_ARB 0x2003
+#define WGL_NEED_PALETTE_ARB 0x2004
+#define WGL_NEED_SYSTEM_PALETTE_ARB 0x2005
+#define WGL_SWAP_LAYER_BUFFERS_ARB 0x2006
+#define WGL_SWAP_METHOD_ARB 0x2007
+#define WGL_NUMBER_OVERLAYS_ARB 0x2008
+#define WGL_NUMBER_UNDERLAYS_ARB 0x2009
+#define WGL_TRANSPARENT_ARB 0x200A
+#define WGL_SHARE_DEPTH_ARB 0x200C
+#define WGL_SHARE_STENCIL_ARB 0x200D
+#define WGL_SHARE_ACCUM_ARB 0x200E
+#define WGL_SUPPORT_GDI_ARB 0x200F
+#define WGL_SUPPORT_OPENGL_ARB 0x2010
+#define WGL_DOUBLE_BUFFER_ARB 0x2011
+#define WGL_STEREO_ARB 0x2012
+#define WGL_PIXEL_TYPE_ARB 0x2013
+#define WGL_COLOR_BITS_ARB 0x2014
+#define WGL_RED_BITS_ARB 0x2015
+#define WGL_RED_SHIFT_ARB 0x2016
+#define WGL_GREEN_BITS_ARB 0x2017
+#define WGL_GREEN_SHIFT_ARB 0x2018
+#define WGL_BLUE_BITS_ARB 0x2019
+#define WGL_BLUE_SHIFT_ARB 0x201A
+#define WGL_ALPHA_BITS_ARB 0x201B
+#define WGL_ALPHA_SHIFT_ARB 0x201C
+#define WGL_ACCUM_BITS_ARB 0x201D
+#define WGL_ACCUM_RED_BITS_ARB 0x201E
+#define WGL_ACCUM_GREEN_BITS_ARB 0x201F
+#define WGL_ACCUM_BLUE_BITS_ARB 0x2020
+#define WGL_ACCUM_ALPHA_BITS_ARB 0x2021
+#define WGL_DEPTH_BITS_ARB 0x2022
+#define WGL_STENCIL_BITS_ARB 0x2023
+#define WGL_AUX_BUFFERS_ARB 0x2024
+#define WGL_NO_ACCELERATION_ARB 0x2025
+#define WGL_GENERIC_ACCELERATION_ARB 0x2026
+#define WGL_FULL_ACCELERATION_ARB 0x2027
+#define WGL_SWAP_EXCHANGE_ARB 0x2028
+#define WGL_SWAP_COPY_ARB 0x2029
+#define WGL_SWAP_UNDEFINED_ARB 0x202A
+#define WGL_TYPE_RGBA_ARB 0x202B
+#define WGL_TYPE_COLORINDEX_ARB 0x202C
+#define WGL_TRANSPARENT_RED_VALUE_ARB 0x2037
+#define WGL_TRANSPARENT_GREEN_VALUE_ARB 0x2038
+#define WGL_TRANSPARENT_BLUE_VALUE_ARB 0x2039
+#define WGL_TRANSPARENT_ALPHA_VALUE_ARB 0x203A
+#define WGL_TRANSPARENT_INDEX_VALUE_ARB 0x203B
+
+// WGL_ARB_pixel_format_float 
+
+#define WGL_TYPE_RGBA_FLOAT_ARB 0x21A0
+
+// WGL_EXT_create_context_es2_profile 
+
+#define WGL_CONTEXT_ES2_PROFILE_BIT_EXT 0x00000004
+
+// WGL_EXT_depth_float 
+
+#define WGL_DEPTH_FLOAT_EXT 0x2040
+
+// WGL_EXT_framebuffer_sRGB 
+
+#define WGL_FRAMEBUFFER_SRGB_CAPABLE_EXT 0x20A9
+
+// WGL_EXT_make_current_read 
+
+#define ERROR_INVALID_PIXEL_TYPE_EXT 0x2043
+
+// WGL_EXT_multisample 
+
+#define WGL_SAMPLE_BUFFERS_EXT 0x2041
+#define WGL_SAMPLES_EXT 0x2042
+
+// WGL_EXT_pixel_format 
+
+#define WGL_NUMBER_PIXEL_FORMATS_EXT 0x2000
+#define WGL_DRAW_TO_WINDOW_EXT 0x2001
+#define WGL_DRAW_TO_BITMAP_EXT 0x2002
+#define WGL_ACCELERATION_EXT 0x2003
+#define WGL_NEED_PALETTE_EXT 0x2004
+#define WGL_NEED_SYSTEM_PALETTE_EXT 0x2005
+#define WGL_SWAP_LAYER_BUFFERS_EXT 0x2006
+#define WGL_SWAP_METHOD_EXT 0x2007
+#define WGL_NUMBER_OVERLAYS_EXT 0x2008
+#define WGL_NUMBER_UNDERLAYS_EXT 0x2009
+#define WGL_TRANSPARENT_EXT 0x200A
+#define WGL_TRANSPARENT_VALUE_EXT 0x200B
+#define WGL_SHARE_DEPTH_EXT 0x200C
+#define WGL_SHARE_STENCIL_EXT 0x200D
+#define WGL_SHARE_ACCUM_EXT 0x200E
+#define WGL_SUPPORT_GDI_EXT 0x200F
+#define WGL_SUPPORT_OPENGL_EXT 0x2010
+#define WGL_DOUBLE_BUFFER_EXT 0x2011
+#define WGL_STEREO_EXT 0x2012
+#define WGL_PIXEL_TYPE_EXT 0x2013
+#define WGL_COLOR_BITS_EXT 0x2014
+#define WGL_RED_BITS_EXT 0x2015
+#define WGL_RED_SHIFT_EXT 0x2016
+#define WGL_GREEN_BITS_EXT 0x2017
+#define WGL_GREEN_SHIFT_EXT 0x2018
+#define WGL_BLUE_BITS_EXT 0x2019
+#define WGL_BLUE_SHIFT_EXT 0x201A
+#define WGL_ALPHA_BITS_EXT 0x201B
+#define WGL_ALPHA_SHIFT_EXT 0x201C
+#define WGL_ACCUM_BITS_EXT 0x201D
+#define WGL_ACCUM_RED_BITS_EXT 0x201E
+#define WGL_ACCUM_GREEN_BITS_EXT 0x201F
+#define WGL_ACCUM_BLUE_BITS_EXT 0x2020
+#define WGL_ACCUM_ALPHA_BITS_EXT 0x2021
+#define WGL_DEPTH_BITS_EXT 0x2022
+#define WGL_STENCIL_BITS_EXT 0x2023
+#define WGL_AUX_BUFFERS_EXT 0x2024
+#define WGL_NO_ACCELERATION_EXT 0x2025
+#define WGL_GENERIC_ACCELERATION_EXT 0x2026
+#define WGL_FULL_ACCELERATION_EXT 0x2027
+#define WGL_SWAP_EXCHANGE_EXT 0x2028
+#define WGL_SWAP_COPY_EXT 0x2029
+#define WGL_SWAP_UNDEFINED_EXT 0x202A
+#define WGL_TYPE_RGBA_EXT 0x202B
+#define WGL_TYPE_COLORINDEX_EXT 0x202C
+
+// WGL_EXT_pixel_format_packed_float 
+
+#define WGL_TYPE_RGBA_UNSIGNED_FLOAT_EXT 0x20A8
+
Index: trunk/nv/lib/gl.hh
===================================================================
--- trunk/nv/lib/gl.hh	(revision 244)
+++ trunk/nv/lib/gl.hh	(revision 245)
@@ -9,4 +9,15 @@
 
 #include <nv/common.hh>
+
+#if NV_PLATFORM == NV_WINDOWS
+#  ifndef WIN32_LEAN_AND_MEAN
+#    define WIN32_LEAN_AND_MEAN 1
+#  endif
+#include <windows.h>
+#  undef WIN32_LEAN_AND_MEAN
+#  undef near
+#  undef far
+#endif
+
 #include <stddef.h>
 
@@ -40,6 +51,10 @@
 
 #include <nv/lib/detail/gl_types.inc>
+#if NV_PLATFORM == NV_WINDOWS
+#include <nv/lib/detail/wgl_types.inc>
+#endif
 
 #if defined(NV_GL_DYNAMIC)
+#	define NV_GL_FUN_REN( rtype, fname, rname, fparams ) NV_GL_API rtype ( NV_GL_APIENTRY *rname) fparams
 #	define NV_GL_FUN( rtype, fname, fparams ) NV_GL_API rtype ( NV_GL_APIENTRY *fname) fparams
 #else
@@ -49,5 +64,9 @@
 
 #include <nv/lib/detail/gl_functions.inc>
+#if NV_PLATFORM == NV_WINDOWS
+#include <nv/lib/detail/wgl_functions.inc>
+#endif
 
+#undef NV_GL_FUN_REN
 #undef NV_GL_FUN_EXT
 #undef NV_GL_FUN
@@ -57,8 +76,11 @@
 namespace nv {
 /* Dynamic load support */
+	bool load_gl_no_context( const char* path = NV_GL_PATH );
 #	if defined( NV_GL_DYNAMIC )
 		bool load_gl_library( const char* path = NV_GL_PATH );
+		bool load_wgl_library( const char* path = NV_GL_PATH );
 #	else
 		inline bool load_gl_library( const char* path = "" ) { return true; }
+		inline bool load_wgl_library( const char* path = "" ) { return true; }
 #	endif
 }
Index: trunk/nv/lib/sdl.hh
===================================================================
--- trunk/nv/lib/sdl.hh	(revision 244)
+++ trunk/nv/lib/sdl.hh	(revision 245)
@@ -18,5 +18,5 @@
 
 #if !defined(NV_SDL_VERSION)
-#	define NV_SDL_VERSION     NV_SDL_12
+#	define NV_SDL_VERSION     NV_SDL_20
 #endif
 
Index: trunk/src/gl/gl_context.cc
===================================================================
--- trunk/src/gl/gl_context.cc	(revision 244)
+++ 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 244)
+++ 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 244)
+++ 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
+}
Index: trunk/src/lib/gl.cc
===================================================================
--- trunk/src/lib/gl.cc	(revision 244)
+++ trunk/src/lib/gl.cc	(revision 245)
@@ -16,19 +16,37 @@
 #endif
 
-#define NV_GL_FUN( rtype, fname, fparams ) rtype (NV_GL_APIENTRY *fname) fparams = nullptr;
+// for wgl support
+#if NV_PLATFORM == NV_WINDOWS
+#    ifndef WIN32_LEAN_AND_MEAN
+#      define WIN32_LEAN_AND_MEAN 1
+#    endif
+#include <windows.h>
+#    undef WIN32_LEAN_AND_MEAN
+#endif
+
+// extern added for wgl needs only!
+#define NV_GL_FUN( rtype, fname, fparams ) extern "C" rtype (NV_GL_APIENTRY *fname) fparams = nullptr;
+#define NV_GL_FUN_REN( rtype, fname, rname, fparams ) extern "C" rtype (NV_GL_APIENTRY *rname) fparams = nullptr;
 #define NV_GL_FUN_EXT NV_GL_FUN
 #include <nv/lib/detail/gl_functions.inc>
+#if NV_PLATFORM == NV_WINDOWS
+#include <nv/lib/detail/wgl_functions.inc>
+#endif
+#undef NV_GL_FUN_REN
 #undef NV_GL_FUN_EXT
 #undef NV_GL_FUN
 
+static nv::library gl_library;
+static bool gl_library_loaded = false;
+static bool wgl_library_loaded = false;
+
 bool nv::load_gl_library( const char* path )
 {
+	if ( gl_library_loaded ) return true;
 #if defined( NV_SDL_GL )
 #		define NV_GL_LOAD( symbol ) *(void **) (&symbol) = SDL_GL_GetProcAddress(#symbol);
 #		define NV_GL_LOAD_EXT( symbol ) *(void **) (&symbol) = SDL_GL_GetProcAddress(#symbol);
 #else
-	static nv::library gl_library;
-	if ( gl_library.is_open() ) return true;
-	gl_library.open( path );
+	if ( !gl_library.is_open() ) gl_library.open( path );
 
 	void * (NV_GL_APIENTRY *ext_loader) (const char* proc) = nullptr;
@@ -55,6 +73,115 @@
 #	undef NV_GL_LOAD
 #	undef NV_GL_LOAD_EXT
+	gl_library_loaded = true;
 	return true;
 }
 
+bool nv::load_wgl_library( const char* path /*= NV_GL_PATH */ )
+{
+	if ( wgl_library_loaded ) return true;
+#if NV_PLATFORM == NV_WINDOWS 
+#if defined( NV_SDL_GL )
+#		define NV_GL_LOAD( symbol ) *(void **) (&symbol) = SDL_GL_GetProcAddress(#symbol);
+#		define NV_GL_LOAD_EXT( symbol ) *(void **) (&symbol) = SDL_GL_GetProcAddress(#symbol);
+#	    define NV_GL_LOAD_REN( fname, rname )  *(void **) (&rname) = SDL_GL_GetProcAddress(#fname);
+#else // 
+	if ( !gl_library.is_open() ) gl_library.open( path );
+
+	void * (NV_GL_APIENTRY *ext_loader) (const char* proc) = nullptr;
+	*(void **) (&ext_loader) = gl_library.get("wglGetProcAddress");
+#define NV_GL_LOAD( symbol ) *(void **) (&symbol) = gl_library.get(#symbol);
+#define NV_GL_LOAD_EXT( symbol ) *(void **) (&symbol) = ext_loader(#symbol);
+#define NV_GL_LOAD_REN( fname, rname ) *(void **) (&rname) = gl_library.get(#fname);
+#endif 
+#	define NV_GL_FUN( rtype, fname, fparams ) NV_GL_LOAD( fname )
+#	define NV_GL_FUN_EXT( rtype, fname, fparams ) NV_GL_LOAD_EXT( fname )
+#	define NV_GL_FUN_REN( rtype, fname, rname, fparams ) NV_GL_LOAD_REN( fname, rname )
+#	include <nv/lib/detail/wgl_functions.inc>
+#	undef NV_GL_FUN_REN
+#	undef NV_GL_FUN_EXT
+#	undef NV_GL_FUN
+
+#	undef NV_GL_LOAD
+#	undef NV_GL_LOAD_EXT
+#	undef NV_GL_LOAD_REN
+	wgl_library_loaded = true;
+	return true;
+#else
+	return false;
 #endif
+}
+
+#endif // NV_DYNAMIC
+
+bool nv::load_gl_no_context( const char* path /*= NV_GL_PATH */ )
+{
+#if NV_PLATFORM == NV_WINDOWS 
+	if ( !gl_library.is_open() ) gl_library.open( path );
+	if ( wgl_library_loaded ) return true;
+
+	HGLRC (NV_GL_APIENTRY *wgl_createcontext) (HDC)        = nullptr;
+	BOOL  (NV_GL_APIENTRY *wgl_makecurrent)   (HDC, HGLRC) = nullptr;
+	BOOL  (NV_GL_APIENTRY *wgl_deletecontext) (HGLRC)      = nullptr;
+
+	*(void **) &wgl_createcontext = gl_library.get("wglCreateContext");
+	*(void **) &wgl_makecurrent   = gl_library.get("wglMakeCurrent");
+	*(void **) &wgl_deletecontext = gl_library.get("wglDeleteContext");
+
+	WNDCLASS wndClass;
+	HINSTANCE hInstance = 0;
+
+	ZeroMemory(&wndClass, sizeof(WNDCLASS));
+
+	wndClass.cbClsExtra = 0;
+	wndClass.cbWndExtra = 0;			
+	wndClass.hCursor = LoadCursor(NULL, IDC_ARROW);
+	wndClass.hIcon = LoadIcon(NULL, IDI_APPLICATION);
+	wndClass.hInstance = hInstance;
+	wndClass.lpfnWndProc = (WNDPROC) DefWindowProc;
+	wndClass.lpszClassName = TEXT("Dummy67789");
+	wndClass.lpszMenuName = 0;
+	wndClass.style = CS_HREDRAW | CS_VREDRAW | CS_OWNDC;
+
+	DWORD err = GetLastError();
+	RegisterClass(&wndClass);
+	err = GetLastError();
+
+
+	HWND hWndFake = CreateWindow(TEXT("Dummy67789"), "FAKE", WS_OVERLAPPEDWINDOW | WS_MAXIMIZE | WS_CLIPCHILDREN, 
+		0, 0, CW_USEDEFAULT, CW_USEDEFAULT, NULL, 
+		NULL, GetModuleHandle(nullptr), NULL); 
+
+	HDC hDC = GetDC(hWndFake); 
+
+	PIXELFORMATDESCRIPTOR pfd; 
+	memset(&pfd, 0, sizeof(PIXELFORMATDESCRIPTOR)); 
+	pfd.nSize= sizeof(PIXELFORMATDESCRIPTOR); 
+	pfd.nVersion   = 1; 
+	pfd.dwFlags    = PFD_DOUBLEBUFFER | PFD_SUPPORT_OPENGL | PFD_DRAW_TO_WINDOW; 
+	pfd.iPixelType = PFD_TYPE_RGBA; 
+	pfd.cColorBits = 32; 
+	pfd.cDepthBits = 24; 
+	pfd.iLayerType = PFD_MAIN_PLANE; 
+
+	int iPixelFormat = ChoosePixelFormat(hDC, &pfd); 
+	if (iPixelFormat == 0)return false; 
+
+	if(!SetPixelFormat(hDC, iPixelFormat, &pfd))return false; 
+
+	HGLRC hRCFake = wgl_createcontext(hDC); 
+	wgl_makecurrent(hDC, hRCFake); 
+
+	LoadLibrary( "gdi32.dll" );
+	bool gl_loaded = nv::load_gl_library( path );
+	bool wgl_loaded = nv::load_wgl_library( path );
+	bool result = gl_loaded && wgl_loaded;
+
+	wgl_makecurrent(NULL, NULL); 
+	wgl_deletecontext(hRCFake); 
+	DestroyWindow(hWndFake); 
+	return result;
+#else
+	return false;
+#endif
+}
+
