From 98a27bd20b8440dfe6d221bc13443b76ec3a18cd Mon Sep 17 00:00:00 2001 From: Josh Holtrop Date: Mon, 23 Jun 2014 16:35:39 -0400 Subject: [PATCH] build glyph bitmap position into its VBO coordinates --- src/gui/Font.cc | 14 ++++++-------- src/gui/Font.h | 4 ---- 2 files changed, 6 insertions(+), 12 deletions(-) diff --git a/src/gui/Font.cc b/src/gui/Font.cc index 316e17d..5b4b207 100644 --- a/src/gui/Font.cc +++ b/src/gui/Font.cc @@ -73,8 +73,8 @@ namespace jes int width = face->glyph->bitmap.width; int height = face->glyph->bitmap.rows; - m_left = face->glyph->bitmap_left; - m_top = face->glyph->bitmap_top; + int left = face->glyph->bitmap_left; + int top = face->glyph->bitmap_top; m_advance = round_up_26_6(face->glyph->advance.x); uint8_t * texture = new uint8_t[width * height]; for (int i = 0; i < height; i++) @@ -95,15 +95,13 @@ namespace jes glTexImage2D(GL_TEXTURE_2D, 0, GL_ALPHA, width, height, 0, GL_ALPHA, GL_UNSIGNED_BYTE, texture); delete[] texture; - float w = width - 1; - float h = height - 1; float s = 1.0 / (width * 2); float t = 1.0 / (height * 2); GLfloat box[4][4] = { - {0, 0, s, t}, - {w, 0, 1 - s, t}, - {0, h, s, 1 - t}, - {w, h, 1 - s, 1 - t}, + {(GLfloat)left, (GLfloat)(top - height), s, t}, + {(GLfloat)(left + width - 1), (GLfloat)(top - height), 1 - s, t}, + {(GLfloat)left, (GLfloat)(top - 1), s, 1 - t}, + {(GLfloat)(left + width - 1), (GLfloat)(top - 1), 1 - s, 1 - t}, }; glGenBuffers(1, &m_vbo_id); glBindBuffer(GL_ARRAY_BUFFER, m_vbo_id); diff --git a/src/gui/Font.h b/src/gui/Font.h index 173a236..c0e9c81 100644 --- a/src/gui/Font.h +++ b/src/gui/Font.h @@ -18,8 +18,6 @@ namespace jes Glyph(); ~Glyph(); bool load(FT_Face face, FT_ULong char_code); - int get_top() { return m_top; } - int get_left() { return m_left; } int get_advance() { return m_advance; } void render() { @@ -31,8 +29,6 @@ namespace jes } protected: bool m_loaded; - int m_top; - int m_left; int m_advance; GLuint m_texture_id; GLuint m_vbo_id;