build glyph bitmap position into its VBO coordinates

This commit is contained in:
Josh Holtrop 2014-06-23 16:35:39 -04:00
parent f75cd9d4ad
commit 98a27bd20b
2 changed files with 6 additions and 12 deletions

View File

@ -73,8 +73,8 @@ namespace jes
int width = face->glyph->bitmap.width; int width = face->glyph->bitmap.width;
int height = face->glyph->bitmap.rows; int height = face->glyph->bitmap.rows;
m_left = face->glyph->bitmap_left; int left = face->glyph->bitmap_left;
m_top = face->glyph->bitmap_top; int top = face->glyph->bitmap_top;
m_advance = round_up_26_6(face->glyph->advance.x); m_advance = round_up_26_6(face->glyph->advance.x);
uint8_t * texture = new uint8_t[width * height]; uint8_t * texture = new uint8_t[width * height];
for (int i = 0; i < height; i++) 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); glTexImage2D(GL_TEXTURE_2D, 0, GL_ALPHA, width, height, 0, GL_ALPHA, GL_UNSIGNED_BYTE, texture);
delete[] texture; delete[] texture;
float w = width - 1;
float h = height - 1;
float s = 1.0 / (width * 2); float s = 1.0 / (width * 2);
float t = 1.0 / (height * 2); float t = 1.0 / (height * 2);
GLfloat box[4][4] = { GLfloat box[4][4] = {
{0, 0, s, t}, {(GLfloat)left, (GLfloat)(top - height), s, t},
{w, 0, 1 - s, t}, {(GLfloat)(left + width - 1), (GLfloat)(top - height), 1 - s, t},
{0, h, s, 1 - t}, {(GLfloat)left, (GLfloat)(top - 1), s, 1 - t},
{w, h, 1 - s, 1 - t}, {(GLfloat)(left + width - 1), (GLfloat)(top - 1), 1 - s, 1 - t},
}; };
glGenBuffers(1, &m_vbo_id); glGenBuffers(1, &m_vbo_id);
glBindBuffer(GL_ARRAY_BUFFER, m_vbo_id); glBindBuffer(GL_ARRAY_BUFFER, m_vbo_id);

View File

@ -18,8 +18,6 @@ namespace jes
Glyph(); Glyph();
~Glyph(); ~Glyph();
bool load(FT_Face face, FT_ULong char_code); 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; } int get_advance() { return m_advance; }
void render() void render()
{ {
@ -31,8 +29,6 @@ namespace jes
} }
protected: protected:
bool m_loaded; bool m_loaded;
int m_top;
int m_left;
int m_advance; int m_advance;
GLuint m_texture_id; GLuint m_texture_id;
GLuint m_vbo_id; GLuint m_vbo_id;