Bläddra i källkod

Merge branch 'world' of https://github.com/taylor001/crown into world

Conflicts:
	engine/Config.h.in
Daniele Bartolini 12 år sedan
förälder
incheckning
7c9630f27f

+ 1 - 1
CMakeLists.txt

@@ -72,7 +72,7 @@ add_subdirectory(engine)
 
 
 # select optional projects to build
 # select optional projects to build
 if (CROWN_BUILD_TOOLS)
 if (CROWN_BUILD_TOOLS)
-	#add_subdirectory(tools)
+	add_subdirectory(tools)
 endif (CROWN_BUILD_TOOLS)
 endif (CROWN_BUILD_TOOLS)
 
 
 if (CROWN_BUILD_SAMPLES)
 if (CROWN_BUILD_SAMPLES)

+ 17 - 12
engine/Config.h.in

@@ -40,20 +40,25 @@ OTHER DEALINGS IN THE SOFTWARE.
 #define CE_MAX_RENDER_TARGETS				32
 #define CE_MAX_RENDER_TARGETS				32
 #define CE_MAX_VERTEX_BUFFERS				1024
 #define CE_MAX_VERTEX_BUFFERS				1024
 #define CE_MAX_INDEX_BUFFERS				1024
 #define CE_MAX_INDEX_BUFFERS				1024
-#define CE_MAX_SHADERS						1024
-#define CE_MAX_GPU_PROGRAMS					1024
+#define CE_MAX_SHADERS						512
+#define CE_MAX_GPU_PROGRAMS					512
 #define CE_MAX_UNIFORMS						128
 #define CE_MAX_UNIFORMS						128
-#define CE_TRANSIENT_VERTEX_BUFFER_SIZE		2 * 1024	// In bytes
-#define CE_TRANSIENT_INDEX_BUFFER_SIZE		2 * 1024	// In bytes
-#define CE_MAX_UNIFORM_NAME_LENGTH			64			// Including NUL character
+#define CE_TRANSIENT_VERTEX_BUFFER_SIZE		6 * 1024 * 1024		// In bytes
+#define CE_TRANSIENT_INDEX_BUFFER_SIZE		2 * 1024 * 1024		// In bytes
+#define CE_MAX_UNIFORM_NAME_LENGTH			64					// Including NUL character
 
 
 #define CE_MAX_WORLDS						1024
 #define CE_MAX_WORLDS						1024
-#define CE_MAX_UNITS						65000		// Per world
-#define CE_MAX_CAMERAS						16			// Per world
-#define CE_MAX_ACTORS						1024		// Per world
-#define CE_MAX_CONTROLLERS					1024		// Per world
-#define CE_MAX_TRIGGERS						1024		// Per world
-#define CE_MAX_JOINTS						512			// Per world
-#define CE_MAX_SOUND_INSTANCES				64			// Per world
+#define CE_MAX_UNITS						65000				// Per world
+#define CE_MAX_CAMERAS						16					// Per world
+#define CE_MAX_ACTORS						1024				// Per world
+#define CE_MAX_CONTROLLERS					16					// Per world
+#define CE_MAX_TRIGGERS						1024				// Per world
+#define CE_MAX_JOINTS						512					// Per world
+#define CE_MAX_SOUND_INSTANCES				64					// Per world
 
 
 #define CE_MAX_CONSOLE_CLIENTS				32
 #define CE_MAX_CONSOLE_CLIENTS				32
+
+#define CE_MAX_GUI_RECTS 					64					// Per Gui
+#define CE_MAX_GUI_TRIANGLES 				64					// Per Gui
+#define CE_MAX_GUI_IMAGES 					64					// Per Gui
+#define CE_MAX_GUI_TEXTS 					64					// Per Gui

+ 65 - 41
engine/gui/Gui.cpp

@@ -36,6 +36,8 @@ OTHER DEALINGS IN THE SOFTWARE.
 #include "Vector2.h"
 #include "Vector2.h"
 #include "Color4.h"
 #include "Color4.h"
 #include "FontResource.h"
 #include "FontResource.h"
+#include "Device.h"
+#include "OsWindow.h"
 
 
 #include "GuiRect.h"
 #include "GuiRect.h"
 #include "GuiTriangle.h"
 #include "GuiTriangle.h"
@@ -128,34 +130,22 @@ Gui::Gui(RenderWorld& render_world, GuiResource* gr, Renderer& r)
 	: m_render_world(render_world)
 	: m_render_world(render_world)
 	, m_resource(gr)
 	, m_resource(gr)
 	, m_r(r)
 	, m_r(r)
-	, m_rect_pool(default_allocator(), MAX_GUI_RECTS, sizeof(GuiRect), CE_ALIGNOF(GuiRect))
-	, m_triangle_pool(default_allocator(), MAX_GUI_TRIANGLES, sizeof(GuiTriangle), CE_ALIGNOF(GuiTriangle))
-	, m_image_pool(default_allocator(), MAX_GUI_IMAGES, sizeof(GuiImage), CE_ALIGNOF(GuiImage))
-	, m_text_pool(default_allocator(), MAX_GUI_TEXTS, sizeof(GuiText), CE_ALIGNOF(GuiText))
+	, m_resolution(1000, 625)
+	, m_visible(true)
+	, m_rect_pool(default_allocator(), CE_MAX_GUI_RECTS, sizeof(GuiRect), CE_ALIGNOF(GuiRect))
+	, m_triangle_pool(default_allocator(), CE_MAX_GUI_TRIANGLES, sizeof(GuiTriangle), CE_ALIGNOF(GuiTriangle))
+	, m_image_pool(default_allocator(), CE_MAX_GUI_IMAGES, sizeof(GuiImage), CE_ALIGNOF(GuiImage))
+	, m_text_pool(default_allocator(), CE_MAX_GUI_TEXTS, sizeof(GuiText), CE_ALIGNOF(GuiText))
 {
 {
 	// orthographic projection
 	// orthographic projection
-	Vector2 size = m_resource->gui_size();
-	m_projection.build_projection_ortho_rh(0, size.x, size.y, 0, -0.01f, 100.0f);
+	m_projection.build_projection_ortho_rh(0, m_resolution.x, m_resolution.y, 0, -0.01f, 100.0f);
 
 
 	// pose
 	// pose
 	Vector3 pos = m_resource->gui_position();
 	Vector3 pos = m_resource->gui_position();
 	m_pose.load_identity();
 	m_pose.load_identity();
 	m_pose.set_translation(pos);
 	m_pose.set_translation(pos);
 
 
-	// FIXME FIXME FIXME -- Shaders init should not be here
-	gui_default_vs = m_r.create_shader(ShaderType::VERTEX, default_vertex);
-	gui_default_fs = m_r.create_shader(ShaderType::FRAGMENT, default_fragment);
-	gui_texture_fs = m_r.create_shader(ShaderType::FRAGMENT, texture_fragment);
-	gui_default_program = m_r.create_gpu_program(gui_default_vs, gui_default_fs);
-	gui_texture_program = m_r.create_gpu_program(gui_default_vs, gui_texture_fs);
-	gui_albedo_0 = m_r.create_uniform("u_albedo_0", UniformType::INTEGER_1, 1);
-
-	// FIXME FIXME FIXME -- Shaders init should not be here
-	font_vs = m_r.create_shader(ShaderType::VERTEX, sdf_vertex);
-	font_fs = m_r.create_shader(ShaderType::FRAGMENT, sdf_fragment);
-	font_program = m_r.create_gpu_program(font_vs, font_fs);
-	font_uniform = m_r.create_uniform("u_texture", UniformType::INTEGER_1, 1);
-
+	create_gfx();
 
 
 	// Gui's rects creation
 	// Gui's rects creation
 	for (uint32_t i = 0; i < m_resource->num_rects(); i++)
 	for (uint32_t i = 0; i < m_resource->num_rects(); i++)
@@ -190,11 +180,6 @@ Gui::Gui(RenderWorld& render_world, GuiResource* gr, Renderer& r)
 
 
 		create_image(mat, pos, size);
 		create_image(mat, pos, size);
 	}
 	}
-
-	// Gui's texts creation
-
-/*	FontResource* res = (FontResource*) device()->resource_manager()->lookup("font", "fonts/veramobi");
-	create_text("ciaO mAngOZOide", res, 30, Vector3(300, 400, 0));*/
 }
 }
 
 
 //-----------------------------------------------------------------------------
 //-----------------------------------------------------------------------------
@@ -220,25 +205,13 @@ Gui::~Gui()
 		CE_DELETE(m_text_pool, m_texts[i]);
 		CE_DELETE(m_text_pool, m_texts[i]);
 	}
 	}
 
 
-	// FIXME FIXME FIXME -- Shaders destruction should not be here
-	m_r.destroy_uniform(gui_albedo_0);
-	m_r.destroy_gpu_program(gui_texture_program);
-	m_r.destroy_gpu_program(gui_default_program);
-	m_r.destroy_shader(gui_texture_fs);
-	m_r.destroy_shader(gui_default_fs);
-	m_r.destroy_shader(gui_default_vs);
-
-	// FIXME FIXME FIXME -- Shaders destruction should not be here
-	m_r.destroy_uniform(font_uniform);
-	m_r.destroy_gpu_program(font_program);
-	m_r.destroy_shader(font_vs);
-	m_r.destroy_shader(font_fs);
+	destroy_gfx();
 }
 }
 
 
 //-----------------------------------------------------------------------------
 //-----------------------------------------------------------------------------
 Vector2 Gui::resolution() const
 Vector2 Gui::resolution() const
 {
 {
-	return m_resource->gui_size();
+	return m_resolution;
 }
 }
 
 
 //-----------------------------------------------------------------------------
 //-----------------------------------------------------------------------------
@@ -248,6 +221,18 @@ void Gui::move(const Vector3& pos)
 	m_pose.set_translation(pos);
 	m_pose.set_translation(pos);
 }
 }
 
 
+//-----------------------------------------------------------------------------
+void Gui::show()
+{
+	m_visible = true;
+}
+
+//-----------------------------------------------------------------------------
+void Gui::hide()
+{
+	m_visible = false;
+}
+
 //-----------------------------------------------------------------------------
 //-----------------------------------------------------------------------------
 GuiRectId Gui::create_rect(const Vector3& pos, const Vector2& size, const Color4& color)
 GuiRectId Gui::create_rect(const Vector3& pos, const Vector2& size, const Color4& color)
 {
 {
@@ -355,11 +340,18 @@ void Gui::destroy_text(GuiTextId id)
 //-----------------------------------------------------------------------------
 //-----------------------------------------------------------------------------
 void Gui::render()
 void Gui::render()
 {
 {
-	Vector2 size = m_resource->gui_size();
+	// resolution
+	uint32_t width = 0;
+	uint32_t height = 0;
+	device()->window()->get_size(width, height);
+	m_resolution.x = width;
+	m_resolution.y = height;
 
 
 	m_r.set_layer_view(1, Matrix4x4::IDENTITY);
 	m_r.set_layer_view(1, Matrix4x4::IDENTITY);
 	m_r.set_layer_projection(1, m_projection);
 	m_r.set_layer_projection(1, m_projection);
-	m_r.set_layer_viewport(1, m_pose.translation().x, m_pose.translation().y, size.x, size.y);
+	m_r.set_layer_viewport(1, m_pose.translation().x, m_pose.translation().y, m_resolution.x, m_resolution.y);
+
+	if (!m_visible) return;
 
 
 	// Render all Rects
 	// Render all Rects
 	for (uint32_t i = 0; i < m_rects.size(); i++)
 	for (uint32_t i = 0; i < m_rects.size(); i++)
@@ -426,4 +418,36 @@ void Gui::render()
 	}
 	}
 }
 }
 
 
+//-----------------------------------------------------------------------------
+void Gui::create_gfx()
+{
+	gui_default_vs = m_r.create_shader(ShaderType::VERTEX, default_vertex);
+	gui_default_fs = m_r.create_shader(ShaderType::FRAGMENT, default_fragment);
+	gui_texture_fs = m_r.create_shader(ShaderType::FRAGMENT, texture_fragment);
+	gui_default_program = m_r.create_gpu_program(gui_default_vs, gui_default_fs);
+	gui_texture_program = m_r.create_gpu_program(gui_default_vs, gui_texture_fs);
+	gui_albedo_0 = m_r.create_uniform("u_albedo_0", UniformType::INTEGER_1, 1);
+
+	font_vs = m_r.create_shader(ShaderType::VERTEX, sdf_vertex);
+	font_fs = m_r.create_shader(ShaderType::FRAGMENT, sdf_fragment);
+	font_program = m_r.create_gpu_program(font_vs, font_fs);
+	font_uniform = m_r.create_uniform("u_texture", UniformType::INTEGER_1, 1);
+}
+
+//-----------------------------------------------------------------------------
+void Gui::destroy_gfx()
+{
+	m_r.destroy_uniform(gui_albedo_0);
+	m_r.destroy_gpu_program(gui_texture_program);
+	m_r.destroy_gpu_program(gui_default_program);
+	m_r.destroy_shader(gui_texture_fs);
+	m_r.destroy_shader(gui_default_fs);
+	m_r.destroy_shader(gui_default_vs);
+
+	m_r.destroy_uniform(font_uniform);
+	m_r.destroy_gpu_program(font_program);
+	m_r.destroy_shader(font_vs);
+	m_r.destroy_shader(font_fs);
+}
+
 } // namespace crown
 } // namespace crown

+ 17 - 9
engine/gui/Gui.h

@@ -32,11 +32,7 @@ OTHER DEALINGS IN THE SOFTWARE.
 #include "PoolAllocator.h"
 #include "PoolAllocator.h"
 #include "Vector2.h"
 #include "Vector2.h"
 #include "Resource.h"
 #include "Resource.h"
-
-#define MAX_GUI_RECTS 64
-#define MAX_GUI_TRIANGLES 64
-#define MAX_GUI_IMAGES 64
-#define MAX_GUI_TEXTS 64
+#include "Config.h"
 
 
 namespace crown
 namespace crown
 {
 {
@@ -67,6 +63,9 @@ struct Gui
 	Vector2				resolution() const;
 	Vector2				resolution() const;
 	void				move(const Vector3& pos);
 	void				move(const Vector3& pos);
 
 
+	void				show();
+	void				hide();
+
 	GuiRectId			create_rect(const Vector3& pos, const Vector2& size, const Color4& color);
 	GuiRectId			create_rect(const Vector3& pos, const Vector2& size, const Color4& color);
 	void				update_rect(GuiRectId id, const Vector3& pos, const Vector2& size, const Color4& color);
 	void				update_rect(GuiRectId id, const Vector3& pos, const Vector2& size, const Color4& color);
 	void				destroy_rect(GuiRectId id);
 	void				destroy_rect(GuiRectId id);
@@ -85,6 +84,12 @@ struct Gui
 
 
 	void				render();
 	void				render();
 
 
+private:
+
+	// FIXME FIXME FIXME -- tmp way
+	void 				create_gfx();
+	void 				destroy_gfx();
+
 public:
 public:
 
 
 	RenderWorld&		m_render_world;
 	RenderWorld&		m_render_world;
@@ -93,16 +98,19 @@ public:
 
 
 	Matrix4x4			m_projection;
 	Matrix4x4			m_projection;
 	Matrix4x4			m_pose;
 	Matrix4x4			m_pose;
+	Vector2				m_resolution;
+
+	bool				m_visible;
 
 
 	PoolAllocator		m_rect_pool;
 	PoolAllocator		m_rect_pool;
 	PoolAllocator		m_triangle_pool;
 	PoolAllocator		m_triangle_pool;
 	PoolAllocator		m_image_pool;
 	PoolAllocator		m_image_pool;
 	PoolAllocator		m_text_pool;
 	PoolAllocator		m_text_pool;
 
 
-	IdArray<MAX_GUI_RECTS, GuiRect*> m_rects;
-	IdArray<MAX_GUI_TRIANGLES, GuiTriangle*> m_triangles;
-	IdArray<MAX_GUI_IMAGES, GuiImage*> m_images;
-	IdArray<MAX_GUI_TEXTS, GuiText*> m_texts;
+	IdArray<CE_MAX_GUI_RECTS, GuiRect*> m_rects;
+	IdArray<CE_MAX_GUI_TRIANGLES, GuiTriangle*> m_triangles;
+	IdArray<CE_MAX_GUI_IMAGES, GuiImage*> m_images;
+	IdArray<CE_MAX_GUI_TEXTS, GuiText*> m_texts;
 };
 };
 
 
 } // namespace crown
 } // namespace crown

+ 38 - 12
engine/lua/LuaGui.cpp

@@ -65,7 +65,31 @@ CE_EXPORT int gui_move(lua_State* L)
 	return 0;
 	return 0;
 }
 }
 
 
-//-------------------------------------------------------------------------
+//-----------------------------------------------------------------------------
+CE_EXPORT int gui_show(lua_State* L)
+{
+	LuaStack stack(L);
+
+	Gui* gui = stack.get_gui(1);
+
+	gui->show();
+
+	return 0;
+}
+
+//-----------------------------------------------------------------------------
+CE_EXPORT int gui_hide(lua_State* L)
+{
+	LuaStack stack(L);
+
+	Gui* gui = stack.get_gui(1);
+
+	gui->hide();
+
+	return 0;
+}
+
+//-----------------------------------------------------------------------------
 CE_EXPORT int gui_create_rect(lua_State* L)
 CE_EXPORT int gui_create_rect(lua_State* L)
 {
 {
 	LuaStack stack(L);
 	LuaStack stack(L);
@@ -82,7 +106,7 @@ CE_EXPORT int gui_create_rect(lua_State* L)
 	return 1;
 	return 1;
 }
 }
 
 
-//-------------------------------------------------------------------------
+//-----------------------------------------------------------------------------
 CE_EXPORT int gui_update_rect(lua_State* L)
 CE_EXPORT int gui_update_rect(lua_State* L)
 {
 {
 	LuaStack stack(L);
 	LuaStack stack(L);
@@ -99,7 +123,7 @@ CE_EXPORT int gui_update_rect(lua_State* L)
 	return 0;
 	return 0;
 }
 }
 
 
-//-------------------------------------------------------------------------
+//-----------------------------------------------------------------------------
 CE_EXPORT int gui_destroy_rect(lua_State* L)
 CE_EXPORT int gui_destroy_rect(lua_State* L)
 {
 {
 	LuaStack stack(L);
 	LuaStack stack(L);
@@ -112,7 +136,7 @@ CE_EXPORT int gui_destroy_rect(lua_State* L)
 	return 0;
 	return 0;
 }
 }
 
 
-//-------------------------------------------------------------------------
+//-----------------------------------------------------------------------------
 CE_EXPORT int gui_create_triangle(lua_State* L)
 CE_EXPORT int gui_create_triangle(lua_State* L)
 {
 {
 	LuaStack stack(L);
 	LuaStack stack(L);
@@ -131,7 +155,7 @@ CE_EXPORT int gui_create_triangle(lua_State* L)
 	return 1;
 	return 1;
 }
 }
 
 
-//-------------------------------------------------------------------------
+//-----------------------------------------------------------------------------
 CE_EXPORT int gui_update_triangle(lua_State* L)
 CE_EXPORT int gui_update_triangle(lua_State* L)
 {
 {
 	LuaStack stack(L);
 	LuaStack stack(L);
@@ -149,7 +173,7 @@ CE_EXPORT int gui_update_triangle(lua_State* L)
 	return 0;
 	return 0;
 }
 }
 
 
-//-------------------------------------------------------------------------
+//-----------------------------------------------------------------------------
 CE_EXPORT int gui_destroy_triangle(lua_State* L)
 CE_EXPORT int gui_destroy_triangle(lua_State* L)
 {
 {
 	LuaStack stack(L);
 	LuaStack stack(L);
@@ -162,7 +186,7 @@ CE_EXPORT int gui_destroy_triangle(lua_State* L)
 	return 0;
 	return 0;
 }
 }
 
 
-//-------------------------------------------------------------------------
+//-----------------------------------------------------------------------------
 CE_EXPORT int gui_create_image(lua_State* L)
 CE_EXPORT int gui_create_image(lua_State* L)
 {
 {
 	LuaStack stack(L);
 	LuaStack stack(L);
@@ -182,7 +206,7 @@ CE_EXPORT int gui_create_image(lua_State* L)
 	return 1;
 	return 1;
 }
 }
 
 
-//-------------------------------------------------------------------------
+//-----------------------------------------------------------------------------
 CE_EXPORT int gui_update_image(lua_State* L)
 CE_EXPORT int gui_update_image(lua_State* L)
 {
 {
 	LuaStack stack(L);
 	LuaStack stack(L);
@@ -197,7 +221,7 @@ CE_EXPORT int gui_update_image(lua_State* L)
 	return 0;
 	return 0;
 }
 }
 
 
-//-------------------------------------------------------------------------
+//-----------------------------------------------------------------------------
 CE_EXPORT int gui_destroy_image(lua_State* L)
 CE_EXPORT int gui_destroy_image(lua_State* L)
 {
 {
 	LuaStack stack(L);
 	LuaStack stack(L);
@@ -210,7 +234,7 @@ CE_EXPORT int gui_destroy_image(lua_State* L)
 	return 0;
 	return 0;
 }
 }
 
 
-//-------------------------------------------------------------------------
+//-----------------------------------------------------------------------------
 CE_EXPORT int gui_create_text(lua_State* L)
 CE_EXPORT int gui_create_text(lua_State* L)
 {
 {
 	LuaStack stack(L);
 	LuaStack stack(L);
@@ -230,7 +254,7 @@ CE_EXPORT int gui_create_text(lua_State* L)
 	return 1;
 	return 1;
 }
 }
 
 
-//-------------------------------------------------------------------------
+//-----------------------------------------------------------------------------
 CE_EXPORT int gui_update_text(lua_State* L)
 CE_EXPORT int gui_update_text(lua_State* L)
 {
 {
 	LuaStack stack(L);
 	LuaStack stack(L);
@@ -246,7 +270,7 @@ CE_EXPORT int gui_update_text(lua_State* L)
 	return 0;
 	return 0;
 }
 }
 
 
-//-------------------------------------------------------------------------
+//-----------------------------------------------------------------------------
 CE_EXPORT int gui_destroy_text(lua_State* L)
 CE_EXPORT int gui_destroy_text(lua_State* L)
 {
 {
 	LuaStack stack(L);
 	LuaStack stack(L);
@@ -264,6 +288,8 @@ void load_gui(LuaEnvironment& env)
 {
 {
 	env.load_module_function("Gui", "resolution",		gui_resolution);
 	env.load_module_function("Gui", "resolution",		gui_resolution);
 	env.load_module_function("Gui", "move",				gui_move);
 	env.load_module_function("Gui", "move",				gui_move);
+	env.load_module_function("Gui", "show",				gui_show);
+	env.load_module_function("Gui", "hide",				gui_hide);
 	env.load_module_function("Gui", "create_rect",		gui_create_rect);
 	env.load_module_function("Gui", "create_rect",		gui_create_rect);
 	env.load_module_function("Gui", "update_rect",		gui_update_rect);
 	env.load_module_function("Gui", "update_rect",		gui_update_rect);
 	env.load_module_function("Gui", "destroy_rect",		gui_destroy_rect);
 	env.load_module_function("Gui", "destroy_rect",		gui_destroy_rect);

+ 2 - 1
engine/os/linux/main.cpp

@@ -329,6 +329,7 @@ public:
 					m_window->m_y = ev.y;
 					m_window->m_y = ev.y;
 					m_window->m_width = ev.width;
 					m_window->m_width = ev.width;
 					m_window->m_height = ev.height;
 					m_window->m_height = ev.height;
+
 					break;
 					break;
 				}
 				}
 				case OsEvent::EXIT:
 				case OsEvent::EXIT:
@@ -432,7 +433,7 @@ public:
 	//				// Text input part
 	//				// Text input part
 	//				if (event.type == KeyPress && len > 0)
 	//				if (event.type == KeyPress && len > 0)
 	//				{
 	//				{
-	//					//crownEvent.event_type = ET_TEXT;
+	//					//crownEvent.event_type = ET_TEXT;m_queue
 	//					//crownEvent.text.type = TET_TEXT_INPUT;
 	//					//crownEvent.text.type = TET_TEXT_INPUT;
 	//					strncpy(keyboardEvent.text, string, 4);
 	//					strncpy(keyboardEvent.text, string, 4);
 
 

+ 1 - 6
engine/resource/GuiResource.cpp

@@ -97,11 +97,8 @@ void compile(Filesystem& fs, const char* resource_path, File* out_file)
 	JSONParser json(buf);
 	JSONParser json(buf);
 	JSONElement root = json.root();
 	JSONElement root = json.root();
 
 
-	List<float>			m_gui_position(default_allocator());
-	List<float>			m_gui_size(default_allocator());
-
+	List<float>	m_gui_position(default_allocator());
 	root.key("position").to_array(m_gui_position);
 	root.key("position").to_array(m_gui_position);
-	root.key("size").to_array(m_gui_size);
 
 
 	// Parse & compile all rects
 	// Parse & compile all rects
 	if (root.has_key("rects"))
 	if (root.has_key("rects"))
@@ -201,8 +198,6 @@ void compile(Filesystem& fs, const char* resource_path, File* out_file)
 	// Fill resource header
 	// Fill resource header
 	h.position[0] = m_gui_position[0];
 	h.position[0] = m_gui_position[0];
 	h.position[1] = m_gui_position[1];
 	h.position[1] = m_gui_position[1];
-	h.size[0] = m_gui_size[0];
-	h.size[1] = m_gui_size[1];
 	h.num_rects = m_gui_rects.size();
 	h.num_rects = m_gui_rects.size();
 	h.num_triangles = m_gui_triangles.size();
 	h.num_triangles = m_gui_triangles.size();
 	h.num_images = m_gui_images.size();
 	h.num_images = m_gui_images.size();

+ 0 - 12
engine/resource/GuiResource.h

@@ -51,7 +51,6 @@ const uint32_t GUI_RESOURCE_VERSION = 1;
 struct GuiHeader
 struct GuiHeader
 {
 {
 	uint32_t position[2];
 	uint32_t position[2];
-	uint32_t size[2];
 	uint32_t num_rects;
 	uint32_t num_rects;
 	uint32_t num_triangles;
 	uint32_t num_triangles;
 	uint32_t num_images;
 	uint32_t num_images;
@@ -129,17 +128,6 @@ struct GuiResource
 		return pos;
 		return pos;
 	}
 	}
 
 
-	//-----------------------------------------------------------------------------
-	Vector2 gui_size() const
-	{
-		Vector2 size;
-
-		size.x = ((GuiHeader*)this)->size[0];
-		size.y = ((GuiHeader*)this)->size[1];
-
-		return size;
-	}
-
 	//-----------------------------------------------------------------------------
 	//-----------------------------------------------------------------------------
 	uint32_t num_rects() const
 	uint32_t num_rects() const
 	{
 	{

+ 5 - 4
tools/CMakeLists.txt

@@ -4,7 +4,8 @@ project(crown-tools)
 
 
 configure_file (${CMAKE_CURRENT_SOURCE_DIR}/Config.h.in ${CMAKE_CURRENT_SOURCE_DIR}/Config.h)
 configure_file (${CMAKE_CURRENT_SOURCE_DIR}/Config.h.in ${CMAKE_CURRENT_SOURCE_DIR}/Config.h)
 
 
-add_subdirectory(gui/resource-browser)
-add_subdirectory(gui/toolchain)
-add_subdirectory(gui/console)
-add_subdirectory(pycrown)
+#add_subdirectory(gui/resource-browser)
+#add_subdirectory(gui/toolchain)
+#add_subdirectory(gui/console)
+#add_subdirectory(pycrown)
+add_subdirectory(gui/fontgen)

+ 12 - 4
tools/gui/fontgen/CMakeLists.txt

@@ -7,9 +7,17 @@ if (FREETYPE_FOUND)
 	link_libraries(${FREETYPE_LIBRARIES})
 	link_libraries(${FREETYPE_LIBRARIES})
 endif (FREETYPE_FOUND)
 endif (FREETYPE_FOUND)
 
 
-add_executable(fontgen main.cpp)
+set (FONTGEN_SRC
+	BinPacker.cpp
+	lodepng.cpp
+	stb_image.c
+)
 
 
-target_link_libraries(fontgen crown)
+set (FONTGEN_HEADERS
+	BinPacker.hpp
+	lodepng.h
+	stb_image.h
+)
 
 
-# fontgen compili with the following string
-#g++ -w -o fontgen main.cpp stb_image.c lodepng.cpp BinPacker.cpp -I/usr/include/freetype2 -L/usr/local/lib -lfreetype
+add_executable(crown-fontgen main.cpp ${FONTGEN_SRC} ${FONTGEN_HEADERS})
+install (TARGETS crown-fontgen DESTINATION bin)

+ 94 - 437
tools/gui/fontgen/main.cpp

@@ -2,6 +2,7 @@
 #include <ctime>
 #include <ctime>
 #include <cstdio>
 #include <cstdio>
 #include <vector>
 #include <vector>
+#include <cstdlib>
 
 
 #include <ft2build.h>
 #include <ft2build.h>
 #include FT_FREETYPE_H
 #include FT_FREETYPE_H
@@ -13,6 +14,10 @@
 
 
 using namespace std;
 using namespace std;
 
 
+static int font_size = 4;
+static char font_name[100];
+
+//-----------------------------------------------------------------------------
 struct sdf_glyph
 struct sdf_glyph
 {
 {
 	int ID;
 	int ID;
@@ -22,357 +27,136 @@ struct sdf_glyph
 	float xadv;
 	float xadv;
 };
 };
 
 
-bool render_signed_distance_font(
-		FT_Library &ft_lib,
-		const char* font_file,
-		int texture_size,
-		bool export_c_header );
-
-bool render_signed_distance_image(
-		const char* image_file,
-		int texture_size,
-		bool export_c_header );
+//-----------------------------------------------------------------------------
+bool render_signed_distance_font(FT_Library &ft_lib, const char* font_file, int texture_size, bool export_c_header);
+unsigned char get_SDF_radial(unsigned char *fontmap, int w, int h, int x, int y, int max_radius);
+bool gen_pack_list(FT_Face &ft_face, int pixel_size, int pack_tex_size, const std::vector<int> &render_list, std::vector<sdf_glyph> &packed_glyphs);
+int save_png_SDFont(const char* orig_filename, int img_width, int img_height, const std::vector<unsigned char> &img_data, const std::vector<sdf_glyph> &packed_glyphs);
 
 
-unsigned char get_SDF_radial(
-		unsigned char *fontmap,
-		int w, int h,
-		int x, int y,
-		int max_radius );
-
-bool gen_pack_list(
-		FT_Face &ft_face,
-		int pixel_size,
-		int pack_tex_size,
-		const std::vector< int > &render_list,
-		std::vector< sdf_glyph > &packed_glyphs );
-
-int save_png_SDFont(
-		const char* orig_filename,
-		const char* font_name,
-		int img_width, int img_height,
-		const std::vector< unsigned char > &img_data,
-		const std::vector< sdf_glyph > &packed_glyphs );
-
-int save_c_header_SDFont(
-		const char* orig_filename,
-		const char* font_name,
-		int img_width, int img_height,
-		const std::vector< unsigned char > &img_data,
-		const std::vector< sdf_glyph > &packed_glyphs );
-
-static int font_size = 4;
-
-//	number of rendered pixels per SDF pixel
+//	number of rendered pixels per SDF pixel (larger value means higher quality, up to a point)
 const int scaler = 16;
 const int scaler = 16;
-//	(larger value means higher quality, up to a point)
 
 
-int main( int argc, char **argv )
+//-----------------------------------------------------------------------------
+int main(int argc, char **argv)
 {
 {
-	printf( "Signed Distance Bitmap Font Tool\n" );
-	printf( "Jonathan \"lonesock\" Dummer\n" );
-	printf( "\n" );
-	if( argc < 2 )
+	printf( "Crown Font Generator\n\n" );
+	if(argc != 4)
 	{
 	{
-		printf( "Usage: ./fontgen <src> <dest> <dim>" );
-		// system( "pause" );
+		printf( "Usage: ./fontgen <src> <name> <texture_dim>" );
 		return -1;
 		return -1;
 	}
 	}
 
 
-	int texture_size = -1;	//	trigger a request
+	const char* src = argv[1];
+	const char* name = argv[2];
+	strncpy(font_name, name, strlen(name));
+	int texture_size = atoi(argv[3]);
+
 	bool export_c_header = false;
 	bool export_c_header = false;
 
 
-	if( texture_size < 64 )
-	{
-		printf( "Select the texture size you would like for the output image.\n" );
-		printf( "Your choice will be limited to the range 64 to 4096.\n" );
-		printf( "Using powers of 2 is a good idea (e.g. 256 or 512).\n" );
-		printf( "(note: negative values will also export a C header)\n\n" );
-		printf( "Please select the texture size: " );
-		scanf( "%i", &texture_size );
-		printf( "\n" );
-		if( texture_size < 0 )
-		{
-			texture_size = -texture_size;
-			export_c_header = true;
-		}
-	}
-	if( texture_size < 64 ) { texture_size = 64; }
-	if( texture_size > 4096 ) { texture_size = 4096; }
+	// Checks texture size
+	if (texture_size < 64) texture_size = 64;
+	if (texture_size > 4096) texture_size = 4096;
 
 
-	//	OK, try out FreeType2
 	FT_Library ft_lib;
 	FT_Library ft_lib;
 	int ft_err = FT_Init_FreeType( &ft_lib );
 	int ft_err = FT_Init_FreeType( &ft_lib );
 	if( ft_err )
 	if( ft_err )
 	{
 	{
 		printf( "Failed to initialize the FreeType library!\n" );
 		printf( "Failed to initialize the FreeType library!\n" );
-		// system( "pause" );
 		return -1;
 		return -1;
 	}
 	}
 
 
-	for( int font_input_idx = 1; font_input_idx < argc; ++font_input_idx )
-	{
-		//	this may be either an image, or a font file, try the image first
-		if( !render_signed_distance_image( argv[font_input_idx], texture_size, export_c_header ) )
-		{
-			//	didn't work, try the font
-			render_signed_distance_font( ft_lib, argv[font_input_idx], texture_size, export_c_header );
-		}
-	}
+	render_signed_distance_font(ft_lib, src, texture_size, export_c_header);
 
 
 	ft_err = FT_Done_FreeType( ft_lib );
 	ft_err = FT_Done_FreeType( ft_lib );
 
 
-	// system( "pause" );
     return 0;
     return 0;
 }
 }
 
 
-bool render_signed_distance_image(
-		const char* image_file,
-		int texture_size,
-		bool export_c_header )
-{
-	//	try to load this file as an image
-	int w, h, channels;
-	unsigned char *img = stbi_load( image_file, &w, &h, &channels, 0 );
-	if( !img )
-	{
-		return false;
-	}
-	//	image loaded
-	printf( "Loaded '%s', %i x %i, channels 0", image_file, w, h );
-	for( int i = 1; i < channels; ++i )
-	{
-		printf( ",%i", i );
-	}
-	printf( "\n" );
-	//	check for components and resizing issues
-	if( (w <= texture_size) && (h <= texture_size) )
-	{
-		printf( "The output texture size is larger than the input image dimensions!\n" );
-		stbi_image_free( img );
-		return false;
-	}
-	//	now, which channel do I use as the input function?
-	int chan = 0;
-	if( channels > 1 )
-	{
-		printf( "Which channel contains the input? " );
-		scanf( "%i", &chan );
-		if( chan < 0 )
-		{
-			chan = 0;
-		} else if( chan >= channels )
-		{
-			chan = channels - 1;
-		}
-	}
-	printf( "Using channel %i as the input\n", chan );
-	std::vector<unsigned char> img_data;
-	img_data.reserve( w*h );
-	for( int i = chan; i < w*h*channels; i += channels )
-	{
-		img_data.push_back( img[i] );
-	}
-	stbi_image_free( img );
-	//	is this channel strictly 2 values?
-	bool needs_threshold = false;
-	int vmax, vmin;
-	{
-		int val0 = img_data[0], val = -1;
-		vmin = img_data[0];
-		vmax = img_data[0];
-		for( int i = 0; i < w*h; ++i )
-		{
-			//	do I need a threshold?
-			if( img_data[i] != val0 )
-			{
-				if( val < 0 )
-				{
-					//	second value
-					val = img_data[i];
-				} else
-				{
-					needs_threshold = (val != img_data[i]);
-				}
-			}
-			//	find min and max, just in case
-			if( img_data[i] < vmin )
-			{
-				vmin = img_data[i];
-			}
-			if( img_data[i] > vmax )
-			{
-				vmax = img_data[i];
-			}
-		}
-	}
-	if( needs_threshold )
-	{
-		int thresh;
-		printf( "The image needs a threshold, between %i and %i (< threshold is 0): ", vmin, vmax );
-		scanf( "%i", &thresh );
-		if( thresh <= vmin )
-		{
-			thresh = vmin + 1;
-		} else if( thresh > vmax )
-		{
-			thresh = vmax;
-		}
-		printf( "using threshold=%i\n", thresh );
-		for( int i = 0; i < w*h; ++i )
-		{
-			if( img_data[i] < thresh )
-			{
-				img_data[i] = 0;
-			} else
-			{
-				img_data[i] = 255;
-			}
-		}
-	}
-
-	//	OK, I'm finally ready to perform the SDF analysis
-	int sw;
-	if( w > h )
-	{
-		sw = 2 * w / texture_size;
-	} else
-	{
-		sw = 2 * h / texture_size;
-	}
-	std::vector<unsigned char> pdata( 4 * texture_size * texture_size, 0 );
-	img = &(img_data[0]);
-	for( int j = 0; j < texture_size; ++j )
-	{
-		for( int i = 0; i < texture_size; ++i )
-		{
-			int sx = i * (w-1) / (texture_size-1);
-			int sy = j * (h-1) / (texture_size-1);
-			int pd_idx = (i+j*texture_size) * 4;
-			pdata[pd_idx] =
-				get_SDF_radial
-						( img, w, h,
-						sx, sy, sw );
-			pdata[pd_idx+1] = pdata[pd_idx];
-			pdata[pd_idx+2] = pdata[pd_idx];
-			pdata[pd_idx+3] = pdata[pd_idx];
-		}
-	}
-
-	//	save the image
-	int fn_size = strlen( image_file ) + 100;
-	char *fn = new char[ fn_size ];
-	#if 0
-	sprintf( fn, "%s_sdf.bmp", image_file );
-	stbi_write_bmp( fn, texture_size, texture_size, 4, &pdata[0] );
-	#endif
-	sprintf( fn, "%s_sdf.png", image_file );
-	printf( "'%s'\n", fn );
-	LodePNG::Encoder encoder;
-	encoder.addText("Comment", "Signed Distance Image: lonesock tools");
-	encoder.getSettings().zlibsettings.windowSize = 512; //	faster, not much worse compression
-	std::vector<unsigned char> buffer;
-	int tin = clock();
-	encoder.encode( buffer, pdata.empty() ? 0 : &pdata[0], texture_size, texture_size );
-	LodePNG::saveFile( buffer, fn );
-	tin = clock() - tin;
-
-	return true;
-}
-
-bool render_signed_distance_font(
-		FT_Library &ft_lib,
-		const char* font_file,
-		int texture_size,
-		bool export_c_header )
+//-----------------------------------------------------------------------------
+bool render_signed_distance_font(FT_Library &ft_lib, const char* font_file, int texture_size, bool export_c_header)
 {
 {
 	FT_Face ft_face;
 	FT_Face ft_face;
-	int ft_err = FT_New_Face( ft_lib, font_file, 0, &ft_face );
-	if( ft_err )
+	int ft_err = FT_New_Face(ft_lib, font_file, 0, &ft_face);
+	if(ft_err)
 	{
 	{
 		printf( "Failed to read the font file '%s'\n", font_file );
 		printf( "Failed to read the font file '%s'\n", font_file );
 		return false;
 		return false;
-	} else
+	}
+	else
 	{
 	{
-		printf( "Font to convert to a Signed Distance Field:\n%s\n\n", font_file );
-		int max_unicode_char= 0;
-		if( max_unicode_char < 1 )
-		{
-			printf( "Select the highest unicode character you wish to render.\n" );
-			printf( "Any characters without glyphs in the font will be skipped.\n" );
-			printf( "(Good values for ANSI text might be 128 or 255, while\n" );
-			printf( "a good value for Unicode text might be 65535.)\n\n" );
-			printf( "Please select the maximum character value: " );
-			scanf( "%i", &max_unicode_char );
-			printf( "\n" );
-		}
-		if( max_unicode_char < 1 ) { max_unicode_char = 1; }
-		//	Try all characters up to a user selected value (it will auto-skip any without glyphs)
+		printf("Font:%s\n", font_file);
+
+		int max_unicode_char= 65535;
 		std::vector< int > render_list;
 		std::vector< int > render_list;
-		for( int char_idx = 0; char_idx <= max_unicode_char; ++char_idx )
+		for (int char_idx = 0; char_idx <= max_unicode_char; ++char_idx)
 		{
 		{
-			render_list.push_back( char_idx );
+			render_list.push_back(char_idx);
 		}
 		}
 		//	find the perfect size
 		//	find the perfect size
-		printf( "\nDetermining ideal font pixel size: " );
+
 		std::vector< sdf_glyph > all_glyphs;
 		std::vector< sdf_glyph > all_glyphs;
 		//	initial guess for the size of the Signed Distance Field font
 		//	initial guess for the size of the Signed Distance Field font
 		//	(intentionally low, the first trial will be at font_size*2, so 8x8)
 		//	(intentionally low, the first trial will be at font_size*2, so 8x8)
 
 
 		bool keep_going = true;
 		bool keep_going = true;
-		while( keep_going )
+		while (keep_going)
 		{
 		{
 			font_size <<= 1;
 			font_size <<= 1;
-			printf( " %i", font_size );
-			keep_going = gen_pack_list( ft_face, font_size, texture_size, render_list, all_glyphs );
+			keep_going = gen_pack_list(ft_face, font_size, texture_size, render_list, all_glyphs);
 		}
 		}
+
 		int font_size_step = font_size >> 2;
 		int font_size_step = font_size >> 2;
-		while( font_size_step )
+		while (font_size_step)
 		{
 		{
-			if( keep_going )
+			if (keep_going)
 			{
 			{
 				font_size += font_size_step;
 				font_size += font_size_step;
-			} else
+			}
+			else
 			{
 			{
 				font_size -= font_size_step;
 				font_size -= font_size_step;
 			}
 			}
-			printf( " %i", font_size );
 			font_size_step >>= 1;
 			font_size_step >>= 1;
-			keep_going = gen_pack_list( ft_face, font_size, texture_size, render_list, all_glyphs );
+			keep_going = gen_pack_list(ft_face, font_size, texture_size, render_list, all_glyphs);
 		}
 		}
+
 		//	just in case
 		//	just in case
-		while( (!keep_going) && (font_size > 1) )
+		while((!keep_going) && (font_size > 1))
 		{
 		{
 			--font_size;
 			--font_size;
-			printf( " %i", font_size );
-			keep_going = gen_pack_list( ft_face, font_size, texture_size, render_list, all_glyphs );
+			keep_going = gen_pack_list(ft_face, font_size, texture_size, render_list, all_glyphs);
 		}
 		}
-		printf( "\nResult = %i pixels\n", font_size );
 
 
-		if( !keep_going )
+		printf("Font size = %i pixels\n\n", font_size);
+
+		if (!keep_going)
 		{
 		{
-			printf( "The data will not fit in a texture %i^2\n", texture_size );
-			// system( "pause" );
+			printf( "The data will not fit in a texture %i^2\n", texture_size);
 			return -1;
 			return -1;
 		}
 		}
 
 
 		//	set up the RAM for the final rendering/compositing
 		//	set up the RAM for the final rendering/compositing
 		//	(use all four channels, so PNG compression is simple)
 		//	(use all four channels, so PNG compression is simple)
-		std::vector<unsigned char> pdata( 4 * texture_size * texture_size, 0 );
+		std::vector<unsigned char> pdata(4 * texture_size * texture_size, 0);
 
 
 		//	render all the glyphs individually
 		//	render all the glyphs individually
-		printf( "\nRendering characters into a packed %i^2 image:\n", texture_size );
+		printf("Rendering into image... ");
+
 		int packed_glyph_index = 0;
 		int packed_glyph_index = 0;
+
 		int tin = clock();
 		int tin = clock();
-		for( unsigned int char_index = 0; char_index < render_list.size(); ++char_index )
+
+		for (unsigned int char_index = 0; char_index < render_list.size(); ++char_index)
 		{
 		{
-			int glyph_index = FT_Get_Char_Index( ft_face, render_list[char_index] );
-			if( glyph_index )
+			int glyph_index = FT_Get_Char_Index(ft_face, render_list[char_index]);
+
+			if (glyph_index)
 			{
 			{
-				ft_err = FT_Load_Glyph( ft_face, glyph_index, 0 );
-				if( !ft_err )
+				ft_err = FT_Load_Glyph(ft_face, glyph_index, 0);
+				if (!ft_err)
 				{
 				{
-					ft_err = FT_Render_Glyph( ft_face->glyph, FT_RENDER_MODE_MONO );
-					if( !ft_err )
+					ft_err = FT_Render_Glyph(ft_face->glyph, FT_RENDER_MODE_MONO);
+					if (!ft_err)
 					{
 					{
 						//	we have the glyph, already rendered, get the data about it
 						//	we have the glyph, already rendered, get the data about it
 						int w = ft_face->glyph->bitmap.width;
 						int w = ft_face->glyph->bitmap.width;
@@ -383,16 +167,16 @@ bool render_signed_distance_font(
 						int sw = w + scaler * 4;
 						int sw = w + scaler * 4;
 						int sh = h + scaler * 4;
 						int sh = h + scaler * 4;
 						unsigned char *smooth_buf = new unsigned char[sw*sh];
 						unsigned char *smooth_buf = new unsigned char[sw*sh];
-						for( int i = 0; i < sw*sh; ++i )
+						for (int i = 0; i < sw*sh; ++i)
 						{
 						{
 							smooth_buf[i] = 0;
 							smooth_buf[i] = 0;
 						}
 						}
 
 
 						//	copy the glyph into the buffer to be smoothed
 						//	copy the glyph into the buffer to be smoothed
 						unsigned char *buf = ft_face->glyph->bitmap.buffer;
 						unsigned char *buf = ft_face->glyph->bitmap.buffer;
-						for( int j = 0; j < h; ++j )
+						for (int j = 0; j < h; ++j)
 						{
 						{
-							for( int i = 0; i < w; ++i )
+							for (int i = 0; i < w; ++i)
 							{
 							{
 								smooth_buf[scaler*2+i+(j+scaler*2)*sw] = 255 * ((buf[j*p+(i>>3)] >> (7 - (i & 7))) & 1);
 								smooth_buf[scaler*2+i+(j+scaler*2)*sw] = 255 * ((buf[j*p+(i>>3)] >> (7 - (i & 7))) & 1);
 							}
 							}
@@ -402,17 +186,12 @@ bool render_signed_distance_font(
 						int sdfx = all_glyphs[packed_glyph_index].x;
 						int sdfx = all_glyphs[packed_glyph_index].x;
 						int sdfh = all_glyphs[packed_glyph_index].height;
 						int sdfh = all_glyphs[packed_glyph_index].height;
 						int sdfy = all_glyphs[packed_glyph_index].y;
 						int sdfy = all_glyphs[packed_glyph_index].y;
-						for( int j = 0; j < sdfh; ++j )
+						for (int j = 0; j < sdfh; ++j)
 						{
 						{
-							for( int i = 0; i < sdfw; ++i )
+							for (int i = 0; i < sdfw; ++i)
 							{
 							{
 								int pd_idx = (i+sdfx+(j+sdfy)*texture_size) * 4;
 								int pd_idx = (i+sdfx+(j+sdfy)*texture_size) * 4;
-								pdata[pd_idx] =
-									//get_SDF
-									get_SDF_radial
-											( smooth_buf, sw, sh,
-											i*scaler + (scaler >>1), j*scaler + (scaler >>1),
-											2*scaler );
+								pdata[pd_idx] = get_SDF_radial(smooth_buf, sw, sh, i*scaler + (scaler >>1), j*scaler + (scaler >>1), 2*scaler);
 								pdata[pd_idx+1] = pdata[pd_idx];
 								pdata[pd_idx+1] = pdata[pd_idx];
 								pdata[pd_idx+2] = pdata[pd_idx];
 								pdata[pd_idx+2] = pdata[pd_idx];
 								pdata[pd_idx+3] = pdata[pd_idx];
 								pdata[pd_idx+3] = pdata[pd_idx];
@@ -422,29 +201,17 @@ bool render_signed_distance_font(
 
 
 						delete [] smooth_buf;
 						delete [] smooth_buf;
 					}
 					}
-					printf( "%i ", render_list[char_index] );
+					//printf( "%i ", render_list[char_index] );
 				}
 				}
 			}
 			}
 		}
 		}
-		tin = clock() - tin;
-		printf( "\nRenderint took %1.3f seconds\n\n", 0.001f * tin );
 
 
-		printf( "\nCompressing the image to PNG\n" );
-		tin = save_png_SDFont(
-				font_file, ft_face->family_name,
-				texture_size, texture_size,
-				pdata, all_glyphs );
-		printf( "Done in %1.3f seconds\n\n", 0.001f * tin );
+		tin = clock() - tin;
+		printf("Done. %.3f seconds.\n", ((float)tin) / CLOCKS_PER_SEC);
 
 
-		if( export_c_header )
-		{
-			printf( "Saving the SDF data in a C header file\n" );
-			tin = save_c_header_SDFont(
-					font_file, ft_face->family_name,
-					texture_size, texture_size,
-					pdata, all_glyphs );
-			printf( "Done in %1.3f seconds\n\n", 0.001f * tin );
-		}
+		printf("Compressing to PNG... ");
+		tin = save_png_SDFont(font_file, texture_size, texture_size, pdata, all_glyphs);
+		printf("Done. %.3f seconds.\n", ((float)tin) / CLOCKS_PER_SEC);
 
 
 		//	clean up my data
 		//	clean up my data
 		all_glyphs.clear();
 		all_glyphs.clear();
@@ -452,33 +219,33 @@ bool render_signed_distance_font(
 
 
 		ft_err = FT_Done_Face( ft_face );
 		ft_err = FT_Done_Face( ft_face );
 	}
 	}
+
 	return true;
 	return true;
 }
 }
 
 
-int save_png_SDFont(
-		const char* orig_filename,
-		const char* font_name,
-		int img_width, int img_height,
-		const std::vector< unsigned char > &img_data,
-		const std::vector< sdf_glyph > &packed_glyphs )
+//-----------------------------------------------------------------------------
+int save_png_SDFont(const char* orig_filename, int img_width, int img_height, const std::vector<unsigned char> &img_data, const std::vector< sdf_glyph > &packed_glyphs)
 {
 {
 	//	save my image
 	//	save my image
-	int fn_size = strlen( orig_filename ) + 100;
-	char *fn = new char[ fn_size ];
-	sprintf( fn, "%s_sdf.png", orig_filename );
-	printf( "'%s'\n", fn );
+	string dest(orig_filename);
+	unsigned offs = dest.find(".ttf");
+	dest.replace(offs, 4, "");
+	dest += ".png";
+
 	LodePNG::Encoder encoder;
 	LodePNG::Encoder encoder;
-	encoder.addText("Comment", "Signed Distance Font: lonesock tools");
 	encoder.getSettings().zlibsettings.windowSize = 512; //	faster, not much worse compression
 	encoder.getSettings().zlibsettings.windowSize = 512; //	faster, not much worse compression
 	std::vector<unsigned char> buffer;
 	std::vector<unsigned char> buffer;
 	int tin = clock();
 	int tin = clock();
-	encoder.encode( buffer, img_data.empty() ? 0 : &img_data[0], img_width, img_height );
-	LodePNG::saveFile( buffer, fn );
+	encoder.encode(buffer, img_data.empty() ? 0 : &img_data[0], img_width, img_height);
+	LodePNG::saveFile(buffer, dest.c_str());
 	tin = clock() - tin;
 	tin = clock() - tin;
 
 
 	//	now save the acompanying info
 	//	now save the acompanying info
-	sprintf( fn, "%s.font", orig_filename );
-	FILE *fp = fopen( fn, "w" );
+	offs = dest.find(".png");
+	dest.replace(offs, 4, "");
+	dest += ".font";
+	FILE *fp = fopen(dest.c_str(), "w");
+
 	// EDITED by CROWN DEVELOPERS -- json output
 	// EDITED by CROWN DEVELOPERS -- json output
 	if( fp )
 	if( fp )
 	{
 	{
@@ -520,122 +287,11 @@ int save_png_SDFont(
 		fprintf(fp, "}");
 		fprintf(fp, "}");
 		fclose( fp );
 		fclose( fp );
 	}
 	}
-	delete [] fn;
-	return tin;
-}
-
-int save_c_header_SDFont(
-		const char* orig_filename,
-		const char* font_name,
-		int img_width, int img_height,
-		const std::vector< unsigned char > &img_data,
-		const std::vector< sdf_glyph > &packed_glyphs )
-{
-	//	save my image
-	int fn_size = strlen( orig_filename ) + strlen( font_name ) + 100;
-	char *fn = new char[ fn_size ];
-	int tin = clock();
-
-	//	now save the acompanying info
-	sprintf( fn, "%s_sdf.h", orig_filename );
-	FILE *fp = fopen( fn, "w" );
-	if( fp )
-	{
-		fprintf( fp, "/*\n" );
-		fprintf( fp, "    Jonathan \"lonesock\" Dummer\n" );
-		fprintf( fp, "    Signed Distance Font Tool\n" );
-		fprintf( fp, "\n" );
-		fprintf( fp, "    C header\n" );
-		fprintf( fp, "    font: \"%s\"\n", font_name );
-		fprintf( fp, "*/\n" );
-		fprintf( fp, "\n" );
-		fprintf( fp, "#ifndef HEADER_SIGNED_DISTANCE_FONT_XXX\n" );
-		fprintf( fp, "#define HEADER_SIGNED_DISTANCE_FONT_XXX\n" );
-		fprintf( fp, "\n" );
-		fprintf( fp, "/* array size information */\n" );
-		fprintf( fp, "const int sdf_tex_width = %i;\n", img_width );
-		fprintf( fp, "const int sdf_tex_height = %i;\n", img_height );
-		fprintf( fp, "const int sdf_num_chars = %i;\n", packed_glyphs.size() );
-		fprintf( fp, "/* 'unsigned char sdf_data[]' is defined last */\n" );
-		fprintf( fp, "\n" );
-
-		//	now give the glyph spacing info
-		fprintf( fp, "/*\n" );
-		fprintf( fp, "    The following array holds the spacing info for rendering.\n" );
-		fprintf( fp, "    Note that the final 3 values need sub-pixel accuracy, so\n" );
-		fprintf( fp, "    they are multiplied by a scaling factor.  Make sure to\n" );
-		fprintf( fp, "    divide by scale_factor before using the 'offset' and\n" );
-		fprintf( fp, "    'advance' values.\n" );
-		fprintf( fp, "\n" );
-		fprintf( fp, "    Here is the data order in the following array:\n" );
-		fprintf( fp, "    [0] Unicode character ID\n" );
-		fprintf( fp, "    [1] X position in this texture\n" );
-		fprintf( fp, "    [2] Y position in this texture\n" );
-		fprintf( fp, "    [3] Width of this glyph in the texture\n" );
-		fprintf( fp, "    [4] Height of this glyph in the texture\n" );
-		fprintf( fp, "    [5] X Offset * scale_factor  | Draw the glyph at X,Y offset\n" );
-		fprintf( fp, "    [6] Y Offset * scale_factor  | relative to the cursor, then\n" );
-		fprintf( fp, "    [7] X Advance * scale_factor | advance the cursor by this.\n" );
-		fprintf( fp, "*/\n" );
-		const float scale_factor = 1000.0;
-		fprintf( fp, "const float scale_factor = %f;\n", scale_factor );
-		fprintf( fp, "const int sdf_spacing[] = {\n" );
-		for( unsigned int i = 0; i < packed_glyphs.size(); ++i )
-		{
-			fprintf( fp, "  %i,%i,%i,%i,%i,",
-				packed_glyphs[i].ID,
-				packed_glyphs[i].x,
-				packed_glyphs[i].y,
-				packed_glyphs[i].width,
-				packed_glyphs[i].height
-				);
-			fprintf( fp, "%i,%i,%i,\n",
-				(int)(scale_factor * packed_glyphs[i].xoff),
-				(int)(scale_factor * packed_glyphs[i].yoff),
-				(int)(scale_factor * packed_glyphs[i].xadv)
-				);
-		}
-		fprintf( fp, "  0\n};\n\n" );
-
-		fprintf( fp, "/* Signed Distance Field: edges are at 127.5 */\n" );
-		fprintf( fp, "const unsigned char sdf_data[] = {" );
-		int nchars = 100000;
-		for( unsigned int i = 0; i < img_data.size(); i += 4 )
-		{
-			if( nchars > 70 )
-			{
-				fprintf( fp, "\n  " );
-				nchars = 2;
-			}
-			//	print the value
-			int v = img_data[i];
-			fprintf( fp, "%i,", v );
-			//	account for the comma
-			++nchars;
-			//	account for the number
-			if( v > 99 )
-			{
-				nchars += 3;
-			} else if( v > 9 )
-			{
-				nchars += 2;
-			} else
-			{
-				++nchars;
-			}
-		}
-		//	an ending value
-		fprintf( fp, "\n  255\n};\n\n" );
-
-		fprintf( fp, "#endif /* HEADER_SIGNED_DISTANCE_FONT_XXX */\n" );
-		fclose( fp );
-	}
-	delete [] fn;
-	tin = clock() - tin;
 
 
 	return tin;
 	return tin;
 }
 }
 
 
+//-----------------------------------------------------------------------------
 bool gen_pack_list(
 bool gen_pack_list(
 		FT_Face &ft_face,
 		FT_Face &ft_face,
 		int pixel_size,
 		int pixel_size,
@@ -714,6 +370,7 @@ bool gen_pack_list(
 	return false;
 	return false;
 }
 }
 
 
+//-----------------------------------------------------------------------------
 unsigned char get_SDF_radial(
 unsigned char get_SDF_radial(
 		unsigned char *fontmap,
 		unsigned char *fontmap,
 		int w, int h,
 		int w, int h,