Resolution fixed and Centered text
This commit is contained in:
@@ -7,7 +7,6 @@ Font::Font(std::string path)
|
||||
boost::char_separator<char> sep(",");
|
||||
tokenizer tok(path, sep);
|
||||
|
||||
int fontSize = 16;
|
||||
|
||||
tokenizer::iterator it = tok.begin();
|
||||
std::string filePath = "";
|
||||
@@ -17,7 +16,7 @@ Font::Font(std::string path)
|
||||
it++;
|
||||
if (it != tok.end()) {
|
||||
try {
|
||||
fontSize = boost::lexical_cast<int>((*it).c_str());
|
||||
FontSize = boost::lexical_cast<int>((*it).c_str());
|
||||
} catch (boost::bad_lexical_cast const&) {
|
||||
LOG_ERROR("input string did not have a valid font resolution");
|
||||
}
|
||||
@@ -39,8 +38,8 @@ Font::Font(std::string path)
|
||||
return;
|
||||
}
|
||||
|
||||
FT_Set_Char_Size(Face, 0, fontSize*64, 300, 300); // temp
|
||||
FT_Set_Pixel_Sizes(Face, 0, fontSize); //
|
||||
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)) {
|
||||
LOG_ERROR("FreeType error: loading char");
|
||||
@@ -88,14 +87,13 @@ Font::Font(std::string path)
|
||||
|
||||
m_Characters.insert(std::pair<GLchar, Character>(c, character));
|
||||
}
|
||||
|
||||
FT_Done_Face(Face);
|
||||
FT_Done_FreeType(library);
|
||||
GLERROR("Font Load");
|
||||
}
|
||||
|
||||
Font::~Font()
|
||||
{
|
||||
FT_Done_Face(Face);
|
||||
for (auto c : m_Characters) {
|
||||
glDeleteTextures(1, &c.second.TextureID);
|
||||
}
|
||||
|
||||
@@ -74,9 +74,9 @@ void PickingPass::Draw(RenderScene& scene)
|
||||
m_EntityColors[std::make_tuple(pickInfo.Entity, pickInfo.World, pickInfo.Camera)] = glm::ivec2(pickColor[0], pickColor[1]);
|
||||
if (m_ColorCounter[0] > 255) {
|
||||
m_ColorCounter[0] = 0;
|
||||
m_ColorCounter[1]++;;
|
||||
m_ColorCounter[1]++;
|
||||
} else {
|
||||
m_ColorCounter[0]++;;
|
||||
m_ColorCounter[0]++;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -8,6 +8,7 @@ PickingPassState::PickingPassState(GLuint frameBuffer)
|
||||
GLERROR("---3");
|
||||
Enable(GL_DEPTH_TEST);
|
||||
Enable(GL_CULL_FACE);
|
||||
Disable(GL_BLEND);
|
||||
|
||||
glm::vec4 clearColor = glm::vec4(0.f);
|
||||
//ClearColor(clearColor);
|
||||
|
||||
@@ -117,6 +117,7 @@ void Renderer::Draw(RenderFrame& frame)
|
||||
m_TextRenderer->Draw(*scene);
|
||||
|
||||
}
|
||||
|
||||
|
||||
m_ImGuiRenderPass->Draw();
|
||||
glfwSwapBuffers(m_Window);
|
||||
|
||||
@@ -34,21 +34,39 @@ void TextRenderer::Draw(RenderScene& scene)
|
||||
for (auto &job : scene.TextJobs) {
|
||||
auto textJob = std::dynamic_pointer_cast<TextJob>(job);
|
||||
if (textJob) {
|
||||
RenderText(textJob->Content, textJob->Resource, 0.01f, textJob->Color, textJob->Matrix, scene.Camera->ProjectionMatrix(), scene.Camera->ViewMatrix());
|
||||
RenderText(textJob->Content, textJob->Resource, textJob->Color, textJob->Matrix, scene.Camera->ProjectionMatrix(), scene.Camera->ViewMatrix());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void TextRenderer::RenderText(std::string text, Font* font, GLfloat scale, glm::vec4 color, glm::mat4 modelMatrix, glm::mat4 projectionMatrix, glm::mat4 viewMatrix)
|
||||
void TextRenderer::RenderText(std::string text, Font* font, glm::vec4 color, glm::mat4 modelMatrix, glm::mat4 projectionMatrix, glm::mat4 viewMatrix)
|
||||
{
|
||||
GLfloat x = 0;
|
||||
GLfloat y = 0;
|
||||
GLfloat penX = 0;
|
||||
GLfloat penY = 0;
|
||||
float scale = 1.0/font->FontSize;
|
||||
|
||||
|
||||
FT_Bool use_kerning = FT_HAS_KERNING(font->Face);
|
||||
FT_UInt previous = 0;
|
||||
FT_UInt num_glyphs = 0;
|
||||
FT_UInt glyph_index;
|
||||
|
||||
FT_Vector pos[128];
|
||||
|
||||
GLfloat stringWidth = 0.f;
|
||||
|
||||
for (std::string::const_iterator c = text.begin(); c != text.end(); c++) {
|
||||
Font::Character ch = font->m_Characters[*c];
|
||||
stringWidth += (ch.Advance >> 6) * scale;
|
||||
}
|
||||
|
||||
penX = -stringWidth/2.f;
|
||||
|
||||
// Activate corresponding render state
|
||||
|
||||
glEnable(GL_BLEND);
|
||||
glDisable(GL_CULL_FACE);
|
||||
glEnable(GL_DEPTH_TEST);
|
||||
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
||||
|
||||
m_TextProgram->Bind();
|
||||
@@ -59,13 +77,12 @@ void TextRenderer::RenderText(std::string text, Font* font, GLfloat scale, glm::
|
||||
glActiveTexture(GL_TEXTURE0);
|
||||
glBindVertexArray(VAO);
|
||||
|
||||
// Iterate through all characters
|
||||
std::string::const_iterator c;
|
||||
for (c = text.begin(); c != text.end(); c++) {
|
||||
|
||||
for (std::string::const_iterator c = text.begin(); c != text.end(); c++) {
|
||||
Font::Character ch = font->m_Characters[*c];
|
||||
|
||||
GLfloat xpos = x + ch.Bearing.x * scale;
|
||||
GLfloat ypos = y - (ch.Size.y - ch.Bearing.y) * scale;
|
||||
GLfloat xpos = penX + ch.Bearing.x * scale;
|
||||
GLfloat ypos = penY - (ch.Size.y - ch.Bearing.y) * scale;
|
||||
|
||||
GLfloat w = ch.Size.x * scale;
|
||||
GLfloat h = ch.Size.y * scale;
|
||||
@@ -89,7 +106,7 @@ void TextRenderer::RenderText(std::string text, Font* font, GLfloat scale, glm::
|
||||
// Render quad
|
||||
glDrawArrays(GL_TRIANGLES, 0, 6);
|
||||
// Now advance cursors for next glyph (note that advance is number of 1/64 pixels)
|
||||
x += (ch.Advance >> 6) * scale; // Bitshift by 6 to get value in pixels (2^6 = 64)
|
||||
penX += (ch.Advance >> 6) * scale; // Bitshift by 6 to get value in pixels (2^6 = 64)
|
||||
}
|
||||
glBindVertexArray(0);
|
||||
glBindTexture(GL_TEXTURE_2D, 0);
|
||||
|
||||
Reference in New Issue
Block a user