Get mesh from ofDrawBitmapString?

I’ve noticed it’s a bit time-consuming to call ofDrawBitmapStringHighlight on every render to draw some text on screen. I was wondering if I could just pre-create the text label somehow and store it.


You could always draw text to an fbo and then just draw that.


in 0.8.4 you could do this through some global functions just look into ofBitmapFont.h to figure out the right calls in 0.9 you can do soimething like:

ofBitmapFont font;
ofVboMesh textMesh;

textMesh = font.getMesh(somestring, x, y);
textMesh.append(font.getMesh(moretext, x, y+10);

// draw

if you are using the programmable renderer you’ll need a specific shader that discards everything with alpha < 0.5. also you can do the same with any ttf font through ofTrueTypeFont

Sweet, thanks to both!

What would be better in any case? To have an fbo or to have a mesh in GPU memory? I know this is a pretty low level optimization… but still what’s better memory or performance-wise?

I don’t think ithere’s much difference in terms of performace, the second might be slightly more flexible if you want to draw lots of texts in different positions, instead of allocating a really big transparent texture to draw to it through an fbo you just create all the geometry for every text in an ofVboMesh.