#include "LayerComposition.h" #include "Atlas.h" #include "MsdfLayer.h" #include "Utils.h" #include "ofUtils.h" #include namespace ofxVariableLab { void MsdfAtlasLayerCombo::setup(const ComboIdentifier & layerIdentifier){ this->identifier = layerIdentifier; ofxMsdfgen::AtlasSettings atlasSettings; //settings.characters = "ABCDEFGHIJKL"; atlasSettings.scale = 64; atlasSettings.minimumScale = 64; atlasSettings.characters = ""; atlasSettings.maxInterpolationStepSize = 50.0; //string fontName = "RobotoFlex.ttf"; //string fontPath = "data/fonts/" + fontName; //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/Version-3-var.ttf"; //string fontPath = "data/celines-fonts/Version-4-var.ttf"; //string fontPath = "data/celines-fonts/Alfarn2.otf"; //string fontPath = "data/celines-fonts/Cottagecore.ttf"; atlas = make_shared (); msdfShader = make_shared (); #ifdef TARGET_EMSCRIPTEN msdfShader->load("ofxMsdfgen/shaders/mix/ES3/shader"); #else msdfShader->load("ofxMsdfgen/shaders/mix/GL3/shader"); #endif cout << "settings scale before " << atlasSettings.scale << endl << "minimum scale before " << atlasSettings.minimumScale << endl; atlas->setup(fontPath, atlasSettings); } void MsdfAtlasLayerCombo::update(){ if(isDirty){ atlas->generate(); isDirty = false; } } void MsdfAtlasLayerCombo::careForChild(shared_ptr layer){ shared_ptr msdfLayer = dynamic_pointer_cast (layer); msdfLayer->setAtlas(this->atlas); msdfLayer->setShader(msdfShader); auto & as = atlas->settings; for(const char c : layer->getProps().text){ if(as.characters.find(c) == std::string::npos){ // not found as.characters += c; isDirty = true; } } layers.push_back(msdfLayer); } const ComboIdentifier & MsdfAtlasLayerCombo::getIdentifier() const { return identifier; } void LayerComposition::setup(){ } void LayerComposition::update(){ for(const auto & atlasLayerCombo : atlasLayerCombos){ atlasLayerCombo.second->update(); } } LayerID LayerComposition::addLayer(const ComboIdentifier & identifier, const string & text, const std::vector & variations){ string layerID = ""; if(atlasLayerCombos.count(identifier) <= 0){ switch(identifier.type){ case Layer::GPUFONT: { ofLogError("LayerComposition::addLayer") << "GPUFont not implemented" << endl; break; } default: case Layer::MSDFGEN: { // TODO: put most stuff in combo setup auto combo = make_shared (); combo->setup(identifier); // TODO: add here text and variations auto layer = make_shared (); auto props = Layer::Props(); props.text = text; props.fontPath = identifier.fontPath; layer->setProps(props); layer->setup(); std::vector msdfVariations; for(const auto & v : variations){ msdfVariations.push_back({v.name, v.value}); } // TODO: do not add Variation to atlas, but to combo, // so we know it's dirty combo->atlas->addVariations(msdfVariations); combo->careForChild(layer); layers[layer->getId()] = layer; atlasLayerCombos[identifier] = std::move(combo); layerID = layer->getId(); } } } return layerID; } shared_ptr LayerComposition::getLayer(const LayerID & layerID){ return layers[layerID]; } void LayerComposition::draw() const { for(const auto & layer_it : layers){ layer_it.second->draw(glm::vec3(0, 0, 0)); } } }