65
65
FT_Face ftface = set->getFTFace();
67
if(FT_Load_Glyph( ftface, FT_Get_Char_Index( ftface, chr ), FT_LOAD_DEFAULT ))
67
FT_UInt index = FT_Get_Char_Index( ftface, chr );
69
//debugLog("FXGlyph %x %d %d", chr, chr, index);
71
if(FT_Load_Glyph( ftface, index, FT_LOAD_DEFAULT ))
68
72
throw FXFontException(ftface->family_name);
77
81
glyph_bitmap = (FT_BitmapGlyph)ftglyph;
79
dims = vec2f( glyph_bitmap->bitmap.width, glyph_bitmap->bitmap.rows) + vec2f(2.0f, 2.0f);
80
corner = vec2f( glyph_bitmap->left, -glyph_bitmap->top) + vec2f(0.5, -0.5);
81
advance = vec2f( ftface->glyph->advance.x >> 6, ftface->glyph->advance.y >> 6);
83
dims = vec2( glyph_bitmap->bitmap.width, glyph_bitmap->bitmap.rows) + vec2(2.0f, 2.0f);
84
corner = vec2( glyph_bitmap->left, -glyph_bitmap->top) + vec2(0.5, -0.5);
85
advance = vec2( ftface->glyph->advance.x >> 6, ftface->glyph->advance.y >> 6);
83
vertex_positions[0] = vec2f(0.0f, 0.0f);
84
vertex_positions[1] = vec2f(dims.x, 0.0f);
87
vertex_positions[0] = vec2(0.0f, 0.0f);
88
vertex_positions[1] = vec2(dims.x, 0.0f);
85
89
vertex_positions[2] = dims;
86
vertex_positions[3] = vec2f(0.0f, dims.y);
90
vertex_positions[3] = vec2(0.0f, dims.y);
92
void FXGlyph::setPage(FXGlyphPage* page, const vec4f& texcoords) {
96
void FXGlyph::setPage(FXGlyphPage* page, const vec4& texcoords) {
94
98
this->texcoords = texcoords;
96
vertex_texcoords[0] = vec2f(texcoords.x, texcoords.y);
97
vertex_texcoords[1] = vec2f(texcoords.z, texcoords.y);
98
vertex_texcoords[2] = vec2f(texcoords.z, texcoords.w);
99
vertex_texcoords[3] = vec2f(texcoords.x, texcoords.w);
102
void FXGlyph::drawToVBO(quadbuf& buffer, const vec2f& pos, const vec4f& colour) const {
103
buffer.add(page->textureid, pos + corner, dims, colour, texcoords);
106
void FXGlyph::draw(const vec2f& pos) const {
100
vertex_texcoords[0] = vec2(texcoords.x, texcoords.y);
101
vertex_texcoords[1] = vec2(texcoords.z, texcoords.y);
102
vertex_texcoords[2] = vec2(texcoords.z, texcoords.w);
103
vertex_texcoords[3] = vec2(texcoords.x, texcoords.w);
106
void FXGlyph::drawToVBO(quadbuf& buffer, const vec2& pos, const vec4& colour) const {
107
buffer.add(page->texture->textureid, pos + corner, dims, colour, texcoords);
110
void FXGlyph::draw(const vec2& pos) const {
107
111
for(int i=0;i<4;i++) {
108
glTexCoord2fv(vertex_texcoords[i]);
109
glVertex2fv(vertex_positions[i] + pos + corner);
112
vec2 pos_offset = vertex_positions[i] + pos + corner;
114
glTexCoord2fv(glm::value_ptr(vertex_texcoords[i]));
115
glVertex2fv(glm::value_ptr(pos_offset));
163
169
//fprintf(stderr, "corner_x = %d, corner_y = %d\n", corner_x, corner_y);
165
vec4f texcoords = vec4f( (((float)corner_x)-0.5f) / (float) page_width,
171
vec4 texcoords = vec4( (((float)corner_x)-0.5f) / (float) page_width,
166
172
(((float)corner_y)-0.5f) / (float) page_height,
167
173
(((float)corner_x+bitmap->bitmap.width)+1.5f) / (float) page_width,
168
174
(((float)corner_y+bitmap->bitmap.rows)+1.5f) / (float) page_height );
181
187
void FXGlyphPage::updateTexture() {
182
188
if(!needs_update) return;
184
glBindTexture( GL_TEXTURE_2D, textureid);
186
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
187
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
188
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
189
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
191
glTexImage2D( GL_TEXTURE_2D, 0, GL_ALPHA, page_width, page_height, 0, GL_ALPHA, GL_UNSIGNED_BYTE, texture_data );
191
texture = texturemanager.create(page_width, page_height, false, GL_CLAMP_TO_EDGE, GL_ALPHA, texture_data);
193
196
needs_update = false;
356
360
if(textureid != -1) glEnd();
363
void FXGlyphSet::drawPages() {
364
vec2 corner = vec2(0.0f);
368
for(std::vector<FXGlyphPage*>::iterator it = pages.begin(); it != pages.end(); it++) {
369
FXGlyphPage* page = *it;
370
page->texture->bind();
373
glTexCoord2f(0.0f, 0.0f);
374
glVertex2f(0.0f, 0.0f);
376
glTexCoord2f(1.0f, 0.0f);
377
glVertex2f(page->texture->w, 0.0f);
379
glTexCoord2f(1.0f, 1.0f);
380
glVertex2f(page->texture->w, page->texture->h);
382
glTexCoord2f(0.0f, 1.0f);
383
glVertex2f(0.0f, page->texture->h);
386
glTranslatef(page->texture->w, 0.0f, 0.0f);
361
394
FXFont::FXFont() {
370
403
void FXFont::init() {
372
405
shadow_strength = 0.7;
373
shadow_offset = vec2f(1.0, 1.0);
406
shadow_offset = vec2(1.0, 1.0);
375
408
align_right = false;
376
409
align_top = true;
378
colour = vec4f(1.0f, 1.0f, 1.0f, 1.0f);
379
shadow_colour = vec4f(0.0f, 0.0f, 0.0f, shadow_strength);
411
colour = vec4(1.0f, 1.0f, 1.0f, 1.0f);
412
shadow_colour = vec4(0.0f, 0.0f, 0.0f, shadow_strength);
382
415
void FXFont::roundCoordinates(bool round) {
434
467
return glyphset->getWidth(text);
437
void FXFont::render(float x, float y, const std::string& text, const vec4f& colour) const{
470
void FXFont::render(float x, float y, const std::string& text, const vec4& colour) const{
439
472
if(fontmanager.use_vbo) {
440
vec2f cursor_start(x,y);
473
vec2 cursor_start(x,y);
441
474
glyphset->drawToVBO(cursor_start, text, colour);
478
glColor4fv(glm::value_ptr(colour));