Index: trunk/tests/objload_test/nv_objload_test.cc
===================================================================
--- trunk/tests/objload_test/objload_test.cc	(revision 239)
+++ trunk/tests/objload_test/nv_objload_test.cc	(revision 321)
@@ -1,16 +1,13 @@
-#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/obj_loader.hh>
-#include <nv/logging.hh>
-#include <nv/logger.hh>
-#include <nv/math.hh>
-#include <nv/string.hh>
+#include <nv/core/logging.hh>
+#include <nv/core/logger.hh>
+#include <nv/core/math.hh>
+#include <nv/core/string.hh>
 
 class application
@@ -23,12 +20,14 @@
 protected:
 	nv::device*       m_device;
+	nv::context*      m_context;
 	nv::window*       m_window;
-	nv::texture2d*    m_diffuse;
-	nv::texture2d*    m_specular;
+	nv::texture       m_diffuse;
+	nv::texture       m_specular;
+	nv::scene_state   m_scene_state;
 	nv::clear_state   m_clear_state;
 	nv::render_state  m_render_state;
 
-	nv::vertex_array* m_va;
-	nv::program*      m_program;
+	nv::vertex_array  m_va;
+	nv::program       m_program;
 	nv::mesh_data*    m_mesh;
 };
@@ -38,13 +37,15 @@
 	m_device = new nv::gl_device();
 	m_window = m_device->create_window( 800, 600, false );
+	m_context = m_window->get_context();
+
 	nv::sampler sampler( nv::sampler::LINEAR, nv::sampler::REPEAT );
-	
-	nv::image_data* sprites = m_device->create_image_data( "diffuse.png" );
-	m_diffuse  = m_device->create_texture2d( sprites->get_size(), nv::RGBA, nv::UBYTE, sampler, (void*)sprites->get_data() );
-	delete sprites;
 
-	sprites    = m_device->create_image_data( "specular.png" );
-	m_specular = m_device->create_texture2d( sprites->get_size(), nv::RGBA, nv::UBYTE, sampler, (void*)sprites->get_data() );
-	delete sprites;
+	nv::image_data* image = m_device->create_image_data( "diffuse.png" );
+	m_diffuse  = m_device->create_texture( image, sampler );
+	delete image;
+
+	image      = m_device->create_image_data( "specular.png" );
+	m_specular = m_device->create_texture( image, sampler );
+	delete image;
 
 	m_clear_state.buffers = nv::clear_state::COLOR_AND_DEPTH_BUFFER;
@@ -63,11 +64,4 @@
 	nv::stream* mesh_file = fs.open( "mesh.obj" );
 
-// 		nv::mesh_loader* loader = new nv::obj_loader();
-// 		loader->load( *mesh_file );
-// 		nv::mesh_data_old* mesh = loader->release_mesh_data();
-// 		m_count = loader->get_size();
-// 		delete mesh_file;
-// 		delete loader;
-
 	nv::obj_loader* loader = new nv::obj_loader();
 	loader->load( *mesh_file );
@@ -77,7 +71,5 @@
 
 	m_program = m_device->create_program( nv::slurp( "obj.vert" ), nv::slurp( "obj.frag" ) );
-
-//	nv::vertex_buffer* vb = nullptr;
-	m_va = m_device->create_vertex_array( m_mesh, nv::STATIC_DRAW );
+	m_va = m_context->create_vertex_array( m_mesh, nv::STATIC_DRAW );
 
 	return true;
@@ -93,25 +85,16 @@
 	{
 		m_window->get_context()->clear( m_clear_state );
+		m_scene_state.set_model( glm::mat4() );
+		m_scene_state.get_camera().set_perspective(60.0f, 1.0f*800.0f/600.0f, 0.1f, 1000.0f);
+		m_scene_state.get_camera().set_lookat(glm::vec3(6.0f, 8.0f, 6.0f) + move, glm::vec3(0.0f, 4.0f, 0.0f) + move, glm::vec3(0.0, 1.0, 0.0));
 
-		glm::mat4 model = glm::translate(glm::mat4(1.0f), glm::vec3(0.0f, 0.0f, 0.0f));
-		glm::mat4 view  = glm::lookAt(glm::vec3(6.0f, 8.0f, 6.0f) + move, glm::vec3(0.0f, 4.0f, 0.0f) + move, glm::vec3(0.0, 1.0, 0.0));
-		glm::mat4 projection = glm::perspective(60.0f, 1.0f*800.0f/600.0f, 0.1f, 1000.0f);
-		glm::mat4 mv         = view * model;
-		glm::mat3 normal_matrix = glm::transpose(glm::inverse(glm::mat3(mv)));
-
-		m_diffuse->bind( 0 );
-		m_specular->bind( 1 );
-		m_program->set_opt_uniform( "nv_m_modelview", mv );
-		m_program->set_opt_uniform( "nv_m_projection", projection );
-		m_program->set_opt_uniform( "nv_m_normal", normal_matrix );
-		m_program->set_uniform( "matrix_mvp", projection * mv );
-		m_program->set_uniform( "light_position", glm::vec3(12.0, 12.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( "custom_color_1", glm::vec3(1.0,0.0,0.0) );
-		m_program->set_uniform( "custom_color_2", glm::vec3(0.0,0.0,1.0) );
-		m_program->set_uniform( "diffuse", 0 );
-		m_program->set_uniform( "specular", 1 );
-		m_window->get_context()->draw( nv::TRIANGLES, m_render_state, m_program, m_va, m_mesh->get_count() );
+		m_context->bind( m_diffuse, nv::TEX_DIFFUSE );
+		m_context->bind( m_specular, nv::TEX_SPECULAR );
+		m_device->set_uniform( m_program, "light_position", glm::vec3(12.0, 12.0, 0) );
+		m_device->set_uniform( m_program, "light_diffuse",  glm::vec4(0.7,0.7,0.7,1.0) );
+		m_device->set_uniform( m_program, "light_specular", glm::vec4(1.0,1.0,1.0,1.0) );
+		m_device->set_uniform( m_program, "custom_color_1", glm::vec3(1.0,0.0,0.0) );
+		m_device->set_uniform( m_program, "custom_color_2", glm::vec3(0.0,0.0,1.0) );
+		m_context->draw( nv::TRIANGLES, m_render_state, m_scene_state, m_program, m_va, m_mesh->get_count() );
 		m_window->swap_buffers();
 
@@ -148,7 +131,7 @@
 {
 	delete m_mesh;
-	delete m_program;
-	delete m_diffuse;
-	delete m_specular;
+	m_device->release( m_program );
+	m_device->release( m_diffuse );
+	m_device->release( m_specular );
 	delete m_window;
 	delete m_device;
