Hello dear oF-Community,
I have a project, where I want to transform some text. In order to do that, I load an ofTrueTypeFont, get its vertices, transform them and then draw all the characters. My problem is that with this method I cannot draw letters with “holes” in them properly. How would you work around this problem/code this more elegantly?
I’ll include my source code, where the problem can be seen. Thanks in advance for any help!
Mara
Include this in the ofApp.h:
ofTrueTypeFont font;
int font_size;
vector <ofPolyline> lines;
vector <ofPath> paths;
vector <glm::vec3> vertices;
int sample_count = 180; //number of Points used for each letter
This is my code from the ofApp.cpp
void ofApp::setup(){
ofBackground(235);
font_size = 100;
font.load("bestinclass.ttf", font_size, false, false, true);
}
void ofApp::draw(){
ofTranslate(ofGetWidth()/3, ofGetHeight()/2);
float time = ofGetElapsedTimef();
paths = font.getStringAsPoints("HELLO",true,false);
for (int i = 0; i < paths.size(); i++) {
lines = paths[i].getOutline();
for (int j = 0; j < lines.size(); j++) {
lines[j] = lines[j].getResampledByCount(sample_count);
vertices = lines[j].getVertices();
}
ofSetColor(30);
ofFill();
ofBeginShape();
for (int k = 0; k < vertices.size(); k++) {
vertices[k].y = vertices[k].y*sin(vertices[k].x*0.005+time+10*ofNoise(0.001*vertices[k].x,time*0.01));
vertices[k].x += sin(time)*10*ofNoise(vertices[k].y*0.1,time);
ofVertex(vertices[k]);
}
ofEndShape();
}
}