From 92553f1e932dfc211bb7540d6ab4de775fdc38f4 Mon Sep 17 00:00:00 2001 From: viktorljung Date: Mon, 18 Jan 2016 17:17:12 +0100 Subject: [PATCH] text size can now be entered in the filepath with a comma separator, like this "filepath,16" --- include/Engine/Rendering/Font.h | 7 ++ include/Engine/Rendering/TextRenderer.h | 1 + resources/Schema/Entities/RenderingWorld.xml | 126 ++++++++++--------- src/Engine/Rendering/Font.cpp | 52 ++++++-- src/Engine/Rendering/PickingPass.cpp | 2 - 5 files changed, 118 insertions(+), 70 deletions(-) diff --git a/include/Engine/Rendering/Font.h b/include/Engine/Rendering/Font.h index 03f15a49..08341c1e 100644 --- a/include/Engine/Rendering/Font.h +++ b/include/Engine/Rendering/Font.h @@ -3,6 +3,9 @@ #include #include FT_FREETYPE_H +#include FT_GLYPH_H +#include +#include #include "../OpenGL.h" #include "../GLM.h" @@ -21,6 +24,10 @@ public: glm::ivec2 Bearing; // Offset from baseline to left/top of glyph GLuint Advance; // Offset to advance to next glyph }; + + FT_Face Face; + + ~Font(); std::map m_Characters; diff --git a/include/Engine/Rendering/TextRenderer.h b/include/Engine/Rendering/TextRenderer.h index 2e127e66..a755fd30 100644 --- a/include/Engine/Rendering/TextRenderer.h +++ b/include/Engine/Rendering/TextRenderer.h @@ -3,6 +3,7 @@ #include #include FT_FREETYPE_H +#include FT_GLYPH_H #include "../OpenGL.h" #include "../GLM.h" diff --git a/resources/Schema/Entities/RenderingWorld.xml b/resources/Schema/Entities/RenderingWorld.xml index 86a3090a..73c0e474 100644 --- a/resources/Schema/Entities/RenderingWorld.xml +++ b/resources/Schema/Entities/RenderingWorld.xml @@ -1,58 +1,72 @@ - + + - - - - - - - - - - - - - Models/Camera.obj - - - MainCamera - - - - - - - - - - Models/Camera.obj - - - ActionCamera - - - - - - - - - - - Models/Core/UnitPlane.obj - - - - - - - - - - An error - - - - - \ No newline at end of file + + + + + + + + MainCamera + + + Models/Camera.obj + false + + + + + + + + + + + + ActionCamera + + + Models/Camera.obj + + + + + + + + + + + Models/Core/UnitPlane.obj + + + + + + + + + + + + An error + + + + + + + + + asdasdasdasdasd + Fonts/DroidSans.ttf + + + + + + + + diff --git a/src/Engine/Rendering/Font.cpp b/src/Engine/Rendering/Font.cpp index cf5cd691..f62205e3 100644 --- a/src/Engine/Rendering/Font.cpp +++ b/src/Engine/Rendering/Font.cpp @@ -3,22 +3,48 @@ Font::Font(std::string path) { + typedef boost::tokenizer> tokenizer; + boost::char_separator sep(","); + tokenizer tok(path, sep); + + int fontSize = 16; + + tokenizer::iterator it = tok.begin(); + std::string filePath = ""; + + if (it != tok.end()) { + filePath = (*it).c_str(); + it++; + if (it != tok.end()) { + try { + LOG_INFO("DFhdoölshöldsihjgf"); + fontSize = boost::lexical_cast((*it).c_str()); + } catch (boost::bad_lexical_cast const&) { + std::cout << "Error: input string was not valid" << std::endl; + } + } + } else { + return; + } + + + FT_Library library; - FT_Face face; if (FT_Init_FreeType(&library)) { LOG_ERROR("FreeType error: init failed"); return; } - if (FT_New_Face(library, path.c_str(), 0, &face)) { + if (FT_New_Face(library, filePath.c_str(), 0, &Face)) { LOG_ERROR("FreeType error: loading font"); return; } - FT_Set_Pixel_Sizes(face, 0, 48); + FT_Set_Char_Size(Face, 0, fontSize*64, 300, 300); // temp + FT_Set_Pixel_Sizes(Face, 0, fontSize); // - if (FT_Load_Char(face, 'X', FT_LOAD_RENDER)) { + if (FT_Load_Char(Face, 'X', FT_LOAD_RENDER)) { LOG_ERROR("FreeType error: loading char"); return; } @@ -26,8 +52,10 @@ Font::Font(std::string path) glPixelStorei(GL_UNPACK_ALIGNMENT, 1); for (GLubyte c = 0; c < 128; c++) { + + //Load character glyph - if (FT_Load_Char(face, c, FT_LOAD_RENDER)) { + if (FT_Load_Char(Face, c, FT_LOAD_RENDER)) { continue; } @@ -40,12 +68,12 @@ Font::Font(std::string path) GL_TEXTURE_2D, 0, GL_RED, - face->glyph->bitmap.width, - face->glyph->bitmap.rows, + Face->glyph->bitmap.width, + Face->glyph->bitmap.rows, 0, GL_RED, GL_UNSIGNED_BYTE, - face->glyph->bitmap.buffer + Face->glyph->bitmap.buffer ); // Set texture options glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); @@ -55,15 +83,15 @@ Font::Font(std::string path) // Now store character for later use Character character = { texture, - glm::ivec2(face->glyph->bitmap.width, face->glyph->bitmap.rows), - glm::ivec2(face->glyph->bitmap_left, face->glyph->bitmap_top), - face->glyph->advance.x + glm::ivec2(Face->glyph->bitmap.width, Face->glyph->bitmap.rows), + glm::ivec2(Face->glyph->bitmap_left, Face->glyph->bitmap_top), + Face->glyph->advance.x }; m_Characters.insert(std::pair(c, character)); } - FT_Done_Face(face); + FT_Done_Face(Face); FT_Done_FreeType(library); GLERROR("Font Load"); } diff --git a/src/Engine/Rendering/PickingPass.cpp b/src/Engine/Rendering/PickingPass.cpp index 6800df1d..7470f029 100644 --- a/src/Engine/Rendering/PickingPass.cpp +++ b/src/Engine/Rendering/PickingPass.cpp @@ -46,10 +46,8 @@ void PickingPass::InitializeShaderPrograms() void PickingPass::Draw(RenderScene& scene) { PickingPassState* state = new PickingPassState(m_PickingBuffer.GetHandle()); - //TODO: Render: Add code for more jobs than modeljobs. - GLuint ShaderHandle = m_PickingProgram->GetHandle(); m_PickingProgram->Bind();