2023-03-19 12:04:47 +01:00
|
|
|
#include "Layer.h"
|
2023-03-26 21:19:37 +02:00
|
|
|
#include "conversion.h"
|
2023-03-25 13:51:04 +01:00
|
|
|
#include "ofAppRunner.h"
|
|
|
|
#include "ofGraphics.h"
|
2023-03-26 21:19:37 +02:00
|
|
|
#include "ofUtils.h"
|
2023-03-25 13:51:04 +01:00
|
|
|
|
|
|
|
namespace ofxVariableLab {
|
|
|
|
|
|
|
|
Layer::Layer(){
|
|
|
|
}
|
|
|
|
Layer::~Layer(){
|
|
|
|
}
|
|
|
|
MsdfLayer::MsdfLayer(){
|
|
|
|
}
|
|
|
|
MsdfLayer::~MsdfLayer(){
|
|
|
|
}
|
|
|
|
|
|
|
|
void Layer::update(){
|
2023-03-26 21:19:37 +02:00
|
|
|
if(isDirty){
|
2023-03-25 13:51:04 +01:00
|
|
|
|
2023-03-26 21:19:37 +02:00
|
|
|
isDirty = false;
|
|
|
|
}
|
2023-03-25 13:51:04 +01:00
|
|
|
}
|
|
|
|
|
2023-03-26 21:19:37 +02:00
|
|
|
void MsdfLayer::draw(glm::vec3 position) const {
|
|
|
|
const ofImage & atlasImage = atlas->getAtlasImage();
|
2023-03-25 13:51:04 +01:00
|
|
|
ofDisableAlphaBlending();
|
|
|
|
ofEnableDepthTest();
|
|
|
|
shader->begin();
|
2023-03-26 21:19:37 +02:00
|
|
|
shader->setUniformTexture("msdf", atlasImage.getTexture(), 0);
|
2023-03-25 13:51:04 +01:00
|
|
|
shader->setUniform4f("fontColor", ofFloatColor::white);
|
|
|
|
float pixelRange = 2;
|
2023-03-26 21:19:37 +02:00
|
|
|
int atlas_w = atlasImage.getWidth();
|
|
|
|
int atlas_h = atlasImage.getHeight();
|
2023-03-25 13:51:04 +01:00
|
|
|
int atlas_x = 0;
|
|
|
|
int atlas_y = 0;
|
|
|
|
glm::vec2 unitRange = glm::vec2(pixelRange) / glm::vec2(atlas_w, atlas_h);
|
|
|
|
shader->setUniform2f("unitRange", unitRange);
|
|
|
|
shader->end();
|
2023-03-26 21:19:37 +02:00
|
|
|
|
|
|
|
ofPushMatrix();
|
2023-03-27 18:55:47 +02:00
|
|
|
atlas->getAtlasImage().draw(0, 0);
|
2023-03-26 21:19:37 +02:00
|
|
|
//cout << "drawing letters (" << ofToString(propsBuffer.size()) << ")" << endl;
|
|
|
|
for(const char c : propsBuffer[0].text){
|
|
|
|
ofxMsdfgen::GlyphGeometry gg = atlas->getGlyphGeometry(c);
|
|
|
|
int x, y, w, h;
|
|
|
|
gg.getBoxRect(x, y, w, h);
|
2023-03-27 18:55:47 +02:00
|
|
|
//y = atlas_h - (y + h);
|
2023-03-26 21:19:37 +02:00
|
|
|
if(y < 0){
|
|
|
|
// FIXME: make sure this does not happen
|
|
|
|
ofLogError("MsdfLayer::draw") << "y smaller 0, this is not good" << endl;
|
|
|
|
}
|
|
|
|
ofPushStyle();
|
|
|
|
ofNoFill();
|
|
|
|
ofSetColor(ofFloatColor(sin(ofGetElapsedTimeMicros() * 0.0001) * 0.5 + 0.5, 0, 0, 1));
|
|
|
|
double pl, pb, pr, pt,
|
|
|
|
il, ib, ir, it;
|
|
|
|
gg.getQuadPlaneBounds(pl, pb, pr, pt);
|
|
|
|
gg.getQuadAtlasBounds(il, ib, ir, it);
|
|
|
|
|
|
|
|
ofPushMatrix();
|
|
|
|
float magic = ofMap(sin(ofGetElapsedTimeMicros() * 0.000001), -1, 1, 1, 1000);
|
2023-03-27 18:55:47 +02:00
|
|
|
ofTranslate(pl * magic, pt * magic, 0);
|
2023-03-26 21:19:37 +02:00
|
|
|
//if(ofGetFrameNum() % 30 == 0){
|
|
|
|
//cout << "drawing letter " << c << endl
|
|
|
|
//<< "\tpl: " << ofToString(pl)
|
|
|
|
//<< "\tpb: " << ofToString(pb)
|
|
|
|
//<< "\tpr: " << ofToString(pr)
|
|
|
|
//<< "\tpt: " << ofToString(pt)
|
|
|
|
//<< endl;
|
|
|
|
//}
|
|
|
|
|
|
|
|
ofFill();
|
|
|
|
shader->begin();
|
|
|
|
ofSetColor(ofFloatColor(1, 1, 1, 1));
|
|
|
|
atlasImage.drawSubsection(0, 0, w, h, x, y, w, h);
|
|
|
|
shader->end();
|
|
|
|
ofPopMatrix();
|
|
|
|
ofPopStyle();
|
|
|
|
ofTranslate(w, 0, 0);
|
|
|
|
}
|
|
|
|
ofPopMatrix();
|
|
|
|
//atlasImage.draw(x, y);
|
2023-03-25 13:51:04 +01:00
|
|
|
ofDisableDepthTest();
|
|
|
|
ofEnableAlphaBlending();
|
|
|
|
}
|
|
|
|
void Layer::setProps(const Props & props){
|
|
|
|
while(propsBuffer.size() > max(0, int(settings.maxBufferSize - 1))){
|
|
|
|
propsBuffer.pop_back();
|
|
|
|
}
|
|
|
|
propsBuffer.push_front(props);
|
|
|
|
}
|
|
|
|
void Layer::clearPropsBuffer(){
|
|
|
|
propsBuffer.clear();
|
|
|
|
}
|
|
|
|
void Layer::setId(const string & id){
|
|
|
|
this->id = id;
|
|
|
|
}
|
|
|
|
const string & Layer::getId(){
|
|
|
|
return id;
|
|
|
|
}
|
|
|
|
}
|