From 1ab9d7b2cc46974eacdda71afbe5c7940d827067 Mon Sep 17 00:00:00 2001 From: themancalledjakob Date: Sat, 3 Jun 2023 17:16:02 +0200 Subject: [PATCH] atlas resolution independent scale --- src/MsdfAtlasLayerCombo.cpp | 2 ++ src/MsdfAtlasLayerCombo.h | 1 + src/MsdfLayer.cpp | 1 + src/MsdfLayer.h | 1 + 4 files changed, 5 insertions(+) diff --git a/src/MsdfAtlasLayerCombo.cpp b/src/MsdfAtlasLayerCombo.cpp index 3cfebd2..3326474 100644 --- a/src/MsdfAtlasLayerCombo.cpp +++ b/src/MsdfAtlasLayerCombo.cpp @@ -14,6 +14,7 @@ void MsdfAtlasLayerCombo::setup(const ComboIdentifier & layerIdentifier, atlasSettings.minimumScale = this->settings.minimumScale; atlasSettings.characters = ""; atlasSettings.maxInterpolationStepSize = this->settings.maxInterpolationStepSize; + scaleFactor = 64.0 / this->settings.scale; atlas = make_shared (); @@ -43,6 +44,7 @@ void MsdfAtlasLayerCombo::careForChild(shared_ptr layer){ msdfLayer->setDirtyDirty(true); msdfLayer->setAtlas(this->atlas); msdfLayer->setShader(msdfShader); + msdfLayer->scaleFactor = scaleFactor; auto & as = atlas->settings; for(const char c : layer->getProps().text){ if(as.characters.find(c) == std::string::npos){ diff --git a/src/MsdfAtlasLayerCombo.h b/src/MsdfAtlasLayerCombo.h index cf19eb0..4aac291 100644 --- a/src/MsdfAtlasLayerCombo.h +++ b/src/MsdfAtlasLayerCombo.h @@ -33,5 +33,6 @@ class MsdfAtlasLayerCombo : public AtlasLayerCombo { VFlipState vFlip; ComboIdentifier identifier; bool isDirty = false; + float scaleFactor = 1.0; }; } diff --git a/src/MsdfLayer.cpp b/src/MsdfLayer.cpp index 79d4e9b..b72fab6 100644 --- a/src/MsdfLayer.cpp +++ b/src/MsdfLayer.cpp @@ -168,6 +168,7 @@ void MsdfLayer::drawCharacter(const char character, const ofImage & atlasImage = atlas->getAtlasImage(); ofDisableAlphaBlending(); ofEnableDepthTest(); + scale *= scaleFactor; float pixelRange = 2; int atlas_w = atlasImage.getWidth(); int atlas_h = atlasImage.getHeight(); diff --git a/src/MsdfLayer.h b/src/MsdfLayer.h index 8b9d917..fd849bb 100644 --- a/src/MsdfLayer.h +++ b/src/MsdfLayer.h @@ -52,6 +52,7 @@ class MsdfLayer : public Layer { /// \brief hashed id, or just counting up string id = ""; VFlipState vFlip = V_FLIP_UNKNOWN; + float scaleFactor = 1.0; private: Props lastProps;