possibly better examples (untested)

This commit is contained in:
jrkb 2023-08-04 10:03:07 +02:00
parent c36483ab21
commit f4cb8bec03
3 changed files with 95 additions and 42 deletions

View file

@ -7,20 +7,62 @@
//--------------------------------------------------------------
void ofApp::setup(){
string fontName = "RobotoFlex.ttf";
fontPath = "data/fonts/" + fontName;
string fontName = "TonkaFlowers.ttf";
fontPath = "data/celines-fonts/" + fontName;
char character = characters[currentCharacter];
makeCharacter(character);
#ifdef TARGET_EMSCRIPTEN
shader.load("ofxMsdfgen/shaders/simple/ES3/shader");
#else
shader.load("ofxMsdfgen/shaders/simple/GL3/shader");
#endif
}
//--------------------------------------------------------------
void ofApp::update(){
}
//--------------------------------------------------------------
void ofApp::draw(){
ofBackground(ofColor::lightGreen);
shader.begin();
float pxRange = ofMap(sin(ofGetElapsedTimeMillis() * 0.001),
-1, 1,
1, 100);
shader.setUniform1f("pxRange", pxRange);
shader.setUniformTexture("msdf", image.getTexture(), 0);
shader.setUniform4f("fontColor", ofFloatColor::white);
image.draw(ofGetWidth() - ofGetHeight(), 0, ofGetHeight(), ofGetHeight());
shader.end();
ofPushStyle();
ofSetColor(ofColor::purple);
ofDrawBitmapString("pxRange: " + ofToString(pxRange), 20, 20);
ofPopStyle();
image.draw(0, 0, 64 * 4, 64 * 4);
string msg = fontPath + "\n" + characters[currentCharacter];
ofDrawBitmapStringHighlight(msg, 20, 20);
}
void ofApp::makeCharacter(char character){
int dimension = 64;
int width = dimension;
int height = dimension;
FreetypeHandle * ft = initializeFreetype();
if(ft){
const char * fontPath_c_str = fontPath.c_str();
FontHandle * font = loadFont(ft, fontPath_c_str);
if(font){
Shape shape;
if(loadGlyph(shape, font, 'a')){
if(loadGlyph(shape, font, character)){
shape.normalize();
Shape::Bounds bounds = shape.getBounds();
@ -69,40 +111,6 @@ void ofApp::setup(){
}
deinitializeFreetype(ft);
}
#ifdef TARGET_EMSCRIPTEN
shader.load("ofxMsdfgen/shaders/simple/ES3/shader");
#else
shader.load("ofxMsdfgen/shaders/simple/GL3/shader");
#endif
}
//--------------------------------------------------------------
void ofApp::update(){
}
//--------------------------------------------------------------
void ofApp::draw(){
ofBackground(ofColor::lightGreen);
shader.begin();
float pxRange = ofMap(sin(ofGetElapsedTimeMillis() * 0.001),
-1, 1,
1, 100);
shader.setUniform1f("pxRange", pxRange);
shader.setUniformTexture("msdf", image.getTexture(), 0);
shader.setUniform4f("fontColor", ofFloatColor::white);
image.draw(0, 0, ofGetHeight(), ofGetHeight());
shader.end();
ofPushStyle();
ofSetColor(ofColor::purple);
ofDrawBitmapString("pxRange: " + ofToString(pxRange), 20, 20);
ofPopStyle();
image.draw(0, 0, 64 * 4, 64 * 4);
}
//--------------------------------------------------------------
@ -112,6 +120,22 @@ void ofApp::keyPressed(int key){
ofSaveImage(image, "output.jpg");
image.save("outerput.png");
}
if(key == 'n'){
currentCharacter++;
currentCharacter %= characters.length();
makeCharacter(characters[currentCharacter]);
}else if(key == 'p'){
currentCharacter = characters.length() + currentCharacter - 1;
currentCharacter %= characters.length();
makeCharacter(characters[currentCharacter]);
}
if(key == 'a'){
showAtlas = !showAtlas;
if(showAtlas){
image.load("atlascache/celines-fonts/TonkaFlowers.ttf/msdfgen/256_256_10Weight_0_Weight_400_.png");
}
cout << "show tlas " << (showAtlas ? "yes" : "no") << endl;
}
}
//--------------------------------------------------------------

View file

@ -24,6 +24,13 @@ class ofApp : public ofBaseApp {
void dragEvent(ofDragInfo dragInfo);
void gotMessage(ofMessage msg);
void makeCharacter(char character);
string characters = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
int currentCharacter = 0;
bool showAtlas = true;
string fontPath;
ofImage image;
ofFloatImage fimage;