Thanks
Setup:
const wchar_t *cache = L" !\"#$%&'()*+,-./0123456789:;<=>?
@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~";
this->manager = font_manager_new( 512, 512, 1 );
this->atlas = texture_atlas_new( 512, 512, 1 );
this->buffer = vertex_buffer_new( "v3f:t2f:c4f" );
//font = texture_font_new( atlas, "Verdana", minsize );
this->font = texture_font_new( atlas, fontFile,
(float)fontFaceSize );
//font = texture_font_new( atlas, font_manager_match_description( 0,
"Verdana", minsize, bold, italic ), minsize );
int missed = texture_font_cache_glyphs( font, cache );
Each time I render:
void TextFreetypeGL::Render(const char* str, const int len) {
if(str == NULL) {
return;
}
Pen pen ;
pen.x = 0; pen.y = 0;
vertex_buffer_clear( this->buffer );
float currentColor[4] = { 0,0,0,1 };
glGetFloatv(GL_CURRENT_COLOR,currentColor);
Markup markup = { 0, (float)this->fontFaceSize, 0, 0, 0.0, 0.0,
{currentColor[0],currentColor[1],currentColor[2],currentColor[3]},
{0,0,0,0},
0, {0,0,0,1}, 0, {0,0,0,1},
0, {0,0,0,1}, 0, {0,0,0,1}, 0 };
// Add glyph one by one to the vertex buffer
// Expand totalBox by each glyph in string
// for multibyte - we can't rely on sizeof(T) == character
FreetypeGLUnicodeStringItr<unsigned char> ustr((const unsigned char
*)str);
for(int i = 0; (len < 0 && *ustr) || (len >= 0 && i < len); i++) {
unsigned int prevChar = (i > 0 ? *ustr-1 : 0);
unsigned int thisChar = *ustr++;
unsigned int nextChar = *ustr;
// Get glyph (build it if needed
TextureGlyph *glyph = texture_font_get_glyph( this->font,
thisChar );
// Take kerning into account if necessary
float kx = texture_glyph_get_kerning( glyph, prevChar );
// Add glyph to the vertex buffer
texture_glyph_add_to_vertex_buffer( glyph, this->buffer, &markup,
&pen, (int)kx );
}
//glBindTexture( GL_TEXTURE_2D, manager->atlas->texid );
glBindTexture( GL_TEXTURE_2D, this->atlas->texid );
glEnable( GL_BLEND );
glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA );
glEnable( GL_TEXTURE_2D );
vertex_buffer_render( this->buffer, GL_TRIANGLES, "vtc" );
glDisable( GL_TEXTURE_2D );
glDisable( GL_BLEND );
glBindTexture(GL_TEXTURE_2D, 0);
Nicolas