Layer has Atlas not atlasImage, etc
This commit is contained in:
parent
7c3b8767e8
commit
0f07dbfb64
4 changed files with 67 additions and 16 deletions
|
@ -1,6 +1,8 @@
|
||||||
#include "Layer.h"
|
#include "Layer.h"
|
||||||
|
#include "conversion.h"
|
||||||
#include "ofAppRunner.h"
|
#include "ofAppRunner.h"
|
||||||
#include "ofGraphics.h"
|
#include "ofGraphics.h"
|
||||||
|
#include "ofUtils.h"
|
||||||
|
|
||||||
namespace ofxVariableLab {
|
namespace ofxVariableLab {
|
||||||
|
|
||||||
|
@ -14,25 +16,70 @@ MsdfLayer::~MsdfLayer(){
|
||||||
}
|
}
|
||||||
|
|
||||||
void Layer::update(){
|
void Layer::update(){
|
||||||
|
if(isDirty){
|
||||||
|
|
||||||
|
isDirty = false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void MsdfLayer::draw(float x, float y) const {
|
void MsdfLayer::draw(glm::vec3 position) const {
|
||||||
|
const ofImage & atlasImage = atlas->getAtlasImage();
|
||||||
ofDisableAlphaBlending();
|
ofDisableAlphaBlending();
|
||||||
ofEnableDepthTest();
|
ofEnableDepthTest();
|
||||||
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::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->setUniform2f("unitRange", unitRange);
|
shader->setUniform2f("unitRange", unitRange);
|
||||||
//atlasImage->drawSubsection(0, 0, w, h, x, y, w, h);
|
|
||||||
atlasImage->draw(x, y);
|
|
||||||
shader->end();
|
shader->end();
|
||||||
|
|
||||||
|
ofPushMatrix();
|
||||||
|
//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);
|
||||||
|
y = atlas_h - (y + h);
|
||||||
|
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);
|
||||||
|
ofTranslate(pr * magic, pt * magic, 0);
|
||||||
|
//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);
|
||||||
ofDisableDepthTest();
|
ofDisableDepthTest();
|
||||||
ofEnableAlphaBlending();
|
ofEnableAlphaBlending();
|
||||||
}
|
}
|
||||||
|
|
|
@ -41,7 +41,7 @@ class Layer {
|
||||||
};
|
};
|
||||||
|
|
||||||
void update();
|
void update();
|
||||||
virtual void draw(float x = 0, float y = 0) const = 0;
|
virtual void draw(glm::vec3 position = glm::vec3(0, 0, 0)) const = 0;
|
||||||
void setProps(const Props & props);
|
void setProps(const Props & props);
|
||||||
//void setProps(float _x,
|
//void setProps(float _x,
|
||||||
//float _y,
|
//float _y,
|
||||||
|
@ -73,8 +73,8 @@ class MsdfLayer : public Layer {
|
||||||
public:
|
public:
|
||||||
MsdfLayer();
|
MsdfLayer();
|
||||||
~MsdfLayer();
|
~MsdfLayer();
|
||||||
void draw(float x = 0, float y = 0) const override;
|
void draw(glm::vec3 position = glm::vec3(0, 0, 0)) const override;
|
||||||
shared_ptr <ofImage> atlasImage;
|
shared_ptr <ofxMsdfgen::Atlas> atlas;
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,21 +1,23 @@
|
||||||
#include "LayerComposition.h"
|
#include "LayerComposition.h"
|
||||||
#include "ofUtils.h"
|
#include "ofUtils.h"
|
||||||
|
#include <memory>
|
||||||
|
|
||||||
namespace ofxVariableLab {
|
namespace ofxVariableLab {
|
||||||
|
|
||||||
void LayerComposition::setup(){
|
void LayerComposition::setup(){
|
||||||
ofxMsdfgen::AtlasSettings settings;
|
ofxMsdfgen::AtlasSettings settings;
|
||||||
settings.characters = "ABCDEFGHIJKL";
|
//settings.characters = "ABCDEFGHIJKL";
|
||||||
settings.scale = 64;
|
settings.scale = 64;
|
||||||
//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/testing2VF.ttf";
|
||||||
string fontPath = "data/celines-fonts/Version-2-var.ttf";
|
string fontPath = "data/celines-fonts/Version-2-var.ttf";
|
||||||
//string fontPath = "data/celines-fonts/Cottagecore.ttf";
|
//string fontPath = "data/celines-fonts/Cottagecore.ttf";
|
||||||
atlas.setup(fontPath, settings);
|
atlas = make_shared <ofxMsdfgen::Atlas>();
|
||||||
|
atlas->setup(fontPath, settings);
|
||||||
|
|
||||||
atlasImage = make_shared <ofImage>(atlas.getAtlasImage());
|
atlasImage = make_shared <ofImage>(atlas->getAtlasImage());
|
||||||
glyphGeometries = atlas.getGlyphGeometries();
|
glyphGeometries = atlas->getGlyphGeometries();
|
||||||
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/unitRange/ES3/shader");
|
||||||
|
@ -24,11 +26,13 @@ void LayerComposition::setup(){
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
auto layer = make_unique <ofxVariableLab::MsdfLayer>();
|
auto layer = make_unique <ofxVariableLab::MsdfLayer>();
|
||||||
layer->atlasImage = atlasImage;
|
layer->atlas = atlas;
|
||||||
layer->shader = msdfShader;
|
layer->shader = msdfShader;
|
||||||
layer->atlasImage->update();
|
|
||||||
|
layer->setProps(Layer::Props());
|
||||||
|
|
||||||
layers.push_back(std::move(layer));
|
layers.push_back(std::move(layer));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void LayerComposition::update(){
|
void LayerComposition::update(){
|
||||||
|
|
|
@ -18,7 +18,7 @@ class LayerComposition {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
private:
|
private:
|
||||||
ofxMsdfgen::Atlas atlas;
|
shared_ptr <ofxMsdfgen::Atlas> atlas;
|
||||||
shared_ptr <ofImage> atlasImage;
|
shared_ptr <ofImage> atlasImage;
|
||||||
vector <ofxMsdfgen::GlyphGeometry> glyphGeometries;
|
vector <ofxMsdfgen::GlyphGeometry> glyphGeometries;
|
||||||
shared_ptr <ofShader> msdfShader;
|
shared_ptr <ofShader> msdfShader;
|
||||||
|
|
Loading…
Reference in a new issue