Index: /trunk/nv/gfx/image.hh
===================================================================
--- /trunk/nv/gfx/image.hh	(revision 89)
+++ /trunk/nv/gfx/image.hh	(revision 89)
@@ -0,0 +1,105 @@
+// Copyright (C) 2012-2013 ChaosForge / Kornel Kisielewicz
+// http://chaosforge.org/
+//
+// This file is part of NV Libraries.
+// For conditions of distribution and use, see copyright notice in nv.hh
+
+#ifndef NV_IMAGE_HH
+#define NV_IMAGE_HH
+
+#include <nv/common.hh>
+#include <glm/glm.hpp>
+
+namespace nv
+{
+	/**
+	 * Defines the starting position of some region and its size.
+	 */
+	struct region
+	{
+		glm::ivec2 pos;
+		glm::ivec2 size;
+
+		region() : pos(0,0), size(0,0) {}
+		region( glm::ivec2 pos, glm::ivec2 size ) : pos(pos), size(size) {}
+	};
+
+	/**
+	 * Holder for images.
+	 *
+	 * By an image we understand a group of pixels, limited to X and Y
+	 * dimensions, of a certain depth (by depth we mean how rich
+	 * the colours are.
+	 */
+	class image
+	{
+	public:
+		/**
+		 * Constructor
+		 *
+		 * @arg[in] size : Dimensions of the image as a vector.
+		 * @arg[in] depth :  Depth of the image.
+		 */
+		image( glm::ivec2 size, size_t depth );
+		/**
+		 * Full constructor.
+		 *
+		 * Allows creation of an image with specified data. It is
+		 * to reverse the image (from left to right).
+		 *
+		 * @arg[in] size : Dimensions of the image as a vector.
+		 * @arg[in] depth : Depth of the image.
+		 * @arg[in] data : Data of the image.
+		 * @arg[in] reversed : Determines if the image should be
+		 * 	reversed or not.
+		 */
+		image( glm::ivec2 size, size_t depth, const uint8 * data, bool reversed = false );
+		/**
+		 * Fills the image with a given value.
+		 *
+		 * @arg[in] value : Value to fill.
+		 */
+		void fill( uint8 value );
+		/**
+		 * Just like fill, but a region can be specified.
+		 *
+		 * @arg[in] r : Region to be filled.
+		 * @arg[in] data : Data to fill the region
+		 * @arg[in] stride : 
+		 */
+		void set_region( region r, const uint8 * data, size_t stride = 0 );
+		/**
+		 * Default destructor. Deallocates data.
+		 */
+		virtual ~image();
+		/**
+		 * Getter for data.
+		 *
+		 * @return The data.
+		 */
+		const uint8 * get_data() const { return m_data; }
+		/**
+		 * Getter for size.
+		 *
+		 * @return Returns the size of the image as a vector.
+		 */
+		const glm::ivec2 get_size() const { return m_size; }
+		/**
+		 * Getter for depth.
+		 *
+		 * @return Returns depth of the image.
+		 */
+		const size_t get_depth() const { return m_depth; }
+	protected:
+		/** Defines the size of the image as a vector. */
+		glm::ivec2 m_size;
+		/** Deefines the depth of the image. */
+		size_t     m_depth;
+		/** Holder for data. */
+		uint8*     m_data;
+	};
+
+}
+
+#endif // NV_IMAGE_HH
+
Index: /trunk/nv/gfx/texture_atlas.hh
===================================================================
--- /trunk/nv/gfx/texture_atlas.hh	(revision 89)
+++ /trunk/nv/gfx/texture_atlas.hh	(revision 89)
@@ -0,0 +1,36 @@
+// Copyright (C) 2012-2013 ChaosForge / Kornel Kisielewicz
+// http://chaosforge.org/
+//
+// This file is part of NV Libraries.
+// For conditions of distribution and use, see copyright notice in nv.hh
+
+#ifndef NV_GL_TEXTURE_ATLAS_HH
+#define NV_GL_TEXTURE_ATLAS_HH
+
+#include <nv/common.hh>
+#include <nv/gfx/image.hh>
+#include <glm/glm.hpp>
+#include <vector>
+
+namespace nv
+{
+
+	class texture_atlas : public image
+	{
+	public:
+		texture_atlas( glm::ivec2 size, size_t depth );
+		region get_region( glm::ivec2 size );
+		void clear();
+		const size_t get_used() const { return m_used; }
+	protected:
+		int fit( size_t index, glm::ivec2 size );
+		void merge();
+	private:
+		size_t  m_used;
+		std::vector<glm::ivec3> m_nodes;
+	};
+
+}
+
+#endif // NV_GL_TEXTURE_ATLAS_HH
+
Index: /trunk/nv/gfx/texture_font.hh
===================================================================
--- /trunk/nv/gfx/texture_font.hh	(revision 89)
+++ /trunk/nv/gfx/texture_font.hh	(revision 89)
@@ -0,0 +1,60 @@
+// Copyright (C) 2012-2013 ChaosForge / Kornel Kisielewicz
+// http://chaosforge.org/
+//
+// This file is part of NV Libraries.
+// For conditions of distribution and use, see copyright notice in nv.hh
+
+#ifndef NV_GL_TEXTURE_FONT_HH
+#define NV_GL_TEXTURE_FONT_HH
+
+#include <string>
+
+#include <nv/common.hh>
+#include <nv/gfx/texture_atlas.hh>
+#include <glm/glm.hpp>
+#include <unordered_map>
+
+namespace nv
+{
+	struct texture_glyph
+	{
+		uint16 charcode;
+		glm::ivec2 size;
+		glm::ivec2 offset;
+		glm::vec2 advance;
+		glm::vec2 tl;
+		glm::vec2 br;
+		std::unordered_map< uint16, float > kerning;
+
+		texture_glyph();
+		float get_kerning( const uint16 charcode );
+	};
+
+	class texture_font
+	{
+		public:
+			texture_font( texture_atlas* atlas, const char * filename, float size );
+			const texture_glyph* get_glyph( uint16 charcode ) const;
+			bool load_glyphs( const std::string& codes );
+			~texture_font();
+		private:
+			void generate_kerning();
+		private:
+			std::unordered_map< uint16, texture_glyph > m_glyphs;
+			texture_atlas* m_atlas;
+			std::string m_filename;
+			float m_size;
+			float m_height;
+			float m_linegap;
+			float m_ascender;
+			float m_descender;
+			bool m_hinting;
+			bool m_filtering;
+			uint8 m_lcd_weights[5];
+			void* m_rlibrary;
+			void* m_rface;
+	};
+}
+
+#endif // NV_GL_TEXTURE_FONT_HH
+
Index: unk/nv/gl/image.hh
===================================================================
--- /trunk/nv/gl/image.hh	(revision 88)
+++ 	(revision )
@@ -1,105 +1,0 @@
-// Copyright (C) 2012-2013 ChaosForge / Kornel Kisielewicz
-// http://chaosforge.org/
-//
-// This file is part of NV Libraries.
-// For conditions of distribution and use, see copyright notice in nv.hh
-
-#ifndef NV_IMAGE_HH
-#define NV_IMAGE_HH
-
-#include <nv/common.hh>
-#include <glm/glm.hpp>
-
-namespace nv
-{
-	/**
-	 * Defines the starting position of some region and its size.
-	 */
-	struct region
-	{
-		glm::ivec2 pos;
-		glm::ivec2 size;
-
-		region() : pos(0,0), size(0,0) {}
-		region( glm::ivec2 pos, glm::ivec2 size ) : pos(pos), size(size) {}
-	};
-
-	/**
-	 * Holder for images.
-	 *
-	 * By an image we understand a group of pixels, limited to X and Y
-	 * dimensions, of a certain depth (by depth we mean how rich
-	 * the colours are.
-	 */
-	class image
-	{
-	public:
-		/**
-		 * Constructor
-		 *
-		 * @arg[in] size : Dimensions of the image as a vector.
-		 * @arg[in] depth :  Depth of the image.
-		 */
-		image( glm::ivec2 size, size_t depth );
-		/**
-		 * Full constructor.
-		 *
-		 * Allows creation of an image with specified data. It is
-		 * to reverse the image (from left to right).
-		 *
-		 * @arg[in] size : Dimensions of the image as a vector.
-		 * @arg[in] depth : Depth of the image.
-		 * @arg[in] data : Data of the image.
-		 * @arg[in] reversed : Determines if the image should be
-		 * 	reversed or not.
-		 */
-		image( glm::ivec2 size, size_t depth, const uint8 * data, bool reversed = false );
-		/**
-		 * Fills the image with a given value.
-		 *
-		 * @arg[in] value : Value to fill.
-		 */
-		void fill( uint8 value );
-		/**
-		 * Just like fill, but a region can be specified.
-		 *
-		 * @arg[in] r : Region to be filled.
-		 * @arg[in] data : Data to fill the region
-		 * @arg[in] stride : 
-		 */
-		void set_region( region r, const uint8 * data, size_t stride = 0 );
-		/**
-		 * Default destructor. Deallocates data.
-		 */
-		virtual ~image();
-		/**
-		 * Getter for data.
-		 *
-		 * @return The data.
-		 */
-		const uint8 * get_data() const { return m_data; }
-		/**
-		 * Getter for size.
-		 *
-		 * @return Returns the size of the image as a vector.
-		 */
-		const glm::ivec2 get_size() const { return m_size; }
-		/**
-		 * Getter for depth.
-		 *
-		 * @return Returns depth of the image.
-		 */
-		const size_t get_depth() const { return m_depth; }
-	protected:
-		/** Defines the size of the image as a vector. */
-		glm::ivec2 m_size;
-		/** Deefines the depth of the image. */
-		size_t     m_depth;
-		/** Holder for data. */
-		uint8*     m_data;
-	};
-
-}
-
-#endif // NV_IMAGE_HH
-
Index: unk/nv/gl/texture_atlas.hh
===================================================================
--- /trunk/nv/gl/texture_atlas.hh	(revision 88)
+++ 	(revision )
@@ -1,36 +1,0 @@
-// Copyright (C) 2012-2013 ChaosForge / Kornel Kisielewicz
-// http://chaosforge.org/
-//
-// This file is part of NV Libraries.
-// For conditions of distribution and use, see copyright notice in nv.hh
-
-#ifndef NV_GL_TEXTURE_ATLAS_HH
-#define NV_GL_TEXTURE_ATLAS_HH
-
-#include <nv/common.hh>
-#include <nv/gl/image.hh>
-#include <glm/glm.hpp>
-#include <vector>
-
-namespace nv
-{
-
-	class texture_atlas : public image
-	{
-	public:
-		texture_atlas( glm::ivec2 size, size_t depth );
-		region get_region( glm::ivec2 size );
-		void clear();
-		const size_t get_used() const { return m_used; }
-	protected:
-		int fit( size_t index, glm::ivec2 size );
-		void merge();
-	private:
-		size_t  m_used;
-		std::vector<glm::ivec3> m_nodes;
-	};
-
-}
-
-#endif // NV_GL_TEXTURE_ATLAS_HH
-
Index: unk/nv/gl/texture_font.hh
===================================================================
--- /trunk/nv/gl/texture_font.hh	(revision 88)
+++ 	(revision )
@@ -1,60 +1,0 @@
-// Copyright (C) 2012-2013 ChaosForge / Kornel Kisielewicz
-// http://chaosforge.org/
-//
-// This file is part of NV Libraries.
-// For conditions of distribution and use, see copyright notice in nv.hh
-
-#ifndef NV_GL_TEXTURE_FONT_HH
-#define NV_GL_TEXTURE_FONT_HH
-
-#include <string>
-
-#include <nv/common.hh>
-#include <nv/gl/texture_atlas.hh>
-#include <glm/glm.hpp>
-#include <unordered_map>
-
-namespace nv
-{
-	struct texture_glyph
-	{
-		uint16 charcode;
-		glm::ivec2 size;
-		glm::ivec2 offset;
-		glm::vec2 advance;
-		glm::vec2 tl;
-		glm::vec2 br;
-		std::unordered_map< uint16, float > kerning;
-
-		texture_glyph();
-		float get_kerning( const uint16 charcode );
-	};
-
-	class texture_font
-	{
-		public:
-			texture_font( texture_atlas* atlas, const char * filename, float size );
-			const texture_glyph* get_glyph( uint16 charcode ) const;
-			bool load_glyphs( const std::string& codes );
-			~texture_font();
-		private:
-			void generate_kerning();
-		private:
-			std::unordered_map< uint16, texture_glyph > m_glyphs;
-			texture_atlas* m_atlas;
-			std::string m_filename;
-			float m_size;
-			float m_height;
-			float m_linegap;
-			float m_ascender;
-			float m_descender;
-			bool m_hinting;
-			bool m_filtering;
-			uint8 m_lcd_weights[5];
-			void* m_rlibrary;
-			void* m_rface;
-	};
-}
-
-#endif // NV_GL_TEXTURE_FONT_HH
-
Index: /trunk/src/gfx/image.cc
===================================================================
--- /trunk/src/gfx/image.cc	(revision 89)
+++ /trunk/src/gfx/image.cc	(revision 89)
@@ -0,0 +1,57 @@
+// Copyright (C) 2011 Kornel Kisielewicz
+// This file is part of NV Libraries.
+// For conditions of distribution and use, see copyright notice in nv.hh
+
+#include "nv/gfx/image.hh"
+
+#include <cstring>
+
+using namespace nv;
+
+image::image( glm::ivec2 size, size_t depth )
+	: m_size( size ), m_depth( depth ), m_data( nullptr )
+{
+	m_data = new uint8[ m_size.x * m_size.y * m_depth ];
+}
+
+image::image( glm::ivec2 size, size_t depth, const uint8 * data, bool reversed )
+	: m_size( size ), m_depth( depth ), m_data( nullptr )
+{
+	m_data = new uint8[ m_size.x * m_size.y * m_depth ];
+
+	if ( reversed )
+	{
+		for( int i = 0; i < size.y; ++i )
+		{
+			memcpy( m_data + size.x * ( size.y - i - 1) * m_depth, data + i * size.x * m_depth, m_size.x * m_depth );
+		}
+
+	}
+	else 
+	{
+		memcpy( m_data, data, m_size.x * m_size.y * m_depth );
+	}
+}
+
+void image::fill( uint8 value )
+{
+	memset( m_data, value, m_size.x * m_size.y * m_depth );
+}
+
+void image::set_region( region r, const uint8 * data, size_t stride )
+{
+	if ( stride == 0 ) stride = r.size.x;
+
+	for( int i = 0; i < r.size.y; ++i )
+ 	{
+		memcpy( m_data+((r.pos.y+i)*m_size.x + r.pos.x ) * m_depth, 
+			data + (i*stride), r.size.x * m_depth );
+	}
+}
+
+image::~image()
+{
+	delete[] m_data;
+}
+
+
Index: /trunk/src/gfx/texture_atlas.cc
===================================================================
--- /trunk/src/gfx/texture_atlas.cc	(revision 89)
+++ /trunk/src/gfx/texture_atlas.cc	(revision 89)
@@ -0,0 +1,133 @@
+// Copyright (C) 2012-2013 ChaosForge / Kornel Kisielewicz
+// http://chaosforge.org/
+//
+// This file is part of NV Libraries.
+// For conditions of distribution and use, see copyright notice in nv.hh
+
+#include "nv/gfx/texture_atlas.hh"
+
+#include "nv/logging.hh"
+#include <iostream>
+
+using namespace nv;
+
+texture_atlas::texture_atlas( glm::ivec2 size, size_t depth )
+	: image( size, depth ), m_used( 0 )
+{
+	m_nodes.push_back( glm::ivec3( 1, 1, m_size.x - 2 ) );
+	fill( 0 );
+}
+
+region texture_atlas::get_region( glm::ivec2 size )
+{
+	region r ( glm::ivec2(0,0), size );
+
+	int best_height = INT_MAX;
+	int best_index  = -1;
+	int best_width  = INT_MAX;
+
+	for( size_t i=0; i < m_nodes.size(); ++i )
+	{
+		int y = fit( i, size );
+		if( y >= 0 )
+		{
+			glm::ivec3 node = m_nodes[ i ];
+			if ( ( (y + size.y) < best_height ) ||
+				( ((y + size.y) == best_height) && (node.z < best_width)) )
+			{
+				best_height = y + size.y;
+				best_index = i;
+				best_width = node.z;
+				r.pos.x = node.x;
+				r.pos.y = y;
+			}
+		}
+	}
+   
+	if ( best_index == -1 )
+	{
+		return region( glm::ivec2( -1, -1 ), glm::ivec2( 0, 0 ) );
+	}
+
+	m_nodes.insert( m_nodes.begin() + best_index, glm::ivec3( r.pos.x, r.pos.y + size.y, size.x ) );
+
+	for( size_t i = best_index+1; i < m_nodes.size(); ++i )
+	{
+		glm::ivec3 node = m_nodes[ i ];
+		glm::ivec3 prev = m_nodes[ i-1 ];
+
+		if (node.x < (prev.x + prev.z) )
+		{
+			int shrink = prev.x + prev.z - node.x;
+			m_nodes[ i ].x += shrink;
+			m_nodes[ i ].z -= shrink;
+
+			if (m_nodes[ i ].z <= 0)
+			{
+				m_nodes.erase( m_nodes.begin() + i );
+				--i;
+			}
+			else
+			{
+				break;
+			}
+		}
+		else
+		{
+			break;
+		}
+	}
+	merge();
+	m_used += size.x * size.y;
+	return r;
+}
+
+int texture_atlas::fit( size_t index, glm::ivec2 size )
+{
+	glm::ivec3 node = m_nodes[ index ];
+
+	if ( (  node.x + size.x ) > ( m_size.x - 1 ) ) 
+	{
+		return -1;
+	}
+
+	int y     = node.y;
+	int wleft = size.x;
+
+	while( wleft > 0 )
+	{
+		node = m_nodes[ index ];
+		if( node.y > y )
+		{
+			y = node.y;
+		}
+		if( (y + size.y) > (m_size.y-1) )
+		{
+			return -1;
+		}
+		wleft -= node.z;
+		++index;
+	}
+	return y;
+}
+
+void texture_atlas::merge()
+{
+	for( size_t i=0; i < m_nodes.size()-1; ++i )
+    {
+		if( m_nodes[ i ].y == m_nodes[ i+1 ].y )
+		{
+			m_nodes[ i ].z += m_nodes[ i+1 ].z;
+            m_nodes.erase( m_nodes.begin()+i+1 );
+			--i;
+		}
+    }
+}
+
+void texture_atlas::clear()
+{
+	m_nodes.clear();
+	m_used = 0;
+	m_nodes.push_back( glm::ivec3( 1, 1, m_size.x - 2 ) );
+	fill( 0 );
+}
Index: /trunk/src/gfx/texture_font.cc
===================================================================
--- /trunk/src/gfx/texture_font.cc	(revision 89)
+++ /trunk/src/gfx/texture_font.cc	(revision 89)
@@ -0,0 +1,160 @@
+// Copyright (C) 2012-2013 ChaosForge / Kornel Kisielewicz
+// http://chaosforge.org/
+//
+// This file is part of NV Libraries.
+// For conditions of distribution and use, see copyright notice in nv.hh
+#include <sstream>
+#include <stdexcept>
+
+#include "nv/gfx/texture_font.hh"
+#include "nv/lib/freetype2.hh"
+
+using namespace nv;
+
+texture_glyph::texture_glyph()
+	: charcode(0), size(0,0), offset(0,0), advance(0.f,0.f), tl(0.f,0.f), br(0.f,0.f)
+{
+}
+
+float texture_glyph::get_kerning( const uint16 charcode )
+{
+	auto i = kerning.find( charcode );
+	return i != kerning.end() ? i->second : 0.0f;
+}
+
+texture_font::texture_font( texture_atlas* atlas, const char * filename, float size )
+	: m_atlas( atlas ), m_filename(filename), m_size( size ), 
+	m_height(0), m_linegap(0), m_ascender(0), m_descender(0),
+	m_hinting( true ), m_filtering( true ), m_rlibrary( nullptr ), m_rface( nullptr )
+{
+	size_t hres = 64;
+	FT_Error error;
+	FT_Matrix matrix = { 
+		(int)((1.0/hres) * 0x10000L),
+		(int)((0.0)      * 0x10000L),
+		(int)((0.0)      * 0x10000L),
+		(int)((1.0)      * 0x10000L) 
+	};
+
+	m_lcd_weights[0] = 0x10;
+	m_lcd_weights[1] = 0x40;
+	m_lcd_weights[2] = 0x70;
+	m_lcd_weights[3] = 0x40;
+	m_lcd_weights[4] = 0x10;
+	 
+	error = FT_Init_FreeType( (FT_Library*)(&m_rlibrary) );
+	if ( error ) NV_THROW( std::runtime_error, "FT_Error" );
+
+	error = FT_New_Face( (FT_Library)(m_rlibrary), filename, 0, (FT_Face*)(&m_rface) );
+	if ( error ) NV_THROW( std::runtime_error, "FT_Error" );
+
+	error = FT_Set_Char_Size( (FT_Face)(m_rface), (int)(size*64), 0, 72*64, 72 ); 
+	if ( error ) NV_THROW( std::runtime_error, "FT_Error" );
+
+    FT_Set_Transform( (FT_Face)(m_rface), &matrix, NULL );
+
+    FT_Size_Metrics metrics = ((FT_Face)(m_rface))->size->metrics; 
+    m_ascender  = (float)(metrics.ascender >> 6) / 100.0f;
+    m_descender = (float)(metrics.descender >> 6) / 100.0f;
+    m_height    = (float)(metrics.height >> 6) / 100.0f;
+    m_linegap   = m_height - m_ascender + m_descender; 
+}
+
+const texture_glyph* texture_font::get_glyph( uint16 charcode ) const
+{
+	auto i = m_glyphs.find( charcode );
+	if ( i == m_glyphs.end() )
+	{
+		return nullptr;
+	}
+	return &(i->second);
+}
+
+bool texture_font::load_glyphs( const std::string& codes )
+{
+	FT_Face face     = (FT_Face)(m_rface);
+	size_t depth     = m_atlas->get_depth();
+	glm::ivec2 asize = m_atlas->get_size();
+	FT_Int32 flags = 0; 
+	flags |= FT_LOAD_RENDER; 
+	if( !m_hinting )
+	{
+		flags |= FT_LOAD_NO_HINTING | FT_LOAD_NO_AUTOHINT;
+	}
+	else
+	{
+		flags |= FT_LOAD_FORCE_AUTOHINT;
+	} 
+
+	if( m_atlas->get_depth() == 3 )
+	{
+		FT_Library_SetLcdFilter( (FT_Library)(m_rlibrary), FT_LCD_FILTER_LIGHT );
+		flags |= FT_LOAD_TARGET_LCD;
+		if ( m_filtering )
+		{
+			FT_Library_SetLcdFilterWeights( (FT_Library)(m_rlibrary), m_lcd_weights );
+		}
+	} 
+
+	for ( char c : codes )
+	{
+		FT_UInt glyph_index = FT_Get_Char_Index( face, c ); 
+		FT_Error error = FT_Load_Glyph( face, glyph_index, flags ); 
+		if ( error )
+		{
+			std::stringstream error_msg;
+			error_msg << "FT_Error while loading glyphs, error: "
+				<< error << " code: " << c; 
+			NV_THROW( std::runtime_error, error_msg.str().c_str() );
+		}
+
+		FT_GlyphSlot slot   = face->glyph;
+		FT_Bitmap ft_bitmap = slot->bitmap;
+		int ft_bitmap_width = slot->bitmap.width;
+		int ft_bitmap_rows  = slot->bitmap.rows;
+		int ft_glyph_top    = slot->bitmap_top;
+		int ft_glyph_left   = slot->bitmap_left;
+
+		glm::ivec2 gsize( ft_bitmap_width/depth + 1, ft_bitmap_rows + 1 ); 
+		region r = m_atlas->get_region( gsize );
+		if ( r.pos.x < 0 ) 
+		{
+			std::stringstream error_msg;
+			error_msg << "Atlas full while loading glyphs, "
+				<< "r.pos.x: " << r.pos.x << " code: "
+				<< c; 
+			NV_THROW( std::runtime_error, error_msg.str().c_str() );
+		}
+		r.size.x -= 1;
+		r.size.y -= 1;
+		m_atlas->set_region( r, ft_bitmap.buffer, ft_bitmap.pitch );
+
+		m_glyphs[ c ] = texture_glyph();
+		texture_glyph* g = &(m_glyphs.find( c )->second);
+
+		g->charcode = c;
+		g->size     = gsize;
+		g->offset   = glm::ivec2( ft_glyph_left, ft_glyph_top );
+		g->tl       = glm::vec2( r.pos.x/(float)asize.x, r.pos.y/(float)asize.y );
+		g->br       = glm::vec2( ( r.pos.x + gsize.x )/(float)asize.x, (r.pos.y + gsize.y )/(float)asize.y );
+
+		// Discard hinting to get advance
+		FT_Load_Glyph( face, glyph_index, FT_LOAD_RENDER | FT_LOAD_NO_HINTING);
+		slot = face->glyph;
+		g->advance = glm::ivec2( slot->advance.x/64.0, slot->advance.y/64.0 );
+	}
+	generate_kerning();
+	return true;
+}
+
+texture_font::~texture_font()
+{
+	if ( m_rface )    FT_Done_Face( (FT_Face)(m_rface) );
+	if ( m_rlibrary ) FT_Done_FreeType( (FT_Library)(m_rlibrary) );
+}
+
+void texture_font::generate_kerning()
+{
+
+}
+
Index: unk/src/gl/image.cc
===================================================================
--- /trunk/src/gl/image.cc	(revision 88)
+++ 	(revision )
@@ -1,57 +1,0 @@
-// Copyright (C) 2011 Kornel Kisielewicz
-// This file is part of NV Libraries.
-// For conditions of distribution and use, see copyright notice in nv.hh
-
-#include "nv/gl/image.hh"
-
-#include <cstring>
-
-using namespace nv;
-
-image::image( glm::ivec2 size, size_t depth )
-	: m_size( size ), m_depth( depth ), m_data( nullptr )
-{
-	m_data = new uint8[ m_size.x * m_size.y * m_depth ];
-}
-
-image::image( glm::ivec2 size, size_t depth, const uint8 * data, bool reversed )
-	: m_size( size ), m_depth( depth ), m_data( nullptr )
-{
-	m_data = new uint8[ m_size.x * m_size.y * m_depth ];
-
-	if ( reversed )
-	{
-		for( int i = 0; i < size.y; ++i )
-		{
-			memcpy( m_data + size.x * ( size.y - i - 1) * m_depth, data + i * size.x * m_depth, m_size.x * m_depth );
-		}
-
-	}
-	else 
-	{
-		memcpy( m_data, data, m_size.x * m_size.y * m_depth );
-	}
-}
-
-void image::fill( uint8 value )
-{
-	memset( m_data, value, m_size.x * m_size.y * m_depth );
-}
-
-void image::set_region( region r, const uint8 * data, size_t stride )
-{
-	if ( stride == 0 ) stride = r.size.x;
-
-	for( int i = 0; i < r.size.y; ++i )
- 	{
-		memcpy( m_data+((r.pos.y+i)*m_size.x + r.pos.x ) * m_depth, 
-			data + (i*stride), r.size.x * m_depth );
-	}
-}
-
-image::~image()
-{
-	delete[] m_data;
-}
-
-
Index: unk/src/gl/texture_atlas.cc
===================================================================
--- /trunk/src/gl/texture_atlas.cc	(revision 88)
+++ 	(revision )
@@ -1,133 +1,0 @@
-// Copyright (C) 2012-2013 ChaosForge / Kornel Kisielewicz
-// http://chaosforge.org/
-//
-// This file is part of NV Libraries.
-// For conditions of distribution and use, see copyright notice in nv.hh
-
-#include "nv/gl/texture_atlas.hh"
-
-#include "nv/logging.hh"
-#include <iostream>
-
-using namespace nv;
-
-texture_atlas::texture_atlas( glm::ivec2 size, size_t depth )
-	: image( size, depth ), m_used( 0 )
-{
-	m_nodes.push_back( glm::ivec3( 1, 1, m_size.x - 2 ) );
-	fill( 0 );
-}
-
-region texture_atlas::get_region( glm::ivec2 size )
-{
-	region r ( glm::ivec2(0,0), size );
-
-	int best_height = INT_MAX;
-	int best_index  = -1;
-	int best_width  = INT_MAX;
-
-	for( size_t i=0; i < m_nodes.size(); ++i )
-	{
-		int y = fit( i, size );
-		if( y >= 0 )
-		{
-			glm::ivec3 node = m_nodes[ i ];
-			if ( ( (y + size.y) < best_height ) ||
-				( ((y + size.y) == best_height) && (node.z < best_width)) )
-			{
-				best_height = y + size.y;
-				best_index = i;
-				best_width = node.z;
-				r.pos.x = node.x;
-				r.pos.y = y;
-			}
-		}
-	}
-   
-	if ( best_index == -1 )
-	{
-		return region( glm::ivec2( -1, -1 ), glm::ivec2( 0, 0 ) );
-	}
-
-	m_nodes.insert( m_nodes.begin() + best_index, glm::ivec3( r.pos.x, r.pos.y + size.y, size.x ) );
-
-	for( size_t i = best_index+1; i < m_nodes.size(); ++i )
-	{
-		glm::ivec3 node = m_nodes[ i ];
-		glm::ivec3 prev = m_nodes[ i-1 ];
-
-		if (node.x < (prev.x + prev.z) )
-		{
-			int shrink = prev.x + prev.z - node.x;
-			m_nodes[ i ].x += shrink;
-			m_nodes[ i ].z -= shrink;
-
-			if (m_nodes[ i ].z <= 0)
-			{
-				m_nodes.erase( m_nodes.begin() + i );
-				--i;
-			}
-			else
-			{
-				break;
-			}
-		}
-		else
-		{
-			break;
-		}
-	}
-	merge();
-	m_used += size.x * size.y;
-	return r;
-}
-
-int texture_atlas::fit( size_t index, glm::ivec2 size )
-{
-	glm::ivec3 node = m_nodes[ index ];
-
-	if ( (  node.x + size.x ) > ( m_size.x - 1 ) ) 
-	{
-		return -1;
-	}
-
-	int y     = node.y;
-	int wleft = size.x;
-
-	while( wleft > 0 )
-	{
-		node = m_nodes[ index ];
-		if( node.y > y )
-		{
-			y = node.y;
-		}
-		if( (y + size.y) > (m_size.y-1) )
-		{
-			return -1;
-		}
-		wleft -= node.z;
-		++index;
-	}
-	return y;
-}
-
-void texture_atlas::merge()
-{
-	for( size_t i=0; i < m_nodes.size()-1; ++i )
-    {
-		if( m_nodes[ i ].y == m_nodes[ i+1 ].y )
-		{
-			m_nodes[ i ].z += m_nodes[ i+1 ].z;
-            m_nodes.erase( m_nodes.begin()+i+1 );
-			--i;
-		}
-    }
-}
-
-void texture_atlas::clear()
-{
-	m_nodes.clear();
-	m_used = 0;
-	m_nodes.push_back( glm::ivec3( 1, 1, m_size.x - 2 ) );
-	fill( 0 );
-}
Index: unk/src/gl/texture_font.cc
===================================================================
--- /trunk/src/gl/texture_font.cc	(revision 88)
+++ 	(revision )
@@ -1,160 +1,0 @@
-// Copyright (C) 2012-2013 ChaosForge / Kornel Kisielewicz
-// http://chaosforge.org/
-//
-// This file is part of NV Libraries.
-// For conditions of distribution and use, see copyright notice in nv.hh
-#include <sstream>
-#include <stdexcept>
-
-#include "nv/gl/texture_font.hh"
-#include "nv/lib/freetype2.hh"
-
-using namespace nv;
-
-texture_glyph::texture_glyph()
-	: charcode(0), size(0,0), offset(0,0), advance(0.f,0.f), tl(0.f,0.f), br(0.f,0.f)
-{
-}
-
-float texture_glyph::get_kerning( const uint16 charcode )
-{
-	auto i = kerning.find( charcode );
-	return i != kerning.end() ? i->second : 0.0f;
-}
-
-texture_font::texture_font( texture_atlas* atlas, const char * filename, float size )
-	: m_atlas( atlas ), m_filename(filename), m_size( size ), 
-	m_height(0), m_linegap(0), m_ascender(0), m_descender(0),
-	m_hinting( true ), m_filtering( true ), m_rlibrary( nullptr ), m_rface( nullptr )
-{
-	size_t hres = 64;
-	FT_Error error;
-	FT_Matrix matrix = { 
-		(int)((1.0/hres) * 0x10000L),
-		(int)((0.0)      * 0x10000L),
-		(int)((0.0)      * 0x10000L),
-		(int)((1.0)      * 0x10000L) 
-	};
-
-	m_lcd_weights[0] = 0x10;
-	m_lcd_weights[1] = 0x40;
-	m_lcd_weights[2] = 0x70;
-	m_lcd_weights[3] = 0x40;
-	m_lcd_weights[4] = 0x10;
-	 
-	error = FT_Init_FreeType( (FT_Library*)(&m_rlibrary) );
-	if ( error ) NV_THROW( std::runtime_error, "FT_Error" );
-
-	error = FT_New_Face( (FT_Library)(m_rlibrary), filename, 0, (FT_Face*)(&m_rface) );
-	if ( error ) NV_THROW( std::runtime_error, "FT_Error" );
-
-	error = FT_Set_Char_Size( (FT_Face)(m_rface), (int)(size*64), 0, 72*64, 72 ); 
-	if ( error ) NV_THROW( std::runtime_error, "FT_Error" );
-
-    FT_Set_Transform( (FT_Face)(m_rface), &matrix, NULL );
-
-    FT_Size_Metrics metrics = ((FT_Face)(m_rface))->size->metrics; 
-    m_ascender  = (float)(metrics.ascender >> 6) / 100.0f;
-    m_descender = (float)(metrics.descender >> 6) / 100.0f;
-    m_height    = (float)(metrics.height >> 6) / 100.0f;
-    m_linegap   = m_height - m_ascender + m_descender; 
-}
-
-const texture_glyph* texture_font::get_glyph( uint16 charcode ) const
-{
-	auto i = m_glyphs.find( charcode );
-	if ( i == m_glyphs.end() )
-	{
-		return nullptr;
-	}
-	return &(i->second);
-}
-
-bool texture_font::load_glyphs( const std::string& codes )
-{
-	FT_Face face     = (FT_Face)(m_rface);
-	size_t depth     = m_atlas->get_depth();
-	glm::ivec2 asize = m_atlas->get_size();
-	FT_Int32 flags = 0; 
-	flags |= FT_LOAD_RENDER; 
-	if( !m_hinting )
-	{
-		flags |= FT_LOAD_NO_HINTING | FT_LOAD_NO_AUTOHINT;
-	}
-	else
-	{
-		flags |= FT_LOAD_FORCE_AUTOHINT;
-	} 
-
-	if( m_atlas->get_depth() == 3 )
-	{
-		FT_Library_SetLcdFilter( (FT_Library)(m_rlibrary), FT_LCD_FILTER_LIGHT );
-		flags |= FT_LOAD_TARGET_LCD;
-		if ( m_filtering )
-		{
-			FT_Library_SetLcdFilterWeights( (FT_Library)(m_rlibrary), m_lcd_weights );
-		}
-	} 
-
-	for ( char c : codes )
-	{
-		FT_UInt glyph_index = FT_Get_Char_Index( face, c ); 
-		FT_Error error = FT_Load_Glyph( face, glyph_index, flags ); 
-		if ( error )
-		{
-			std::stringstream error_msg;
-			error_msg << "FT_Error while loading glyphs, error: "
-				<< error << " code: " << c; 
-			NV_THROW( std::runtime_error, error_msg.str().c_str() );
-		}
-
-		FT_GlyphSlot slot   = face->glyph;
-		FT_Bitmap ft_bitmap = slot->bitmap;
-		int ft_bitmap_width = slot->bitmap.width;
-		int ft_bitmap_rows  = slot->bitmap.rows;
-		int ft_glyph_top    = slot->bitmap_top;
-		int ft_glyph_left   = slot->bitmap_left;
-
-		glm::ivec2 gsize( ft_bitmap_width/depth + 1, ft_bitmap_rows + 1 ); 
-		region r = m_atlas->get_region( gsize );
-		if ( r.pos.x < 0 ) 
-		{
-			std::stringstream error_msg;
-			error_msg << "Atlas full while loading glyphs, "
-				<< "r.pos.x: " << r.pos.x << " code: "
-				<< c; 
-			NV_THROW( std::runtime_error, error_msg.str().c_str() );
-		}
-		r.size.x -= 1;
-		r.size.y -= 1;
-		m_atlas->set_region( r, ft_bitmap.buffer, ft_bitmap.pitch );
-
-		m_glyphs[ c ] = texture_glyph();
-		texture_glyph* g = &(m_glyphs.find( c )->second);
-
-		g->charcode = c;
-		g->size     = gsize;
-		g->offset   = glm::ivec2( ft_glyph_left, ft_glyph_top );
-		g->tl       = glm::vec2( r.pos.x/(float)asize.x, r.pos.y/(float)asize.y );
-		g->br       = glm::vec2( ( r.pos.x + gsize.x )/(float)asize.x, (r.pos.y + gsize.y )/(float)asize.y );
-
-		// Discard hinting to get advance
-		FT_Load_Glyph( face, glyph_index, FT_LOAD_RENDER | FT_LOAD_NO_HINTING);
-		slot = face->glyph;
-		g->advance = glm::ivec2( slot->advance.x/64.0, slot->advance.y/64.0 );
-	}
-	generate_kerning();
-	return true;
-}
-
-texture_font::~texture_font()
-{
-	if ( m_rface )    FT_Done_Face( (FT_Face)(m_rface) );
-	if ( m_rlibrary ) FT_Done_FreeType( (FT_Library)(m_rlibrary) );
-}
-
-void texture_font::generate_kerning()
-{
-
-}
-
Index: /trunk/tests/render_test/rl.cc
===================================================================
--- /trunk/tests/render_test/rl.cc	(revision 88)
+++ /trunk/tests/render_test/rl.cc	(revision 89)
@@ -3,5 +3,5 @@
 #include <nv/interface/vertex_buffer.hh>
 #include <nv/gl/gl_device.hh>
-#include <nv/gl/image.hh>
+#include <nv/gfx/image.hh>
 #include <nv/interface/context.hh>
 #include <nv/interface/window.hh>
