Oftruetypefont issue

I typically load the font (verdana for ex) in setup() but later on in draw() after I have projected forward with oftranslate (0,0, 500), the font is completely blown up (rightly so I guess). I think what’s happening with a declaration like

font.loadFont(“type/verdana.ttf”, 5, true, true, true, .4, 372);

it’s always size 5 for the initial plane (wherever along z that is). Once I translate forward, it just projects each of those pixels and so loses a lot of density. How do I fix this issue? I’ve played around with the other parameters no luck. I’ve tried bind() but didn’t get what I was looking for. Thanks.

@nuvella

Yeah, it looks like there’s a texture that gets loaded (when you call loadFont) behind the scenes that contains all your verdana size 5 characters. 5 point font is pretty small, so it has a low resolution. Bringing that texture closer to the camera will only magnify the existing texture, not increase the resolution of your rendered font.

You should check out drawStringAsShapes(...). That will draw your text as geometric objects, which can be scaled nicely.

Here’s some sample code to show the difference between drawString(...) and drawStringAsShapes(...). Play around with the simplifyAmt when you load your font. Smaller values yield higher resolution geometric versions of your text, but then also require more processing power. Also, make sure that makeContours is set to true. Otherwise, the geometry information isn’t created and your drawStringsAsShapes(...) will fail.

ofTrueTypeFont font;

//--------------------------------------------------------------
void testApp::setup(){

   font.loadFont("verdana.ttf", 5, true, false, true, 0.1);
}

//--------------------------------------------------------------
void testApp::draw(){
   ofBackground(0);

   ofPushMatrix();
       ofTranslate(0, 0, 500);
       font.drawString("test", ofGetWidth()/2 - 20, ofGetHeight()/2);
       font.drawStringAsShapes("test", ofGetWidth()/2 + 20, ofGetHeight()/2);
   ofPopMatrix();
}
2 Likes

Thanks very helpful, definitely improved dramatically, using a darker color also helped aesthetically speaking

1 Like