interpolate glyph pairs
This commit is contained in:
parent
94f0da2768
commit
207e2537b1
3 changed files with 81 additions and 89 deletions
161
src/Layer.cpp
161
src/Layer.cpp
|
@ -26,15 +26,16 @@ void MsdfLayer::draw(glm::vec3 position) const {
|
||||||
const ofImage & atlasImage = atlas->getAtlasImage();
|
const ofImage & atlasImage = atlas->getAtlasImage();
|
||||||
ofDisableAlphaBlending();
|
ofDisableAlphaBlending();
|
||||||
ofEnableDepthTest();
|
ofEnableDepthTest();
|
||||||
shader->begin();
|
|
||||||
shader->setUniformTexture("msdf", atlasImage.getTexture(), 0);
|
|
||||||
shader->setUniform4f("fontColor", ofFloatColor::white);
|
|
||||||
float pixelRange = 2;
|
float pixelRange = 2;
|
||||||
int atlas_w = atlasImage.getWidth();
|
int atlas_w = atlasImage.getWidth();
|
||||||
int atlas_h = atlasImage.getHeight();
|
int atlas_h = atlasImage.getHeight();
|
||||||
int atlas_x = 0;
|
int atlas_x = 0;
|
||||||
int atlas_y = 0;
|
int atlas_y = 0;
|
||||||
glm::vec2 unitRange = glm::vec2(pixelRange) / glm::vec2(atlas_w, atlas_h);
|
glm::vec2 unitRange = glm::vec2(pixelRange) / glm::vec2(atlas_w, atlas_h);
|
||||||
|
|
||||||
|
shader->begin();
|
||||||
|
shader->setUniformTexture("msdf", atlasImage.getTexture(), 0);
|
||||||
|
shader->setUniform4f("fontColor", ofFloatColor::white);
|
||||||
shader->setUniform2f("unitRange", unitRange);
|
shader->setUniform2f("unitRange", unitRange);
|
||||||
shader->end();
|
shader->end();
|
||||||
|
|
||||||
|
@ -46,116 +47,108 @@ void MsdfLayer::draw(glm::vec3 position) const {
|
||||||
ofPopStyle();
|
ofPopStyle();
|
||||||
char previous_c;
|
char previous_c;
|
||||||
bool firstLetter = true;
|
bool firstLetter = true;
|
||||||
|
|
||||||
|
// set variation axis
|
||||||
|
const float swing_sin = sin(ofGetElapsedTimef() * 1);
|
||||||
|
const float swing_01 = ofMap(swing_sin, -1, 1, 0, 1);
|
||||||
|
const vector <ofxMsdfgen::FontVariationAxis> & variationAxisAvailable = atlas->getVariationAxesAvailable();
|
||||||
|
const string var_name = variationAxisAvailable[0].name;
|
||||||
|
const float var_value = ofMap(swing_01, 0, 1,
|
||||||
|
variationAxisAvailable[0].minValue,
|
||||||
|
variationAxisAvailable[0].maxValue);
|
||||||
|
|
||||||
|
int i = 0;
|
||||||
for(const char c : propsBuffer[0].text){
|
for(const char c : propsBuffer[0].text){
|
||||||
ofxMsdfgen::GlyphGeometry gg = atlas->getGlyphGeometry(c);
|
float mix = -1;
|
||||||
int x, y, w, h;
|
ofxMsdfgen::GlyphGeometry gg_a;
|
||||||
gg.getBoxRect(x, y, w, h);
|
ofxMsdfgen::GlyphGeometry gg_b;
|
||||||
//y = atlas_h - (y + h);
|
|
||||||
if(y < 0){
|
bool success = atlas->getGlyphGeometryPair(c,
|
||||||
|
{var_name, var_value},
|
||||||
|
gg_a,
|
||||||
|
gg_b,
|
||||||
|
mix);
|
||||||
|
if(!success){
|
||||||
|
ofLogError("MsdfLayer::draw") << "could not get glyphGeometryPair" << endl;
|
||||||
|
}
|
||||||
|
int x_a, y_a, w_a, h_a;
|
||||||
|
int x_b, y_b, w_b, h_b;
|
||||||
|
gg_a.getBoxRect(x_a, y_a, w_a, h_a);
|
||||||
|
gg_b.getBoxRect(x_b, y_b, w_b, h_b);
|
||||||
|
if(y_a < 0 || y_b < 0){
|
||||||
// FIXME: make sure this does not happen
|
// FIXME: make sure this does not happen
|
||||||
ofLogError("MsdfLayer::draw") << "y smaller 0, this is not good" << endl;
|
ofLogError("MsdfLayer::draw") << "y smaller 0, this is not good" << endl;
|
||||||
}
|
}
|
||||||
ofPushStyle();
|
ofPushStyle();
|
||||||
double pl, pb, pr, pt,
|
double pl_a, pb_a, pr_a, pt_a;
|
||||||
il, ib, ir, it;
|
double pl_b, pb_b, pr_b, pt_b;
|
||||||
gg.getQuadPlaneBounds(pl, pb, pr, pt);
|
gg_a.getQuadPlaneBounds(pl_a, pb_a, pr_a, pt_a);
|
||||||
gg.getQuadAtlasBounds(il, ib, ir, it);
|
gg_b.getQuadPlaneBounds(pl_b, pb_b, pr_b, pt_b);
|
||||||
|
|
||||||
|
double advance_a = gg_a.getAdvance();
|
||||||
|
double advance_b = gg_b.getAdvance();
|
||||||
|
|
||||||
|
float x = glm::mix(float(x_a), float(x_b), mix);
|
||||||
|
float y = glm::mix(float(y_a), float(y_b), mix);
|
||||||
|
float w = glm::mix(float(w_a), float(w_b), mix);
|
||||||
|
float h = glm::mix(float(h_a), float(h_b), mix);
|
||||||
|
float pl = glm::mix(float(pl_a), float(pl_b), mix);
|
||||||
|
//float pb = glm::mix(float(pb_a), float(pb_b), mix);
|
||||||
|
//float pr = glm::mix(float(pr_a), float(pr_b), mix);
|
||||||
|
float pt = glm::mix(float(pt_a), float(pt_b), mix);
|
||||||
|
double advance = glm::mix(advance_a, advance_b, mix);
|
||||||
|
|
||||||
ofPushMatrix();
|
ofPushMatrix();
|
||||||
float magic = ofMap(sin(ofGetElapsedTimeMicros() * 0.000001), -1, 1, 1, 200);
|
float magic = atlas->settings.scale;
|
||||||
magic = atlas->settings.scale;
|
|
||||||
auto fontMetrics = atlas->getFontGeometry().getMetrics();
|
|
||||||
float cender = (fontMetrics.ascenderY - fontMetrics.descenderY);
|
|
||||||
//magic *= cender;
|
|
||||||
//if(ofGetFrameNum() % 30 == 0){
|
|
||||||
//cout << "drawing letter " << c << endl
|
|
||||||
//<< "\tpl: " << ofToString(pl)
|
|
||||||
//<< "\tpb: " << ofToString(pb)
|
|
||||||
//<< "\tpr: " << ofToString(pr)
|
|
||||||
//<< "\tpt: " << ofToString(pt)
|
|
||||||
//<< endl;
|
|
||||||
//}
|
|
||||||
|
|
||||||
//ofPushMatrix();
|
|
||||||
//for(int i = 0; i < 2; i++){
|
|
||||||
//if(i == 1){
|
|
||||||
//ofRotateDeg(90);
|
|
||||||
//ofTranslate(400, -150, 0);
|
|
||||||
//}
|
|
||||||
//ofNoFill();
|
|
||||||
//ofSetColor(ofColor::white);
|
|
||||||
//ofDrawLine(glm::vec2(0, 90), glm::vec2(0, 140));
|
|
||||||
//ofSetColor(ofColor::lightGray);
|
|
||||||
//for(int i = 1; i < 3; i++){
|
|
||||||
//ofDrawLine(glm::vec2(i * 20, 90), glm::vec2(i * 20, 140));
|
|
||||||
//}
|
|
||||||
//ofFill();
|
|
||||||
//if(i == 0){
|
|
||||||
//ofSetColor(ofColor::red);
|
|
||||||
//ofDrawRectangle(0, 100, pl * 50, 10);
|
|
||||||
//ofSetColor(ofColor::lightBlue);
|
|
||||||
//ofDrawRectangle(0, 120, pr * 50, 10);
|
|
||||||
//ofSetColor(ofColor::green);
|
|
||||||
//ofDrawRectangle(0, 130, gg.getAdvance() * 50, 10);
|
|
||||||
//ofDrawBitmapStringHighlight(ofToString(gg.getAdvance()), 0, 150);
|
|
||||||
//ofDrawBitmapStringHighlight(ofToString(pl), 0, 170);
|
|
||||||
//ofDrawBitmapStringHighlight(ofToString(pb), 0, 190);
|
|
||||||
//ofDrawBitmapStringHighlight(ofToString(pr), 0, 210);
|
|
||||||
//ofDrawBitmapStringHighlight(ofToString(pt), 0, 230);
|
|
||||||
//}else{
|
|
||||||
//ofSetColor(ofColor::green);
|
|
||||||
//ofDrawRectangle(0, 110, pb * 50, 10);
|
|
||||||
//ofSetColor(ofColor::yellow);
|
|
||||||
//ofDrawRectangle(0, 130, pt * 50, 10);
|
|
||||||
//}
|
|
||||||
//}
|
|
||||||
//ofPopMatrix();
|
|
||||||
shader->begin();
|
|
||||||
ofSetColor(ofFloatColor(1, 1, 1, 1));
|
ofSetColor(ofFloatColor(1, 1, 1, 1));
|
||||||
ofTranslate(pl * magic, 0, 0);
|
ofTranslate(pl * magic, 0, 0);
|
||||||
ofTranslate(0, -1 * pt * magic, 0);
|
ofTranslate(0, -1 * pt * magic, 0);
|
||||||
msdf_atlas::unicode_t a = static_cast <msdf_atlas::unicode_t>(previous_c);
|
//msdf_atlas::unicode_t a = static_cast <msdf_atlas::unicode_t>(previous_c);
|
||||||
msdf_atlas::unicode_t b = static_cast <msdf_atlas::unicode_t>(c);
|
//msdf_atlas::unicode_t b = static_cast <msdf_atlas::unicode_t>(c);
|
||||||
double advance = gg.getAdvance();
|
|
||||||
if(!firstLetter){
|
if(!firstLetter){
|
||||||
//cout << "this is being printed" << endl;
|
//cout << "this is being printed" << endl;
|
||||||
auto & fontGeometry = atlas->getFontGeometry();
|
auto & fontGeometry = atlas->getFontGeometry();
|
||||||
const std::map <std::pair <int, int>, double> kerning = fontGeometry.getKerning();
|
const std::map <std::pair <int, int>, double> kerning = fontGeometry.getKerning();
|
||||||
ofxMsdfgen::GlyphGeometry gg_previous = atlas->getGlyphGeometry(c);
|
ofxMsdfgen::GlyphGeometry gg_previous = atlas->getGlyphGeometry(c);
|
||||||
|
|
||||||
std::map <std::pair <int, int>, double>::const_iterator it = kerning.find(std::make_pair <int, int>(gg_previous.getIndex(), gg.getIndex()));
|
std::map <std::pair <int, int>, double>::const_iterator it = kerning.find(std::make_pair <int, int>(gg_previous.getIndex(), gg_a.getIndex()));
|
||||||
if(it != kerning.end()){
|
if(it != kerning.end()){
|
||||||
advance += it->second;
|
advance += it->second;
|
||||||
ofDrawBitmapStringHighlight(ofToString(it->second), 0, 200, ofColor::black, ofColor::pink);
|
ofDrawBitmapStringHighlight(ofToString(it->second), 0, 200, ofColor::black, ofColor::pink);
|
||||||
}
|
}
|
||||||
ofPushStyle();
|
|
||||||
ofFill();
|
|
||||||
ofSetColor(ofColor::green);
|
|
||||||
ofDrawRectangle(0, 0, 400, 400);
|
|
||||||
ofPopStyle();
|
|
||||||
//fontGeometry.getAdvance(advance, 'a', 'b');
|
|
||||||
//cout << "first worked" << endl;
|
|
||||||
//fontGeometry.getAdvance(advance, a, b);
|
|
||||||
//cout << "this is maybeh being printed" << endl;
|
|
||||||
//bool gotAdvance = atlas->getFontGeometry().getAdvance(advance, a, b);
|
|
||||||
//cout << "this is being not printed" << endl;
|
|
||||||
//if(gotAdvance){
|
|
||||||
//ofTranslate(advance * magic, 0, 0);
|
|
||||||
//}
|
|
||||||
}else{
|
|
||||||
firstLetter = false;
|
|
||||||
}
|
}
|
||||||
msdf_atlas::GlyphBox gb;
|
glm::vec2 translation_a = glm::vec2(float(x_a) / float(atlas_w),
|
||||||
atlasImage.drawSubsection(0, 0, w, h, x, y, w, h);
|
float(y_a) / float(atlas_h));
|
||||||
|
glm::vec2 scale_a = glm::vec2(float(w_a) / float(atlas_w),
|
||||||
|
float(h_a) / float(atlas_h));
|
||||||
|
glm::vec2 translation_b = glm::vec2(float(x_b) / float(atlas_w),
|
||||||
|
float(y_b) / float(atlas_h));
|
||||||
|
glm::vec2 scale_b = glm::vec2(float(w_b) / float(atlas_w),
|
||||||
|
float(h_b) / float(atlas_h));
|
||||||
|
//if(firstLetter){
|
||||||
|
//cout << "translation_a: " << ofToString(translation_a) << endl;
|
||||||
|
//cout << "scale_a: " << ofToString(scale_a) << endl;
|
||||||
|
//}
|
||||||
|
shader->begin();
|
||||||
|
shader->setUniform4f("fontColor", ofFloatColor::yellow);
|
||||||
|
shader->setUniform2f("translation_a", translation_a);
|
||||||
|
shader->setUniform2f("scale_a", scale_a);
|
||||||
|
shader->setUniform2f("translation_b", translation_b);
|
||||||
|
shader->setUniform2f("scale_b", scale_b);
|
||||||
|
shader->setUniform1f("msdf_mix", mix);
|
||||||
|
atlasImage.draw(0, 0, w, h);
|
||||||
shader->end();
|
shader->end();
|
||||||
ofPopMatrix();
|
ofPopMatrix();
|
||||||
ofPopStyle();
|
ofPopStyle();
|
||||||
ofTranslate(advance * magic, 0, 0);
|
ofTranslate(advance * magic, 0, 0);
|
||||||
ofTranslate(-1 * pl * magic, 0, 0);
|
ofTranslate(-1 * pl * magic, 0, 0);
|
||||||
previous_c = c;
|
previous_c = c;
|
||||||
|
if(firstLetter){
|
||||||
|
firstLetter = false;
|
||||||
|
}
|
||||||
|
i++;
|
||||||
}
|
}
|
||||||
ofPopMatrix();
|
ofPopMatrix();
|
||||||
//atlasImage.draw(x, y);
|
|
||||||
ofDisableDepthTest();
|
ofDisableDepthTest();
|
||||||
ofEnableAlphaBlending();
|
ofEnableAlphaBlending();
|
||||||
}
|
}
|
||||||
|
|
|
@ -25,7 +25,6 @@ class Layer {
|
||||||
float x = 0;
|
float x = 0;
|
||||||
float y = 0;
|
float y = 0;
|
||||||
float rotation = 0;
|
float rotation = 0;
|
||||||
float wght = 100;
|
|
||||||
float fontSize_px = 24;
|
float fontSize_px = 24;
|
||||||
float * color[4];
|
float * color[4];
|
||||||
TransformOrigin transformOrigin = TransformOrigin::CENTER;
|
TransformOrigin transformOrigin = TransformOrigin::CENTER;
|
||||||
|
@ -34,7 +33,7 @@ class Layer {
|
||||||
bool mirror_y = false;
|
bool mirror_y = false;
|
||||||
float mirror_y_distance = 0;
|
float mirror_y_distance = 0;
|
||||||
float letterDelay = 0;
|
float letterDelay = 0;
|
||||||
string text = "ASYA is the best";
|
string text = "Variable Font Editor";
|
||||||
};
|
};
|
||||||
struct Settings {
|
struct Settings {
|
||||||
uint32_t maxBufferSize = 100;
|
uint32_t maxBufferSize = 100;
|
||||||
|
|
|
@ -19,9 +19,9 @@ void LayerComposition::setup(){
|
||||||
|
|
||||||
msdfShader = make_shared <ofShader>();
|
msdfShader = make_shared <ofShader>();
|
||||||
#ifdef TARGET_EMSCRIPTEN
|
#ifdef TARGET_EMSCRIPTEN
|
||||||
msdfShader->load("ofxMsdfgen/shaders/unitRange/ES3/shader");
|
msdfShader->load("ofxMsdfgen/shaders/mix/ES3/shader");
|
||||||
#else
|
#else
|
||||||
msdfShader->load("ofxMsdfgen/shaders/unitRange/GL3/shader");
|
msdfShader->load("ofxMsdfgen/shaders/mix/GL3/shader");
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
auto layer = make_unique <ofxVariableLab::MsdfLayer>();
|
auto layer = make_unique <ofxVariableLab::MsdfLayer>();
|
||||||
|
@ -45,7 +45,7 @@ void LayerComposition::update(){
|
||||||
|
|
||||||
void LayerComposition::draw() const {
|
void LayerComposition::draw() const {
|
||||||
for(const auto & layer : layers){
|
for(const auto & layer : layers){
|
||||||
layer->draw(glm::vec3(0, 200, 0));
|
layer->draw(glm::vec3(400, 200, 0));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue