Resolution fixed and Centered text
This commit is contained in:
@@ -27,6 +27,7 @@ public:
|
||||
|
||||
FT_Face Face;
|
||||
|
||||
int FontSize = 16;
|
||||
|
||||
~Font();
|
||||
|
||||
|
||||
@@ -25,7 +25,7 @@ private:
|
||||
|
||||
GLuint VAO, VBO;
|
||||
|
||||
void RenderText(std::string text, Font* font, GLfloat scale, glm::vec4 color, glm::mat4 modelMatrix, glm::mat4 projectionMatrix, glm::mat4 viewMatrix);
|
||||
void RenderText(std::string text, Font* font, glm::vec4 color, glm::mat4 modelMatrix, glm::mat4 projectionMatrix, glm::mat4 viewMatrix);
|
||||
|
||||
ShaderProgram* m_TextProgram;
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
<?xml version="1.0" encoding="UTF-8" standalone="no" ?>
|
||||
<Text xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="Text.xsd">
|
||||
<Content>Text</Content>
|
||||
<Resource>Fonts/DroidSans.ttf</Resource>
|
||||
<Resource></Resource>
|
||||
<Color R="1" G="1" B="1" A="1"/>
|
||||
<Visible>true</Visible>
|
||||
</Text>
|
||||
@@ -13,28 +13,58 @@
|
||||
</c:Camera>
|
||||
<c:Model>
|
||||
<Resource>Models/Camera.obj</Resource>
|
||||
<Visible>false</Visible>
|
||||
</c:Model>
|
||||
<c:Transform>
|
||||
<Position X="0.624614298" Y="0.345819205" Z="5.40656805"/>
|
||||
<Orientation X="0.0523599274" Y="-0.104719244" Z="8.8963592e-09"/>
|
||||
<Position X="3.57542324" Y="3.61114573" Z="9.16725922"/>
|
||||
<Orientation X="-0.488691777" Y="0.575939536" Z="-3.55363916e-08"/>
|
||||
</c:Transform>
|
||||
</Components>
|
||||
<Children/>
|
||||
<Children>
|
||||
<Entity>
|
||||
<Components>
|
||||
<c:Text>
|
||||
<Content>Camera 1</Content>
|
||||
<Resource>Fonts/DroidSans.ttf,24</Resource>
|
||||
</c:Text>
|
||||
<c:Transform>
|
||||
<Position X="0.298732847" Y="0.296712071" Z="-1"/>
|
||||
<Scale X="0.100000001" Y="0.100000001" Z="0.100000001"/>
|
||||
</c:Transform>
|
||||
</Components>
|
||||
<Children/>
|
||||
</Entity>
|
||||
</Children>
|
||||
</Entity>
|
||||
<Entity>
|
||||
<Components>
|
||||
<c:Camera>
|
||||
<Name>ActionCamera</Name>
|
||||
</c:Camera>
|
||||
<c:Listener/>
|
||||
<c:Model>
|
||||
<Resource>Models/Camera.obj</Resource>
|
||||
<Visible>false</Visible>
|
||||
</c:Model>
|
||||
<c:Transform>
|
||||
<Position X="5" Y="1" Z="5"/>
|
||||
<Position X="7.20140934" Y="2.30552006" Z="8.67392826"/>
|
||||
<Orientation X="-0.296705663" Y="0.767948866" Z="2.27869563e-07"/>
|
||||
</c:Transform>
|
||||
</Components>
|
||||
<Children/>
|
||||
<Children>
|
||||
<Entity>
|
||||
<Components>
|
||||
<c:Text>
|
||||
<Content>Camera 2</Content>
|
||||
<Resource>Fonts/DroidSans.ttf,24</Resource>
|
||||
</c:Text>
|
||||
<c:Transform>
|
||||
<Position X="0.286911726" Y="0.310270816" Z="-1"/>
|
||||
<Scale X="0.100000001" Y="0.100000001" Z="0.100000001"/>
|
||||
</c:Transform>
|
||||
</Components>
|
||||
<Children/>
|
||||
</Entity>
|
||||
</Children>
|
||||
</Entity>
|
||||
<Entity>
|
||||
<Components>
|
||||
@@ -42,7 +72,7 @@
|
||||
<Resource>Models/Core/UnitPlane.obj</Resource>
|
||||
</c:Model>
|
||||
<c:Transform>
|
||||
<Position X="0" Y="-1" Z="0"/>
|
||||
<Position X="0" Y="-1" Z="0.600000024"/>
|
||||
<Scale X="100" Y="1" Z="100"/>
|
||||
</c:Transform>
|
||||
</Components>
|
||||
@@ -60,10 +90,12 @@
|
||||
<Entity>
|
||||
<Components>
|
||||
<c:Text>
|
||||
<Content>asdasdasdasdasd</Content>
|
||||
<Resource>Fonts/DroidSans.ttf</Resource>
|
||||
<Content>Welcome!</Content>
|
||||
<Resource>Fonts/DroidSans.ttf,64</Resource>
|
||||
</c:Text>
|
||||
<c:Transform/>
|
||||
<c:Transform>
|
||||
<Position X="0" Y="0" Z="0.700000048"/>
|
||||
</c:Transform>
|
||||
</Components>
|
||||
<Children/>
|
||||
</Entity>
|
||||
|
||||
@@ -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