Index: trunk/nv/formats/md2_loader.hh
===================================================================
--- trunk/nv/formats/md2_loader.hh	(revision 227)
+++ trunk/nv/formats/md2_loader.hh	(revision 228)
@@ -14,7 +14,7 @@
 #define NV_MD2_LOADER_HH
 
+#include <nv/common.hh>
 #include <unordered_map>
 #include <vector>
-#include <nv/common.hh>
 #include <nv/interface/mesh_loader.hh>
 
Index: trunk/nv/formats/md3_loader.hh
===================================================================
--- trunk/nv/formats/md3_loader.hh	(revision 227)
+++ trunk/nv/formats/md3_loader.hh	(revision 228)
@@ -14,7 +14,7 @@
 #define NV_MD3_LOADER_HH
 
+#include <nv/common.hh>
 #include <unordered_map>
 #include <vector>
-#include <nv/common.hh>
 #include <nv/gfx/mesh_data.hh>
 #include <nv/interface/mesh_loader.hh>
Index: trunk/nv/formats/md5_loader.hh
===================================================================
--- trunk/nv/formats/md5_loader.hh	(revision 227)
+++ trunk/nv/formats/md5_loader.hh	(revision 228)
@@ -14,7 +14,7 @@
 #define NV_MD5_LOADER_HH
 
+#include <nv/common.hh>
 #include <unordered_map>
 #include <vector>
-#include <nv/common.hh>
 #include <nv/interface/mesh_loader.hh>
 
Index: trunk/nv/gfx/image.hh
===================================================================
--- trunk/nv/gfx/image.hh	(revision 227)
+++ trunk/nv/gfx/image.hh	(revision 228)
@@ -69,4 +69,11 @@
 		void fill( uint8 value );
 		/**
+		 * Fills the region with a given value.
+		 *
+		 * @arg[in] r : Region to be filled.
+		 * @arg[in] value : Value to fill.
+		 */
+		void fill( region r, uint8 value, int stride = 0 );
+		/**
 		 * Just like fill, but a region can be specified.
 		 *
@@ -76,4 +83,14 @@
 		 */
 		void set_region( region r, const uint8 * data, int stride = 0 );
+
+		/**
+		 * Just like fill, but a region can be specified. Checks for data depth,
+		 * and converts if needed.
+		 *
+		 * @arg[in] r : Region to be filled.
+		 * @arg[in] data : Data to fill the region
+		 */
+		void set_region( region r, const image_data* idata );
+
 		/**
 		 * Default destructor. Deallocates data.
Index: trunk/nv/gl/gl_device.hh
===================================================================
--- trunk/nv/gl/gl_device.hh	(revision 227)
+++ trunk/nv/gl/gl_device.hh	(revision 228)
@@ -21,5 +21,5 @@
 	public:
 		gl_device();
-		virtual window* create_window( uint16 width, uint16 height );
+		virtual window* create_window( uint16 width, uint16 height, bool fullscreen );
 		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 227)
+++ trunk/nv/gl/gl_window.hh	(revision 228)
@@ -22,5 +22,5 @@
 	{
 	public:
-		gl_window( device* dev, uint16 width, uint16 height );
+		gl_window( device* dev, uint16 width, uint16 height, bool fullscreen = false );
 		uint16 get_width() const;
 		uint16 get_height() const;
Index: trunk/nv/interface/device.hh
===================================================================
--- trunk/nv/interface/device.hh	(revision 227)
+++ trunk/nv/interface/device.hh	(revision 228)
@@ -28,5 +28,5 @@
 	{
 	public:
-		virtual window* create_window( uint16 width, uint16 height ) = 0;
+		virtual window* create_window( uint16 width, uint16 height, bool fullscreen ) = 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/lua/lua_state.hh
===================================================================
--- trunk/nv/lua/lua_state.hh	(revision 227)
+++ trunk/nv/lua/lua_state.hh	(revision 228)
@@ -12,7 +12,7 @@
 #define NV_LUA_HH
 
+#include <nv/common.hh>
 #include <istream>
 #include <map>
-#include <nv/common.hh>
 #include <nv/flags.hh>
 #include <nv/types.hh>
@@ -141,4 +141,11 @@
 				register_native_function( detail::function_wrapper< F, f >, name );
 			}
+
+			template < typename C, typename F, F* f > 
+			void register_function( const char* name )
+			{
+				register_native_function( detail::object_method_wrapper< C, F, f >, name );
+			}
+
 		protected:
 			bool is_defined( const path& p, bool global );
Index: trunk/nv/lua/lua_values.hh
===================================================================
--- trunk/nv/lua/lua_values.hh	(revision 227)
+++ trunk/nv/lua/lua_values.hh	(revision 228)
@@ -221,5 +221,5 @@
 			{
 				typedef typename type_degrade<T>::type degraded;
-				p = pass_traits<degraded>::to( L, -1 );
+				p = (T)pass_traits<degraded>::to( L, -1 );
 				detail::pop_and_discard(L, 1);
 			}
@@ -229,5 +229,5 @@
 				typedef typename type_degrade<T>::type degraded;
 				T ret;
-				ret = pass_traits<degraded>::to( L, -1 );
+				ret = (T)pass_traits<degraded>::to( L, -1 );
 				detail::pop_and_discard(L, 1);
 				return ret;
Index: trunk/nv/random.hh
===================================================================
--- trunk/nv/random.hh	(revision 227)
+++ trunk/nv/random.hh	(revision 228)
@@ -8,6 +8,6 @@
 #define NV_RANDOM_HH
 
+#include <nv/common.hh>
 #include <random>
-#include <nv/common.hh>
 #include <nv/math.hh>
 
Index: trunk/src/gfx/image.cc
===================================================================
--- trunk/src/gfx/image.cc	(revision 227)
+++ trunk/src/gfx/image.cc	(revision 228)
@@ -48,4 +48,19 @@
 }
 
+void image::fill( region r, uint8 value, int stride )
+{
+	if ( stride == 0 ) stride = r.size.x * static_cast<sint32>( m_depth );
+
+	sint32 bpos  = (r.pos.y*m_size.x + r.pos.x ) * static_cast<sint32>( m_depth );
+	sint32 bline = m_size.x*static_cast<sint32>( m_depth );
+
+	for( int i = 0; i < r.size.y; ++i )
+	{
+		// TODO: test 
+		std::fill( m_data + bpos + bline * i, m_data + bpos + bline * i + stride, value );
+	}
+}
+
+
 void image::set_region( region r, const uint8 * data, int stride )
 {
@@ -64,4 +79,36 @@
 }
 
+void image::set_region( region r, const image_data* idata )
+{
+	if ( idata->get_depth() == m_depth )
+	{
+		set_region( r, idata->get_data() );
+		return;
+	}
+
+	fill( r, 255 );
+
+	sint32 bpos       = (r.pos.y*m_size.x + r.pos.x ) * static_cast<sint32>( m_depth );
+	sint32 bline      = m_size.x*static_cast<sint32>( m_depth );
+
+	const uint8* data = idata->get_data();
+	sint32 depth      = idata->get_depth();
+	sint32 dstride    = r.size.x * static_cast<sint32>( depth );
+
+	for( int y = 0; y < r.size.y; ++y )
+	{
+		sint32 pos = bpos + bline * y;
+		for( int x = 0; x < r.size.x; ++x )
+		{
+			sint32 xy = pos + x * m_depth;
+			for( int e = 0; e < depth; ++e )
+			{
+				m_data[ xy + e ] = data[ y*dstride + x * depth + e ];
+			}
+		}
+	}
+}
+
+
 image::~image()
 {
Index: trunk/src/gl/gl_device.cc
===================================================================
--- trunk/src/gl/gl_device.cc	(revision 227)
+++ trunk/src/gl/gl_device.cc	(revision 228)
@@ -15,7 +15,7 @@
 using namespace nv;
 
-window* gl_device::create_window( uint16 width, uint16 height )
+window* gl_device::create_window( uint16 width, uint16 height, bool fullscreen )
 {
-	return new gl_window( this, width, height );
+	return new gl_window( this, width, height, fullscreen );
 }
 
Index: trunk/src/gl/gl_window.cc
===================================================================
--- trunk/src/gl/gl_window.cc	(revision 227)
+++ trunk/src/gl/gl_window.cc	(revision 228)
@@ -203,12 +203,14 @@
 
 
-gl_window::gl_window( device* dev, uint16 width, uint16 height )
+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 )
 {
 #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_FULLSCREEN;
 	m_handle = SDL_CreateWindow("Nova Engine", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED,
 		width, height, flags );
Index: trunk/src/lua/lua_map_tile.cc
===================================================================
--- trunk/src/lua/lua_map_tile.cc	(revision 227)
+++ trunk/src/lua/lua_map_tile.cc	(revision 228)
@@ -130,5 +130,5 @@
 		{
 			nv::uint8 c = tile->data[ y * tile->size_x + x ];
-			if ( c != 0 ) area->set_cell( coord + nv::ivec2( x, y ), tile->data[ y * tile->size_x + x ] );
+			if ( c != 0 ) area->set_cell( coord + nv::ivec2( x, y ), c );
 		}
 
Index: trunk/src/lua/lua_state.cc
===================================================================
--- trunk/src/lua/lua_state.cc	(revision 227)
+++ trunk/src/lua/lua_state.cc	(revision 228)
@@ -234,5 +234,7 @@
 		for(; lib->func != NULL; lib++)
 		{
-			lib->func( m_state );
+			lua_pushcfunction( m_state, lib->func );
+			lua_call(m_state, 0, 1);
+			lua_setglobal( m_state, lib->name );
 		}
 		register_nova( this );
