Performance

54 views
Skip to first unread message

SoftCoder

unread,
Nov 18, 2011, 1:38:39 AM11/18/11
to freetype-gl
Hello there, I'm a developer of the open source game megaglest (see
megaglest.org) and while working with ftgl to support better fonts i
decided to try this code. It works fine in linux but after making some
changes to compile and run under windows (using vc++ 2008) I am having
troubles. It gets an access violation when uploading to the texture
atlas. But aside from that, I was wondering why my fps were lower
using this code than using ftgl's texture font? I was expecting this
code to perform better?

Thanks

SoftCoder

unread,
Nov 18, 2011, 4:01:55 AM11/18/11
to freetype-gl
Ok got it working nicely in windows as well! Now I just need to figure
out hoe to squeeze the best performance, any comments would be
appreciated:

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 Rougier

unread,
Nov 19, 2011, 10:54:12 AM11/19/11
to freet...@googlegroups.com
You're recreating the vertex buffer each time you render it. If your
text does not change, this is not necessary.
You can see the difference by running the demo-benchmark in the source tree.


Nicolas

Reply all
Reply to author
Forward
0 new messages