possibly better examples (untested)
This commit is contained in:
parent
c36483ab21
commit
f4cb8bec03
3 changed files with 95 additions and 42 deletions
|
@ -1,4 +1,5 @@
|
||||||
#include "ofApp.h"
|
#include "ofApp.h"
|
||||||
|
#include "Atlas.h"
|
||||||
#include "conversion.h"
|
#include "conversion.h"
|
||||||
#include "import-font.h"
|
#include "import-font.h"
|
||||||
#include "ofAppRunner.h"
|
#include "ofAppRunner.h"
|
||||||
|
@ -12,11 +13,25 @@ void ofApp::setup(){
|
||||||
ofSetVerticalSync(false);
|
ofSetVerticalSync(false);
|
||||||
//string fontName = "RobotoFlex.ttf";
|
//string fontName = "RobotoFlex.ttf";
|
||||||
//string fontPath = "data/fonts/" + fontName;
|
//string fontPath = "data/fonts/" + fontName;
|
||||||
string fontPath = "data/celines-fonts/testing2VF.ttf";
|
string fontPath = "data/celines-fonts/TonkaFlowers.ttf";
|
||||||
//string fontPath = "data/celines-fonts/Cottagecore.ttf";
|
//string fontPath = "data/celines-fonts/Cottagecore.ttf";
|
||||||
ofxMsdfgen::AtlasSettings settings;
|
ofxMsdfgen::AtlasSettings settings;
|
||||||
settings.characters = "ABCDEFGHIJKL";
|
settings.minimumScale = 256;
|
||||||
|
settings.scale = 256;
|
||||||
|
settings.maxInterpolationStepSize = 10;
|
||||||
|
settings.characters = "acdqrs"; //"abjkosy";
|
||||||
|
// fine acdhjopqrs
|
||||||
|
// // fucked befgiklmn
|
||||||
atlas.setup(fontPath, settings);
|
atlas.setup(fontPath, settings);
|
||||||
|
vector <ofxMsdfgen::FontVariation> fvs;
|
||||||
|
fvs.push_back({"Weight", 0.0});
|
||||||
|
fvs.push_back({"Weight", 400.0});
|
||||||
|
//for(int i = 0; i < 16; i++){
|
||||||
|
//float value = i * 25;
|
||||||
|
//fvs.push_back({"Weight", 0.0});
|
||||||
|
//}
|
||||||
|
atlas.addVariations(fvs);
|
||||||
|
atlas.generate(true, true);
|
||||||
atlasImage = atlas.getAtlasImage();
|
atlasImage = atlas.getAtlasImage();
|
||||||
glyphGeometries = atlas.getGlyphGeometries();
|
glyphGeometries = atlas.getGlyphGeometries();
|
||||||
#ifdef TARGET_EMSCRIPTEN
|
#ifdef TARGET_EMSCRIPTEN
|
||||||
|
@ -50,7 +65,7 @@ void ofApp::draw(){
|
||||||
|
|
||||||
shader.begin();
|
shader.begin();
|
||||||
shader.setUniformTexture("msdf", atlasImage.getTexture(), 0);
|
shader.setUniformTexture("msdf", atlasImage.getTexture(), 0);
|
||||||
shader.setUniform4f("fontColor", ofFloatColor::white);
|
shader.setUniform4f("fontColor", ofFloatColor::red);
|
||||||
|
|
||||||
ofPushMatrix();
|
ofPushMatrix();
|
||||||
ofTranslate(40, 40, 0);
|
ofTranslate(40, 40, 0);
|
||||||
|
@ -62,7 +77,8 @@ void ofApp::draw(){
|
||||||
//unicode_t character = word[c];
|
//unicode_t character = word[c];
|
||||||
//const ofxMsdfgen::GlyphGeometry & glyphGeometry = glyphGeometries[0];
|
//const ofxMsdfgen::GlyphGeometry & glyphGeometry = glyphGeometries[0];
|
||||||
int amount = 0;
|
int amount = 0;
|
||||||
float mouser = ofGetMousePressed() ? ofMap(ofGetMouseX(), 0, ofGetWidth(), 0.001, 1) : 1;
|
float mouser = ofGetMousePressed() ? ofMap(ofGetMouseX(), 0, ofGetWidth(), 0.001, 4) : 1;
|
||||||
|
shader.setUniform1f("pxRange", mouser);
|
||||||
for(int iz = 0; iz < 3; iz++){
|
for(int iz = 0; iz < 3; iz++){
|
||||||
tx = 0;
|
tx = 0;
|
||||||
ty = 0;
|
ty = 0;
|
||||||
|
@ -91,7 +107,9 @@ void ofApp::draw(){
|
||||||
ofDisableAlphaBlending();
|
ofDisableAlphaBlending();
|
||||||
ofDisableDepthTest();
|
ofDisableDepthTest();
|
||||||
cam.end();
|
cam.end();
|
||||||
|
ofClear(0, 0, 0, 255);
|
||||||
|
|
||||||
|
atlasImage.draw(0, 0, ofGetHeight(), ofGetHeight());
|
||||||
shader.end();
|
shader.end();
|
||||||
ofPushStyle();
|
ofPushStyle();
|
||||||
ofSetColor(ofColor::purple);
|
ofSetColor(ofColor::purple);
|
||||||
|
@ -106,6 +124,10 @@ void ofApp::draw(){
|
||||||
void ofApp::keyPressed(int key){
|
void ofApp::keyPressed(int key){
|
||||||
if(key == 's'){
|
if(key == 's'){
|
||||||
atlasImage.save("web_atlasImage.png");
|
atlasImage.save("web_atlasImage.png");
|
||||||
|
}else{
|
||||||
|
//a
|
||||||
|
atlas.settings.characters = "" + (char)key;
|
||||||
|
atlas.generate();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -7,20 +7,62 @@
|
||||||
|
|
||||||
//--------------------------------------------------------------
|
//--------------------------------------------------------------
|
||||||
void ofApp::setup(){
|
void ofApp::setup(){
|
||||||
string fontName = "RobotoFlex.ttf";
|
string fontName = "TonkaFlowers.ttf";
|
||||||
fontPath = "data/fonts/" + fontName;
|
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 dimension = 64;
|
||||||
int width = dimension;
|
int width = dimension;
|
||||||
int height = dimension;
|
int height = dimension;
|
||||||
|
|
||||||
FreetypeHandle * ft = initializeFreetype();
|
FreetypeHandle * ft = initializeFreetype();
|
||||||
if(ft){
|
if(ft){
|
||||||
const char * fontPath_c_str = fontPath.c_str();
|
const char * fontPath_c_str = fontPath.c_str();
|
||||||
FontHandle * font = loadFont(ft, fontPath_c_str);
|
FontHandle * font = loadFont(ft, fontPath_c_str);
|
||||||
if(font){
|
if(font){
|
||||||
Shape shape;
|
Shape shape;
|
||||||
if(loadGlyph(shape, font, 'a')){
|
if(loadGlyph(shape, font, character)){
|
||||||
shape.normalize();
|
shape.normalize();
|
||||||
Shape::Bounds bounds = shape.getBounds();
|
Shape::Bounds bounds = shape.getBounds();
|
||||||
|
|
||||||
|
@ -69,40 +111,6 @@ void ofApp::setup(){
|
||||||
}
|
}
|
||||||
deinitializeFreetype(ft);
|
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");
|
ofSaveImage(image, "output.jpg");
|
||||||
image.save("outerput.png");
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//--------------------------------------------------------------
|
//--------------------------------------------------------------
|
||||||
|
|
|
@ -24,6 +24,13 @@ class ofApp : public ofBaseApp {
|
||||||
void dragEvent(ofDragInfo dragInfo);
|
void dragEvent(ofDragInfo dragInfo);
|
||||||
void gotMessage(ofMessage msg);
|
void gotMessage(ofMessage msg);
|
||||||
|
|
||||||
|
void makeCharacter(char character);
|
||||||
|
|
||||||
|
string characters = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
|
||||||
|
int currentCharacter = 0;
|
||||||
|
|
||||||
|
bool showAtlas = true;
|
||||||
|
|
||||||
string fontPath;
|
string fontPath;
|
||||||
ofImage image;
|
ofImage image;
|
||||||
ofFloatImage fimage;
|
ofFloatImage fimage;
|
||||||
|
|
Loading…
Reference in a new issue