Index: /trunk/nv/gl/gl_context.hh
===================================================================
--- /trunk/nv/gl/gl_context.hh	(revision 43)
+++ /trunk/nv/gl/gl_context.hh	(revision 44)
@@ -20,12 +20,12 @@
 	{
 	public:
-		void clear( const clear_state& cs );
-		const ivec4& get_viewport();
-		void set_viewport( const ivec4& viewport );
-
+		gl_context();
+		virtual void clear( const clear_state& cs );
+		virtual const ivec4& get_viewport();
+		virtual void set_viewport( const ivec4& viewport );
+		virtual void apply_render_state( const render_state& state );
 	private:
 		void force_apply_render_state( const render_state& state );
 		void force_apply_stencil_face( int face, const stencil_test_face& stencil );
-		void apply_render_state( const render_state& state );
 		void apply_stencil_test( const stencil_test& stencil );
 		void apply_stencil_face( int face, stencil_test_face& stencil, const stencil_test_face& new_stencil );
Index: /trunk/nv/gl/gl_device.hh
===================================================================
--- /trunk/nv/gl/gl_device.hh	(revision 43)
+++ /trunk/nv/gl/gl_device.hh	(revision 44)
@@ -24,4 +24,6 @@
 		virtual program* create_program( const string& vs_source, const string& fs_source );
 		virtual vertex_buffer* create_vertex_buffer( buffer_hint hint, int size, void* source = nullptr );
+		virtual index_buffer* create_index_buffer( buffer_hint hint, int size, void* source = nullptr );
+		virtual vertex_array* create_vertex_array();
 		virtual ~gl_device();
 	private:
Index: /trunk/nv/gl/gl_vertex_buffer.hh
===================================================================
--- /trunk/nv/gl/gl_vertex_buffer.hh	(revision 43)
+++ /trunk/nv/gl/gl_vertex_buffer.hh	(revision 44)
@@ -31,4 +31,24 @@
 	};
 
+	class gl_index_buffer : public index_buffer
+	{
+	public:
+		gl_index_buffer( buffer_hint hint, int size, void* data = nullptr );
+		virtual void assign( void* data );
+		virtual void bind();
+		virtual void unbind();
+		virtual bool is_valid() const;
+	private:
+		gl_buffer_name m_name;
+	};
+
+	class gl_vertex_array : public vertex_array
+	{
+	public:
+		gl_vertex_array();
+		virtual void bind();
+		virtual void unbind();
+	};
+
 } // namespace nv
 
Index: /trunk/nv/gl/gl_window.hh
===================================================================
--- /trunk/nv/gl/gl_window.hh	(revision 43)
+++ /trunk/nv/gl/gl_window.hh	(revision 44)
@@ -14,4 +14,5 @@
 
 #include <nv/interface/window.hh>
+#include <nv/gl/gl_context.hh>
 
 namespace nv
@@ -26,9 +27,12 @@
 		string get_title() const;
 		void set_title( const string& title );
+		virtual context* get_context() { return m_context; }
+		~gl_window();
 	private:
-		uint16 m_width;
-		uint16 m_height;
-		string m_title;
-		void*  m_screen;
+		uint16      m_width;
+		uint16      m_height;
+		string      m_title;
+		void*       m_screen;
+		gl_context* m_context;
 	};
 
Index: /trunk/nv/interface/context.hh
===================================================================
--- /trunk/nv/interface/context.hh	(revision 43)
+++ /trunk/nv/interface/context.hh	(revision 44)
@@ -23,4 +23,7 @@
 	public:
 		virtual void clear( const clear_state& cs ) = 0;
+		virtual void apply_render_state( const render_state& state ) = 0;
+		virtual const ivec4& get_viewport() = 0;
+		virtual void set_viewport( const ivec4& viewport ) = 0;
 	protected:
 		clear_state  m_clear_state;
Index: /trunk/nv/interface/device.hh
===================================================================
--- /trunk/nv/interface/device.hh	(revision 43)
+++ /trunk/nv/interface/device.hh	(revision 44)
@@ -28,4 +28,6 @@
 		virtual program* create_program( const string& vs_source, const string& fs_source ) = 0;
 		virtual vertex_buffer* create_vertex_buffer( buffer_hint hint, int size, void* source = nullptr ) = 0;
+		virtual index_buffer* create_index_buffer( buffer_hint hint, int size, void* source = nullptr ) = 0;
+		virtual vertex_array* create_vertex_array() = 0;
 	};
 
Index: /trunk/nv/interface/vertex_buffer.hh
===================================================================
--- /trunk/nv/interface/vertex_buffer.hh	(revision 43)
+++ /trunk/nv/interface/vertex_buffer.hh	(revision 44)
@@ -14,4 +14,7 @@
 
 #include <nv/common.hh>
+#include <nv/types.hh>
+#include <unordered_map>
+#include <string>
 
 namespace nv
@@ -25,8 +28,8 @@
 	};
 
-	class vertex_buffer
+	class buffer
 	{
 	public:
-		vertex_buffer( buffer_hint hint, int size ) { m_size = size; m_hint = hint; }
+		buffer( buffer_hint hint, int size ) { m_size = size; m_hint = hint; }
 		virtual void assign( void* data ) = 0;
 		virtual void bind() = 0;
@@ -40,4 +43,70 @@
 	};
 
+	class vertex_buffer : public buffer
+	{
+	public:
+		vertex_buffer( buffer_hint hint, int size ) : buffer( hint, size ) {}
+	};
+
+	class index_buffer  : public buffer 
+	{
+	public:
+		index_buffer( buffer_hint hint, int size ) : buffer( hint, size ) {}
+	};
+
+	class vertex_buffer_attribute
+	{
+	public:
+		vertex_buffer_attribute( vertex_buffer* buffer, type datatype, int components, int offset = 0, int stride = 0, bool owner = true )
+			: m_buffer( buffer ), m_datatype( datatype ), m_components( components ), m_offset( offset ), m_stride( stride ), m_owner( owner ) {}
+
+		vertex_buffer* get_buffer() const { return m_buffer; }
+		type get_datatype() const { return m_datatype; }
+		int get_components() const { return m_components; }
+		int get_offset() const { return m_offset; }
+		int get_stride() const { return m_stride; }
+
+		~vertex_buffer_attribute()
+		{
+			if (m_owner)
+			{
+				delete m_buffer;
+			}
+		}
+	protected:
+		vertex_buffer* m_buffer;
+		type           m_datatype;
+		int  m_components;
+		int  m_offset;
+		int  m_stride;
+		bool m_owner;
+	};
+
+	typedef std::unordered_map< int, vertex_buffer_attribute* > vertex_buffer_attribute_map;
+
+	class vertex_array
+	{
+	public:
+		vertex_array() : m_map(), m_index( nullptr ) {}
+		void add_vertex_buffer( int location, vertex_buffer* buffer, type datatype, int components, int offset = 0, int stride = 0, bool owner = true ) 
+		{
+			m_map[ location ] = new vertex_buffer_attribute( buffer, datatype, components, offset, stride, owner );
+		};
+		void set_index_buffer( index_buffer* buffer ) { m_index = buffer; }
+		virtual void bind() = 0;
+		virtual void unbind() = 0;
+		~vertex_array() { 
+			for ( vertex_buffer_attribute_map::iterator i = m_map.begin(); 	i != m_map.end(); ++i ) 
+			{
+				delete i->second;
+			}
+			if (m_index) delete m_index; 
+		}
+	protected:
+		vertex_buffer_attribute_map m_map;
+		index_buffer* m_index;
+	};
+
+
 } // namespace nv
 
Index: /trunk/nv/interface/window.hh
===================================================================
--- /trunk/nv/interface/window.hh	(revision 43)
+++ /trunk/nv/interface/window.hh	(revision 44)
@@ -18,5 +18,5 @@
 namespace nv
 {
-
+	class context;
 	class window
 	{
@@ -26,4 +26,5 @@
 		virtual string get_title() const = 0;
 		virtual void set_title( const string& title ) = 0;
+		virtual context* get_context() = 0;
 	};
 
Index: /trunk/nv/types.hh
===================================================================
--- /trunk/nv/types.hh	(revision 43)
+++ /trunk/nv/types.hh	(revision 44)
@@ -16,4 +16,10 @@
 	enum type
 	{
+		INT,
+		BYTE,
+		SHORT,
+		UINT,
+		UBYTE,
+		USHORT,
 		FLOAT,
 		FLOAT_VECTOR_2,
@@ -23,5 +29,4 @@
 		FLOAT_MATRIX_3,
 		FLOAT_MATRIX_4,
-		INT,
 		INT_VECTOR_2,
 		INT_VECTOR_3,
@@ -43,6 +48,11 @@
 	template < type EnumType > struct enum_to_type {};
 
+	template <> struct enum_to_type< INT >   { typedef int type; };
+	template <> struct enum_to_type< UINT >  { typedef unsigned int type; };
+	template <> struct enum_to_type< SHORT > { typedef short type; };
+	template <> struct enum_to_type< USHORT >{ typedef unsigned short type; };
+	template <> struct enum_to_type< BYTE >  { typedef char type; };
+	template <> struct enum_to_type< UBYTE > { typedef unsigned char type; };
 	template <> struct enum_to_type< FLOAT > { typedef f32 type; };
-	template <> struct enum_to_type< INT >   { typedef int type; };
 
 	template <> struct enum_to_type< FLOAT_VECTOR_2 > { typedef vec2 type; };
@@ -60,6 +70,11 @@
 	template < typename Type > struct type_to_enum {};
 
+	template <> struct type_to_enum< int >           { static const type type = INT; };
+	template <> struct type_to_enum< unsigned int >  { static const type type = UINT; };
+	template <> struct type_to_enum< short >         { static const type type = SHORT; };
+	template <> struct type_to_enum< unsigned short >{ static const type type = USHORT; };
+	template <> struct type_to_enum< char >          { static const type type = BYTE; };
+	template <> struct type_to_enum< unsigned char > { static const type type = UBYTE; };
 	template <> struct type_to_enum< f32 > { static const type type = FLOAT; };
-	template <> struct type_to_enum< int > { static const type type = INT; };
 
 	template <> struct type_to_enum< vec2 > { static const type type = FLOAT_VECTOR_2; };
Index: /trunk/src/gl/gl_context.cc
===================================================================
--- /trunk/src/gl/gl_context.cc	(revision 43)
+++ /trunk/src/gl/gl_context.cc	(revision 44)
@@ -13,4 +13,5 @@
 {
 	// apply_framebuffer
+	
 	apply_scissor_test( cs.scissor_test );
 	apply_color_mask( cs.color_mask );
@@ -35,6 +36,6 @@
 		m_clear_stencil = cs.stencil;
 	}
-
-	glClear( cs.buffers );
+	
+	glClear( clear_state_buffers_to_mask( cs.buffers ) );
 }
 
@@ -347,2 +348,7 @@
 }
 
+
+gl_context::gl_context()
+{
+	force_apply_render_state( m_render_state );
+}
Index: /trunk/src/gl/gl_device.cc
===================================================================
--- /trunk/src/gl/gl_device.cc	(revision 43)
+++ /trunk/src/gl/gl_device.cc	(revision 44)
@@ -56,4 +56,14 @@
 }
 
+index_buffer* gl_device::create_index_buffer( buffer_hint hint, int size, void* source /*= nullptr */ )
+{
+	return new gl_index_buffer( hint, size, source );
+}
+
+vertex_array* gl_device::create_vertex_array()
+{
+	return new gl_vertex_array();
+}
+
 gl_device::~gl_device()
 {
Index: /trunk/src/gl/gl_enum.cc
===================================================================
--- /trunk/src/gl/gl_enum.cc	(revision 43)
+++ /trunk/src/gl/gl_enum.cc	(revision 44)
@@ -186,4 +186,10 @@
 	switch( type )
 	{
+	case BYTE           : return GL_BYTE;
+	case UBYTE          : return GL_UNSIGNED_BYTE;
+	case SHORT          : return GL_SHORT;
+	case USHORT         : return GL_UNSIGNED_SHORT;
+	case INT            : return GL_INT;
+	case UINT	        : return GL_UNSIGNED_INT;
 	case FLOAT          : return GL_FLOAT;
 	case FLOAT_VECTOR_2 : return GL_FLOAT_VEC2;
@@ -193,5 +199,4 @@
 	case FLOAT_MATRIX_3 : return GL_FLOAT_MAT3;
 	case FLOAT_MATRIX_4 : return GL_FLOAT_MAT4;
-	case INT            : return GL_INT;
 	case INT_VECTOR_2   : return GL_INT_VEC2;
 	case INT_VECTOR_3   : return GL_INT_VEC3;
@@ -205,15 +210,20 @@
 	switch( gl_enum )
 	{
-	case GL_FLOAT      : return FLOAT;
-	case GL_FLOAT_VEC2 : return FLOAT_VECTOR_2;
-	case GL_FLOAT_VEC3 : return FLOAT_VECTOR_3;
-	case GL_FLOAT_VEC4 : return FLOAT_VECTOR_4;
-	case GL_FLOAT_MAT2 : return FLOAT_MATRIX_2;
-	case GL_FLOAT_MAT3 : return FLOAT_MATRIX_3;
-	case GL_FLOAT_MAT4 : return FLOAT_MATRIX_4;
-	case GL_INT        : return INT;
-	case GL_INT_VEC2   : return INT_VECTOR_2;
-	case GL_INT_VEC3   : return INT_VECTOR_3;
-	case GL_INT_VEC4   : return INT_VECTOR_4;
+	case GL_BYTE           : return BYTE;
+	case GL_UNSIGNED_BYTE  : return UBYTE;
+	case GL_SHORT          : return SHORT;
+	case GL_UNSIGNED_SHORT : return USHORT;
+	case GL_INT            : return INT;
+	case GL_UNSIGNED_INT   : return UINT;
+	case GL_FLOAT          : return FLOAT;
+	case GL_FLOAT_VEC2     : return FLOAT_VECTOR_2;
+	case GL_FLOAT_VEC3     : return FLOAT_VECTOR_3;
+	case GL_FLOAT_VEC4     : return FLOAT_VECTOR_4;
+	case GL_FLOAT_MAT2     : return FLOAT_MATRIX_2;
+	case GL_FLOAT_MAT3     : return FLOAT_MATRIX_3;
+	case GL_FLOAT_MAT4     : return FLOAT_MATRIX_4;
+	case GL_INT_VEC2       : return INT_VECTOR_2;
+	case GL_INT_VEC3       : return INT_VECTOR_3;
+	case GL_INT_VEC4       : return INT_VECTOR_4;
 	default : return type(0); // TODO: throw!
 	}
Index: /trunk/src/gl/gl_vertex_buffer.cc
===================================================================
--- /trunk/src/gl/gl_vertex_buffer.cc	(revision 43)
+++ /trunk/src/gl/gl_vertex_buffer.cc	(revision 44)
@@ -40,2 +40,68 @@
 	return m_name.is_valid();
 }
+
+gl_index_buffer::gl_index_buffer( buffer_hint hint, int size, void* data ) 
+	: index_buffer( hint, size ), m_name()
+{
+	if (data)
+	{
+		assign( data );
+	}
+}
+
+void gl_index_buffer::assign( void* data )
+{
+	glBindBuffer( GL_ELEMENT_ARRAY_BUFFER, m_name.get_value() );
+	glBufferData( GL_ELEMENT_ARRAY_BUFFER, m_size, data, buffer_hint_to_enum( m_hint ) );
+	glBindBuffer( GL_ELEMENT_ARRAY_BUFFER, 0);
+}
+
+void gl_index_buffer::bind()
+{
+	glBindBuffer( GL_ELEMENT_ARRAY_BUFFER, m_name.get_value() );
+}
+
+void gl_index_buffer::unbind()
+{
+	glBindBuffer( GL_ELEMENT_ARRAY_BUFFER, 0 );
+}
+
+bool gl_index_buffer::is_valid() const
+{
+	return m_name.is_valid();
+}
+
+gl_vertex_array::gl_vertex_array()
+{
+
+}
+
+void gl_vertex_array::bind()
+{
+	for ( vertex_buffer_attribute_map::iterator i = m_map.begin(); 	i != m_map.end(); ++i ) 
+	{
+		int location                = i->first;
+		vertex_buffer_attribute* va = i->second;
+		vertex_buffer*           vb = va->get_buffer();
+		glEnableVertexAttribArray( location );
+		vb->bind();
+		glVertexAttribPointer( 
+			location, 
+			va->get_components(), 
+			nv::type_to_gl_enum( va->get_datatype() ),
+			GL_FALSE,
+			va->get_stride(),
+			(void*)va->get_offset()
+			);
+		vb->unbind();
+	}
+
+}
+
+void gl_vertex_array::unbind()
+{
+	for ( vertex_buffer_attribute_map::iterator i = m_map.begin(); 	i != m_map.end(); ++i ) 
+	{
+		glDisableVertexAttribArray( i->first );
+	}
+}
Index: /trunk/src/gl/gl_window.cc
===================================================================
--- /trunk/src/gl/gl_window.cc	(revision 43)
+++ /trunk/src/gl/gl_window.cc	(revision 44)
@@ -29,4 +29,7 @@
 	NV_LOG( LOG_INFO, "OpenGL Version      : " << glGetString(GL_VERSION) );
 	NV_LOG( LOG_INFO, "OpenGL GLSL Version : " << glGetString(GL_SHADING_LANGUAGE_VERSION) );
+
+	m_context = new gl_context();
+	m_context->set_viewport( nv::ivec4( 0, 0, m_width, m_height ) );
 }
 
@@ -51,2 +54,7 @@
 	m_title = title;
 }
+
+gl_window::~gl_window()
+{
+	delete m_context;
+}
