Index: /trunk/nv/interface/animated_mesh.hh
===================================================================
--- /trunk/nv/interface/animated_mesh.hh	(revision 230)
+++ /trunk/nv/interface/animated_mesh.hh	(revision 231)
@@ -35,19 +35,10 @@
 	};
 
-	class animated_mesh
+	class animated_mesh : public mesh_interface
 	{
 	public:
-		animated_mesh( context* a_context ) : m_context( a_context ), m_va( nullptr ) {}
+		animated_mesh() {}
 		virtual void run_animation( animation_entry* ) {}
-		virtual void update( uint32 ) {}
-		virtual void update( program* ) {}
 		virtual transform get_tag( const std::string& ) const { return transform(); }
-		virtual nv::vertex_array* get_vertex_array() const { return m_va; }
-		virtual size_t get_index_count() const { return 0; }
-		virtual nv::primitive get_primitive_type() { return nv::TRIANGLES; }
-		virtual ~animated_mesh() {}
-	protected:
-		context*      m_context;
-		vertex_array* m_va;
 	};
 
Index: /trunk/nv/interface/context.hh
===================================================================
--- /trunk/nv/interface/context.hh	(revision 230)
+++ /trunk/nv/interface/context.hh	(revision 231)
@@ -32,4 +32,19 @@
 	};
 
+	class mesh_interface
+	{
+	public:
+		mesh_interface() : m_va( nullptr ) {}
+		explicit mesh_interface( vertex_array* array ) : m_va( array ) {}
+		virtual void update( uint32 ) {}
+		virtual void update( program* ) {}
+		virtual nv::vertex_array* get_vertex_array() const { return m_va; }
+		virtual size_t get_index_count() const { return 0; }
+		virtual nv::primitive get_primitive_type() { return nv::TRIANGLES; }
+		virtual ~mesh_interface() {}
+	protected:
+		vertex_array* m_va;
+	};
+
 	class device;
 	class context
@@ -40,4 +55,9 @@
 		// temporary
 		virtual void draw( primitive prim, const render_state& rs, program* p, vertex_array* va, size_t count ) = 0;
+		virtual void draw( const render_state& rs, program* p, mesh_interface* mesh )
+		{
+			draw( mesh->get_primitive_type(), rs, p, mesh->get_vertex_array(), mesh->get_index_count() );
+		}
+
 		virtual void apply_render_state( const render_state& state ) = 0;
 		virtual const ivec4& get_viewport() = 0;
Index: /trunk/src/gfx/keyframed_mesh.cc
===================================================================
--- /trunk/src/gfx/keyframed_mesh.cc	(revision 230)
+++ /trunk/src/gfx/keyframed_mesh.cc	(revision 231)
@@ -16,5 +16,5 @@
 
 keyframed_mesh::keyframed_mesh( context* a_context, mesh_data* a_data )
-	: animated_mesh( a_context )
+	: animated_mesh()
 	, m_data( a_data )
 	, m_start_frame( false )
@@ -28,5 +28,5 @@
 	, m_active( false )
 {
-	m_va = m_context->get_device()->create_vertex_array();
+	m_va = a_context->get_device()->create_vertex_array();
 }
 
@@ -126,15 +126,15 @@
 	m_loc_next_normal   = a_program->get_attribute( "nv_next_normal" )->get_location();
 
-	vb = m_context->get_device()->create_vertex_buffer( nv::STATIC_DRAW, m_data->get_vertex_count() * sizeof( nv::vec3 ) * m_data->get_frame_count(), (void*)m_data->get_positions().data() );
+	vb = a_context->get_device()->create_vertex_buffer( nv::STATIC_DRAW, m_data->get_vertex_count() * sizeof( nv::vec3 ) * m_data->get_frame_count(), (void*)m_data->get_positions().data() );
 	m_va->add_vertex_buffer( m_loc_next_position, vb, nv::FLOAT, 3, 0, 0, false );
 	m_va->add_vertex_buffer( nv::POSITION, vb, nv::FLOAT, 3 );
 
-	vb = m_context->get_device()->create_vertex_buffer( nv::STATIC_DRAW, m_data->get_vertex_count() * sizeof( nv::vec3 ) * m_data->get_frame_count(), (void*)m_data->get_normals().data() );
+	vb = a_context->get_device()->create_vertex_buffer( nv::STATIC_DRAW, m_data->get_vertex_count() * sizeof( nv::vec3 ) * m_data->get_frame_count(), (void*)m_data->get_normals().data() );
 	m_va->add_vertex_buffer( m_loc_next_normal, vb, nv::FLOAT, 3, 0, 0, false );
 	m_va->add_vertex_buffer( nv::NORMAL, vb, nv::FLOAT, 3 );
 
-	vb = m_context->get_device()->create_vertex_buffer( nv::STATIC_DRAW, m_data->get_vertex_count() * sizeof( nv::vec2 ), (void*)m_data->get_texcoords().data() );
+	vb = a_context->get_device()->create_vertex_buffer( nv::STATIC_DRAW, m_data->get_vertex_count() * sizeof( nv::vec2 ), (void*)m_data->get_texcoords().data() );
 	m_va->add_vertex_buffer( nv::slot::TEXCOORD, vb, nv::FLOAT, 2 );
-	nv::index_buffer* ib = m_context->get_device()->create_index_buffer( nv::STATIC_DRAW, m_data->get_index_count() * sizeof( nv::uint32 ), (void*)m_data->get_indices().data() );
+	nv::index_buffer* ib = a_context->get_device()->create_index_buffer( nv::STATIC_DRAW, m_data->get_index_count() * sizeof( nv::uint32 ), (void*)m_data->get_indices().data() );
 	m_va->set_index_buffer( ib, nv::UINT, true );
 }
@@ -163,15 +163,15 @@
 	: keyframed_mesh( a_context, a_data )
 {
-	m_vb_position = m_context->get_device()->create_vertex_buffer( nv::STATIC_DRAW, m_data->get_vertex_count() * sizeof( nv::vec3 ), (void*)m_data->get_position_frame(0) );
+	m_vb_position = a_context->get_device()->create_vertex_buffer( nv::STATIC_DRAW, m_data->get_vertex_count() * sizeof( nv::vec3 ), (void*)m_data->get_position_frame(0) );
 	m_va->add_vertex_buffer( nv::slot::POSITION, m_vb_position, nv::FLOAT, 3 );
 
-	m_vb_normal   = m_context->get_device()->create_vertex_buffer( nv::STATIC_DRAW, m_data->get_vertex_count() * sizeof( nv::vec3 ), (void*)m_data->get_normal_frame(0) );
+	m_vb_normal   = a_context->get_device()->create_vertex_buffer( nv::STATIC_DRAW, m_data->get_vertex_count() * sizeof( nv::vec3 ), (void*)m_data->get_normal_frame(0) );
 	m_va->add_vertex_buffer( nv::slot::NORMAL, m_vb_normal, nv::FLOAT, 3 );
 
 	nv::vertex_buffer* vb;
-	vb = m_context->get_device()->create_vertex_buffer( nv::STATIC_DRAW, m_data->get_vertex_count() * sizeof( nv::vec2 ), (void*)m_data->get_texcoords().data() );
+	vb = a_context->get_device()->create_vertex_buffer( nv::STATIC_DRAW, m_data->get_vertex_count() * sizeof( nv::vec2 ), (void*)m_data->get_texcoords().data() );
 	m_va->add_vertex_buffer( nv::slot::TEXCOORD, vb, nv::FLOAT, 2 );
 
-	nv::index_buffer* ib = m_context->get_device()->create_index_buffer( nv::STATIC_DRAW, m_data->get_index_count() * sizeof( nv::uint32 ), (void*)m_data->get_indices().data() );
+	nv::index_buffer* ib = a_context->get_device()->create_index_buffer( nv::STATIC_DRAW, m_data->get_index_count() * sizeof( nv::uint32 ), (void*)m_data->get_indices().data() );
 	m_va->set_index_buffer( ib, nv::UINT, true );
 
Index: /trunk/src/gfx/skeletal_mesh.cc
===================================================================
--- /trunk/src/gfx/skeletal_mesh.cc	(revision 230)
+++ /trunk/src/gfx/skeletal_mesh.cc	(revision 231)
@@ -12,5 +12,5 @@
 
 nv::skeletal_mesh::skeletal_mesh( context* a_context, md5_loader* a_loader )
-	: animated_mesh( a_context )
+	: animated_mesh()
 	, m_data( a_loader )
 	, m_animation( nullptr )
Index: /trunk/tests/md2_test/md2_test.cc
===================================================================
--- /trunk/tests/md2_test/md2_test.cc	(revision 230)
+++ /trunk/tests/md2_test/md2_test.cc	(revision 231)
@@ -58,17 +58,9 @@
 	}
 
+	nv::mesh_interface* get_mesh() { return m_mesh; }
+
 	size_t get_max_frames()
 	{
 		return m_mesh->get_max_frames();
-	}
-
-	void draw( nv::render_state& rstate, const glm::mat4& m, const glm::mat4& v, const glm::mat4& p )
-	{
-		NV_PROFILE( "mesh-draw" );
-		glm::mat4 mv = v * m;
-		m_mesh->get_program()->set_opt_uniform( "nv_m_modelview", mv );
-		m_mesh->get_program()->set_opt_uniform( "nv_m_normal", glm::transpose(glm::inverse(glm::mat3(mv))) );
-		m_mesh->get_program()->set_uniform( "matrix_mvp", p * mv );
-		m_mesh->draw( rstate );
 	}
 
@@ -80,6 +72,6 @@
 
 private:
-	nv::mesh_data*           m_mesh_data;
-	nv::keyframed_mesh_gpu*  m_mesh;
+	nv::mesh_data*       m_mesh_data;
+	nv::keyframed_mesh*  m_mesh;
 };
 
@@ -106,5 +98,5 @@
 	NV_PROFILE( "app_construct" );
 	m_device = new nv::gl_device();
-	m_window = m_device->create_window( 800, 600 );
+	m_window = m_device->create_window( 800, 600, false );
 
 	nv::sampler sampler( nv::sampler::LINEAR, nv::sampler::REPEAT );
@@ -178,5 +170,10 @@
 			NV_PROFILE( "draw" );
 			glm::mat4 model      = glm::mat4(1.0f);
-			m_mesh->draw( m_render_state, model, view, projection );
+			glm::mat4 mv = view * model;
+			m_program->set_opt_uniform( "nv_m_modelview", mv );
+			m_program->set_opt_uniform( "nv_m_normal", glm::transpose(glm::inverse(glm::mat3(mv))) );
+			m_program->set_uniform( "matrix_mvp", projection * mv );
+			m_mesh->get_mesh()->update( m_program );
+			m_window->get_context()->draw( m_render_state, m_program, m_mesh->get_mesh() );
 		}
 
Index: /trunk/tests/md3_test/md3_test.cc
===================================================================
--- /trunk/tests/md3_test/md3_test.cc	(revision 231)
+++ /trunk/tests/md3_test/md3_test.cc	(revision 231)
@@ -0,0 +1,306 @@
+#include <nv/common.hh>
+#include <iomanip>
+#include <nv/gfx/keyframed_mesh.hh>
+#include <nv/interface/vertex_buffer.hh>
+#include <nv/gl/gl_device.hh>
+#include <nv/gfx/image.hh>
+#include <nv/interface/context.hh>
+#include <nv/interface/window.hh>
+#include <nv/interface/program.hh>
+#include <nv/interface/texture2d.hh>
+#include <nv/interface/mesh_loader.hh>
+#include <nv/io/c_file_system.hh>
+#include <nv/formats/md3_loader.hh>
+#include <nv/profiler.hh>
+#include <nv/logging.hh>
+#include <nv/logger.hh>
+#include <nv/math.hh>
+#include <nv/time.hh>
+#include <nv/string.hh>
+#include <nv/interface/mesh.hh>
+#include <glm/gtx/rotate_vector.hpp>
+#include <glm/gtc/matrix_access.hpp>
+#include <glm/gtx/matrix_interpolation.hpp>
+
+bool GPU_ANIMATION = false;
+
+class mesh_part
+{
+public:
+	mesh_part( const std::string& path, nv::program* program, nv::window* window )
+	{
+		NV_PROFILE("mesh_construct");
+		nv::md3_loader* loader;
+		{
+			NV_PROFILE("loader->load");
+			nv::c_file_system fs;
+			nv::stream* mesh_file = fs.open( path.c_str() );
+			loader = new nv::md3_loader();
+			loader->load( *mesh_file );
+			delete mesh_file;
+		}
+
+		{
+			NV_PROFILE("create_mesh_data");
+			m_data      = loader->release_mesh_data();
+		}
+		delete loader;
+
+		{
+			NV_PROFILE("create_mesh");
+			if ( GPU_ANIMATION )
+				m_mesh      = new nv::keyframed_mesh_gpu( window->get_context(), m_data, program );
+			else
+				m_mesh      = new nv::keyframed_mesh_cpu( window->get_context(), m_data );
+		}
+
+	}
+
+	nv::mat4 get_transform( const std::string& tag )
+	{
+		return m_mesh->get_tag( tag ).extract();
+	}
+
+	void setup_animation( nv::uint32 start, nv::uint32 stop, nv::uint32 fps, bool loop )
+	{
+		m_mesh->setup_animation( start, stop, fps, loop );
+	}
+
+	void update( nv::uint32 ms )
+	{
+		m_mesh->update( ms );
+	}
+
+	nv::mesh_interface* get_mesh() const { return m_mesh; }
+
+	size_t get_max_frames()
+	{
+		return m_mesh->get_max_frames();
+	}
+
+	void draw( nv::context* c, nv::program* program, nv::render_state& rstate, const glm::mat4& m, const glm::mat4& v, const glm::mat4& p )
+	{
+		NV_PROFILE( "mesh-draw" );
+		glm::mat4 mv = v * m;
+		program->set_opt_uniform( "nv_m_modelview", mv );
+		program->set_opt_uniform( "nv_m_normal", glm::transpose(glm::inverse(glm::mat3(mv))) );
+		program->set_uniform( "matrix_mvp", p * mv );
+		
+		c->draw( rstate, program, m_mesh );
+	}
+
+	~mesh_part()
+	{
+		delete m_data;
+		delete m_mesh;
+	}
+
+private:
+	nv::mesh_data*           m_data;
+	nv::keyframed_mesh*      m_mesh;
+};
+
+class application
+{
+public:
+	application();
+	bool initialize();
+	bool run();
+	~application();
+protected:
+	nv::device*       m_device;
+	nv::window*       m_window;
+	nv::texture2d*    m_diffuse;
+	nv::texture2d*    m_diffuse_weapon;
+	nv::clear_state   m_clear_state;
+	nv::render_state  m_render_state;
+
+	mesh_part* m_torso;
+	mesh_part* m_legs;
+	mesh_part* m_head;
+	mesh_part* m_weapon;
+	nv::program*      m_program;
+};
+
+application::application()
+{
+	NV_PROFILE( "app_construct" );
+	m_device = new nv::gl_device();
+	m_window = m_device->create_window( 800, 600, false );
+
+	nv::sampler sampler( nv::sampler::LINEAR, nv::sampler::REPEAT );
+	nv::image_data* data = m_device->create_image_data( "data/doom.png" );
+	m_diffuse  = m_device->create_texture2d( data->get_size(), nv::RGBA, nv::UBYTE, sampler, (void*)data->get_data() );
+	delete data;
+	data = m_device->create_image_data( "data/rocketl.png" );
+	m_diffuse_weapon = m_device->create_texture2d( data->get_size(), nv::RGBA, nv::UBYTE, sampler, (void*)data->get_data() );
+	delete data;
+
+	m_clear_state.buffers = nv::clear_state::COLOR_AND_DEPTH_BUFFER;
+	m_render_state.depth_test.enabled = true;
+	m_render_state.culling.enabled    = true;
+	m_render_state.blending.enabled   = false;
+	m_render_state.blending.src_rgb_factor   = nv::blending::SRC_ALPHA;
+	m_render_state.blending.dst_rgb_factor   = nv::blending::ONE_MINUS_SRC_ALPHA;
+	m_render_state.blending.src_alpha_factor = nv::blending::SRC_ALPHA;
+	m_render_state.blending.dst_alpha_factor = nv::blending::ONE_MINUS_SRC_ALPHA;
+}
+
+bool application::initialize()
+{
+	NV_PROFILE( "app_initialize" );
+	m_program = m_device->create_program( 
+		nv::slurp( GPU_ANIMATION ? "obj_gpu.vert" : "obj_cpu.vert" ), 
+		nv::slurp( "obj.frag" ) 
+	);
+	m_torso   = new mesh_part( "data/upper.md3", m_program, m_window );
+	m_legs    = new mesh_part( "data/lower.md3", m_program, m_window );
+	m_head    = new mesh_part( "data/head.md3", m_program, m_window );
+	m_weapon  = new mesh_part( "data/rocketl.md3", m_program, m_window );
+	return true;
+}
+
+bool application::run()
+{
+	nv::profiler::pointer()->log_report(); 
+	NV_PROFILE( "app_run" );
+	int keypress = 0;
+
+	glm::vec3 move( 0, 0, 0 );
+
+	nv::uint32 ticks   = m_device->get_ticks();
+	nv::uint32 last_ticks;
+	nv::fps_counter_class< nv::system_us_timer > fps_counter;
+
+	m_legs->setup_animation( 0, m_legs->get_max_frames(), 20, true );
+	m_torso->setup_animation( 0, m_torso->get_max_frames(), 20, true );
+
+	bool common = true;
+	while(!keypress) 
+	{
+		last_ticks = ticks;
+		ticks      = m_device->get_ticks();
+		nv::uint32 elapsed = ticks - last_ticks;
+		m_torso->update( elapsed );
+		m_legs->update( elapsed );
+		{
+			NV_PROFILE( "clear" );
+			m_window->get_context()->clear( m_clear_state );
+		}
+
+		glm::mat4 view;
+		glm::mat4 projection;
+		{
+			NV_PROFILE( "update_sh" );
+
+			glm::vec3 source( 80.0f, 0.0f, 0.0f );
+			glm::vec3 eye = glm::rotate( source, (ticks / 20.f), glm::vec3( 0.0,1.0,0.0 ) );
+
+			view       = glm::lookAt(eye + move, glm::vec3(0.0f, 0.0f, 0.0f) + move, glm::vec3(0.0, 1.0, 0.0));
+			projection = glm::perspective(60.0f, 1.0f*800.0f/600.0f, 0.1f, 1000.0f);
+
+			m_diffuse->bind( 0 );
+			m_program->set_opt_uniform( "nv_m_projection", projection );
+			m_program->set_uniform( "light_position", glm::vec3(120.0, 120.0, 0) );
+			m_program->set_uniform( "light_diffuse",  glm::vec4(1.0,1.0,1.0,1.0) );
+			m_program->set_uniform( "light_specular", glm::vec4(1.0,1.0,1.0,1.0) );
+			m_program->set_uniform( "diffuse", 0 );
+		}
+
+		{
+			NV_PROFILE( "draw" );
+			glm::mat4 model      = glm::mat4(1.0f);
+			m_legs->draw( m_window->get_context(), m_program, m_render_state, model, view, projection );
+
+			//model = m_legs->get_transform( "tag_torso", last_legs_frame, legs_frame, legs_interpolate );
+			model = m_legs->get_transform( "tag_torso" );
+			m_torso->draw( m_window->get_context(), m_program, m_render_state, model, view, projection );
+
+			glm::mat4 head = model * m_torso->get_transform( "tag_head" ); //, last_torso_frame, torso_frame, torso_interpolate );
+			m_head->draw( m_window->get_context(), m_program, m_render_state, head, view, projection );
+
+			glm::mat4 weapon = model * m_torso->get_transform( "tag_weapon" ); //, last_torso_frame, torso_frame, torso_interpolate );
+			m_diffuse_weapon->bind( 0 );
+			m_weapon->draw( m_window->get_context(), m_program, m_render_state, weapon, view, projection );
+
+		}
+
+		{
+			NV_PROFILE( "swap" );
+			m_window->swap_buffers();
+		}
+
+		{
+			NV_PROFILE( "pollevent" );
+			nv::io_event event;
+			while(m_window->poll_event(event)) 
+			{      
+				switch (event.type) 
+				{
+				case nv::EV_QUIT:
+					keypress = 1;
+					break;
+				case nv::EV_KEY:
+					if (event.key.pressed)
+					{
+						switch (event.key.code) 
+						{
+						case nv::KEY_ESCAPE : keypress = 1; break;
+						case nv::KEY_1 : m_legs->setup_animation( 0, 89, 20, true ); m_torso->setup_animation( 0, 89, 20, true ); common = true; break;
+						case nv::KEY_2 : m_legs->setup_animation( 90, 8, 20, true ); if (common) m_torso->setup_animation( 151, 1, 20, true ); common = false; break;
+						case nv::KEY_3 : m_legs->setup_animation( 98, 12, 20, true ); if (common) m_torso->setup_animation( 151, 1, 20, true ); common = false; break;
+						case nv::KEY_4 : m_legs->setup_animation( 110, 9, 15, true ); if (common) m_torso->setup_animation( 151, 1, 20, true ); common = false; break;
+						case nv::KEY_5 : m_legs->setup_animation( 138, 10, 15, true ); if (common) m_torso->setup_animation( 151, 1, 20, true ); common = false; break;
+						case nv::KEY_6 : m_legs->setup_animation( 171, 9, 15, true ); if (common) m_torso->setup_animation( 151, 1, 20, true ); common = false; break;
+						case nv::KEY_Q : m_torso->setup_animation( 90, 40, 20, true ); if (common) m_legs->setup_animation( 171, 10, 15, true ); common = false; break;
+						case nv::KEY_W : m_torso->setup_animation( 130, 6, 15, true ); if (common) m_legs->setup_animation( 171, 10, 15, true ); common = false; break;
+						case nv::KEY_E : m_torso->setup_animation( 136, 6, 15, true ); if (common) m_legs->setup_animation( 171, 10, 15, true ); common = false; break;
+						case nv::KEY_R : m_torso->setup_animation( 142, 5, 20, true ); if (common) m_legs->setup_animation( 171, 10, 15, true ); common = false; break;
+						case nv::KEY_T : m_torso->setup_animation( 147, 4, 20, true ); if (common) m_legs->setup_animation( 171, 10, 15, true ); common = false; break;
+						case nv::KEY_Y : m_torso->setup_animation( 151, 1, 15, true ); if (common) m_legs->setup_animation( 171, 10, 15, true ); common = false; break;
+						case nv::KEY_U : m_torso->setup_animation( 152, 1, 15, true ); if (common) m_legs->setup_animation( 171, 10, 15, true ); common = false; break;
+						case nv::KEY_F1 : nv::profiler::pointer()->log_report(); break;
+						default: break;
+						}
+					}
+					break;
+				default: break;
+				}
+			}
+		}
+		fps_counter.tick();
+	}
+	return true;
+}
+
+application::~application()
+{
+	delete m_program;
+	delete m_torso;
+	delete m_legs;
+	delete m_head;
+	delete m_weapon;
+	delete m_diffuse;
+	delete m_diffuse_weapon;
+	delete m_window;
+	delete m_device;
+}
+
+
+int main(int, char* [])
+{
+	nv::logger log(nv::LOG_TRACE);
+	log.add_sink( new nv::log_file_sink("log.txt"), nv::LOG_TRACE );
+	log.add_sink( new nv::log_console_sink(), nv::LOG_TRACE );
+	
+	NV_LOG( nv::LOG_NOTICE, "Logging started" );
+	application app;
+	if ( app.initialize() )
+	{
+		app.run();
+	}
+	NV_LOG( nv::LOG_NOTICE, "Logging stopped" );
+
+	return 0;
+}
+
Index: /trunk/tests/md5_test/md5_test.cc
===================================================================
--- /trunk/tests/md5_test/md5_test.cc	(revision 231)
+++ /trunk/tests/md5_test/md5_test.cc	(revision 231)
@@ -0,0 +1,279 @@
+#include <nv/common.hh>
+#include <iomanip>
+#include <nv/gfx/keyframed_mesh.hh>
+#include <nv/interface/vertex_buffer.hh>
+#include <nv/gl/gl_device.hh>
+#include <nv/gfx/image.hh>
+#include <nv/interface/context.hh>
+#include <nv/interface/window.hh>
+#include <nv/interface/program.hh>
+#include <nv/interface/texture2d.hh>
+#include <nv/interface/mesh_loader.hh>
+#include <nv/io/c_file_system.hh>
+#include <nv/formats/md5_loader.hh>
+#include <nv/profiler.hh>
+#include <nv/logging.hh>
+#include <nv/logger.hh>
+#include <nv/math.hh>
+#include <nv/time.hh>
+#include <nv/string.hh>
+#include <nv/interface/mesh.hh>
+#include <nv/gfx/skeletal_mesh.hh>
+#include <glm/gtx/rotate_vector.hpp>
+#include <glm/gtc/matrix_access.hpp>
+#include <glm/gtx/matrix_interpolation.hpp>
+
+class mesh_part
+{
+public:
+	mesh_part( const std::string& path, nv::program* program, nv::window* window )
+		: m_mesh( nullptr ), m_program( program ), m_loader( nullptr ), m_animation( nullptr ), m_window( window )
+	{
+		
+		NV_PROFILE("mesh_construct");
+		{
+			NV_PROFILE("loader->load");
+			nv::c_file_system fs;
+			nv::stream* mesh_file = fs.open( path.c_str() );
+			m_loader = new nv::md5_loader();
+			m_loader->load( *mesh_file );
+			delete mesh_file;
+		}
+
+		{
+			NV_PROFILE("create_mesh");
+			m_mesh = new nv::skeletal_mesh( window->get_context(), m_loader );
+		}
+
+	}
+
+	void load_animation( const std::string& path )
+	{
+		delete m_animation;
+		m_animation = nullptr;
+		NV_PROFILE("load_animation");
+		nv::c_file_system fs;
+		nv::stream* anim_file = fs.open( path.c_str() );
+
+		if ( anim_file != nullptr )
+		{
+			m_animation = new nv::md5_animation();
+			if ( !m_animation->load_animation(*anim_file) )
+			{
+				delete m_animation;
+				m_animation = nullptr;
+			}
+			m_mesh->setup_animation( m_animation );
+			delete anim_file;
+		}
+	}
+
+	void update( nv::uint32 ms )
+	{
+		m_mesh->update( ms );
+	}
+
+	void draw( nv::context* context, nv::render_state& rstate, const glm::mat4& m, const glm::mat4& v, const glm::mat4& p )
+	{
+ 		NV_PROFILE( "mesh-draw" );
+ 		glm::mat4 mv = v * m;
+		m_program->set_opt_uniform( "nv_m_model", m );
+ 		m_program->set_opt_uniform( "nv_m_modelview", mv );
+		m_program->set_opt_uniform( "nv_m_view_inv", glm::inverse( v ) );
+ 		m_program->set_opt_uniform( "nv_m_normal", glm::transpose(glm::inverse(glm::mat3(mv))) );
+		m_program->set_uniform( "matrix_mvp", p * mv );
+		context->draw( rstate, m_program, m_mesh );
+	}
+
+	~mesh_part()
+	{
+ 		delete m_mesh;
+	}
+
+private:
+	nv::skeletal_mesh* m_mesh;
+	nv::program*       m_program;
+	nv::md5_loader*    m_loader;
+	nv::md5_animation* m_animation;
+	nv::window*        m_window;
+};
+
+class application
+{
+public:
+	application();
+	bool initialize();
+	bool run();
+	~application();
+protected:
+	nv::device*       m_device;
+	nv::window*       m_window;
+	nv::texture2d*    m_diffuse;
+	nv::texture2d*    m_specular;
+	nv::texture2d*    m_normal;
+	nv::clear_state   m_clear_state;
+	nv::render_state  m_render_state;
+
+	mesh_part*   m_mesh;
+	nv::program* m_program;
+};
+
+application::application()
+{
+	NV_PROFILE( "app_construct" );
+	m_device = new nv::gl_device();
+	m_window = m_device->create_window( 800, 600, false );
+
+	nv::sampler sampler( nv::sampler::LINEAR, nv::sampler::REPEAT );
+	nv::image_data* data = m_device->create_image_data( "data/qshambler_d.png" );
+	m_diffuse  = m_device->create_texture2d( data->get_size(), nv::RGBA, nv::UBYTE, sampler, (void*)data->get_data() );
+	delete data;
+	data = m_device->create_image_data( "data/qshambler_s.png" );
+	m_specular = m_device->create_texture2d( data->get_size(), nv::RGBA, nv::UBYTE, sampler, (void*)data->get_data() );
+	delete data;
+
+	data = m_device->create_image_data( "data/qshambler_local.png" );
+	m_normal = m_device->create_texture2d( data->get_size(), nv::RGBA, nv::UBYTE, sampler, (void*)data->get_data() );
+	delete data;
+
+	m_clear_state.buffers = nv::clear_state::COLOR_AND_DEPTH_BUFFER;
+	m_render_state.depth_test.enabled = true;
+	m_render_state.culling.enabled    = true;
+	m_render_state.culling.order      = nv::culling::CCW;
+	m_render_state.blending.enabled   = false;
+	m_render_state.blending.src_rgb_factor   = nv::blending::SRC_ALPHA;
+	m_render_state.blending.dst_rgb_factor   = nv::blending::ONE_MINUS_SRC_ALPHA;
+	m_render_state.blending.src_alpha_factor = nv::blending::SRC_ALPHA;
+	m_render_state.blending.dst_alpha_factor = nv::blending::ONE_MINUS_SRC_ALPHA;
+}
+
+bool application::initialize()
+{
+	NV_PROFILE( "app_initialize" );
+	m_program = m_device->create_program( nv::slurp( "md5.vert" ), nv::slurp( "md5.frag" ) );
+	m_mesh    = new mesh_part( "data/qshambler.md5mesh", m_program, m_window );
+	m_mesh->load_animation( "data/idle02.md5anim" );
+	return true;
+}
+
+bool application::run()
+{
+	nv::profiler::pointer()->log_report(); 
+	NV_PROFILE( "app_run" );
+	int keypress = 0;
+
+	glm::vec3 move( 0, 50.f, 0 );
+
+	nv::uint32 ticks   = m_device->get_ticks();
+	nv::uint32 last_ticks;
+	nv::fps_counter_class< nv::system_us_timer > fps_counter;
+
+	//m_mesh->setup_animation( 0, m_mesh->get_max_frames(), 2, true );
+
+	while(!keypress) 
+	{
+		last_ticks = ticks;
+		ticks      = m_device->get_ticks();
+		nv::uint32 elapsed = ticks - last_ticks;
+		m_mesh->update( elapsed );
+		{
+			NV_PROFILE( "clear" );
+			m_window->get_context()->clear( m_clear_state );
+		}
+
+		glm::mat4 view;
+		glm::mat4 projection;
+		{
+			NV_PROFILE( "update_sh" );
+
+			glm::vec3 source( 150.0f, 0.0f, 0.0f );
+			glm::vec3 eye = glm::rotate( source, (ticks / 20.f), glm::vec3( 0.0,1.0,0.0 ) );
+
+			view       = glm::lookAt(eye + move, glm::vec3(0.0f, 0.0f, 0.0f) + move, glm::vec3(0.0, 1.0, 0.0));
+			projection = glm::perspective(60.0f, 1.0f*800.0f/600.0f, 0.1f, 1000.0f);
+
+			m_diffuse ->bind( 0 );
+			m_specular->bind( 1 );
+			m_normal  ->bind( 2 );
+			m_program->set_opt_uniform( "nv_m_projection", projection );
+			m_program->set_uniform( "light_position", glm::vec3(180.0, 180.0, 0) );
+			m_program->set_uniform( "light_diffuse",  glm::vec4(0.7,0.7,0.7,1.0) );
+			m_program->set_uniform( "light_specular", glm::vec4(1.0,1.0,1.0,1.0) );
+			m_program->set_uniform( "diffuse", 0 );
+			m_program->set_uniform( "specular", 1 );
+			m_program->set_uniform( "normalmap", 2 );
+		}
+
+		{
+			NV_PROFILE( "draw" );
+			glm::mat4 model      = 
+				glm::mat4(1.f,0.f,0.f,0.f,
+				          0.f,0.f,1.f,0.f,
+						  0.f,1.f,0.f,0.f,
+						  0.f,0.f,0.f,1.f);
+
+			m_mesh->draw( m_window->get_context(), m_render_state, model, view, projection );
+		}
+
+		{
+			NV_PROFILE( "swap" );
+			m_window->swap_buffers();
+		}
+
+		{
+			NV_PROFILE( "pollevent" );
+			nv::io_event event;
+			while(m_window->poll_event(event)) 
+			{      
+				switch (event.type) 
+				{
+				case nv::EV_QUIT:
+					keypress = 1;
+					break;
+				case nv::EV_KEY:
+					if (event.key.pressed)
+					{
+						switch (event.key.code) 
+						{
+						case nv::KEY_ESCAPE : keypress = 1; break;
+						case nv::KEY_F1 : nv::profiler::pointer()->log_report(); break;
+						default: break;
+						}
+					}
+					break;
+				default: break;
+				}
+			}
+		}
+		fps_counter.tick();
+	}
+	return true;
+}
+
+application::~application()
+{
+	delete m_program;
+	delete m_mesh;
+	delete m_diffuse;
+	delete m_window;
+	delete m_device;
+}
+
+
+int main(int, char* [])
+{
+	nv::logger log(nv::LOG_TRACE);
+	log.add_sink( new nv::log_file_sink("log.txt"), nv::LOG_TRACE );
+	log.add_sink( new nv::log_console_sink(), nv::LOG_TRACE );
+	
+	NV_LOG( nv::LOG_NOTICE, "Logging started" );
+	application app;
+	if ( app.initialize() )
+	{
+		app.run();
+	}
+	NV_LOG( nv::LOG_NOTICE, "Logging stopped" );
+
+	return 0;
+}
+
Index: /trunk/tests/render_test/rl.cc
===================================================================
--- /trunk/tests/render_test/rl.cc	(revision 230)
+++ /trunk/tests/render_test/rl.cc	(revision 231)
@@ -80,5 +80,5 @@
 {
 	m_device = new nv::gl_device();
-	m_window = m_device->create_window( 800, 600 );
+	m_window = m_device->create_window( 800, 600, false );
 	
 	nv::image_data* sprites = m_device->create_image_data( "spritesheet.png" );
