From 5456033ccfbc042b2c4ba0bb9c9d471654a05a7f Mon Sep 17 00:00:00 2001 From: themancalledjakob Date: Wed, 12 Apr 2023 15:47:40 +0200 Subject: [PATCH] worldSize playaround --- src/GPUFontAtlasLayerCombo.cpp | 52 +++++++++++++++++++++------------- 1 file changed, 33 insertions(+), 19 deletions(-) diff --git a/src/GPUFontAtlasLayerCombo.cpp b/src/GPUFontAtlasLayerCombo.cpp index de76501..e2789a3 100644 --- a/src/GPUFontAtlasLayerCombo.cpp +++ b/src/GPUFontAtlasLayerCombo.cpp @@ -1,6 +1,7 @@ #include "GPUFontAtlasLayerCombo.h" #include "Utils.h" #include "ofColor.h" +#include "ofEvents.h" namespace ofxVariableLab { @@ -46,20 +47,20 @@ void GPUFontAtlasLayerCombo::setup(const ComboIdentifier & identifier){ cout << "Render type " << r->getType() << endl; } void GPUFontAtlasLayerCombo::update(){ - float animationSpeed = ofMap(sin(ofGetElapsedTimef() * 0.01), -1, 1, 0.0, 2); - float threshold = 5.0; - for(int i = 0; i < fontVariationAxes.size(); i++){ - ofxGPUFont::Font::FontVariationAxis & axis = fontVariationAxes[i]; - ofxGPUFont::Font::FontVariationAxisParameters & axisParams = fontVariationAxesParameters[i]; - double newValue = ofMap(sin(ofGetElapsedTimef() * animationSpeed), - -1, 1, - axisParams.minValue, axisParams.maxValue); - if(abs(newValue - axis.value) > threshold){ - font->setFontVariationAxis(library, axis.name, newValue); - axis.value = newValue; - font->prepareGlyphsForText(mainText, true); - } - } + //float animationSpeed = ofMap(sin(ofGetElapsedTimef() * 0.01), -1, 1, 0.0, 2); + //float threshold = 5.0; + //for(int i = 0; i < fontVariationAxes.size(); i++){ + //ofxGPUFont::Font::FontVariationAxis & axis = fontVariationAxes[i]; + //ofxGPUFont::Font::FontVariationAxisParameters & axisParams = fontVariationAxesParameters[i]; + //double newValue = ofMap(sin(ofGetElapsedTimef() * animationSpeed), + //-1, 1, + //axisParams.minValue, axisParams.maxValue); + //if(abs(newValue - axis.value) > threshold){ + //font->setFontVariationAxis(library, axis.name, newValue); + //axis.value = newValue; + //font->prepareGlyphsForText(mainText, true); + //} + //} } void GPUFontAtlasLayerCombo::careForChild(shared_ptr layer){ } @@ -77,10 +78,21 @@ void GPUFontAtlasLayerCombo::draw(){ int width = ofGetWidth(); int height = ofGetHeight(); + glm::vec2 mouse = glm::vec2(ofGetMouseX(), ofGetMouseY()); + + float targetFontSize = ofGetFrameNum() % 100 < 50 ? 42 : 420; + + float worldSize = targetFontSize / (float)width; + + font->setWorldSize(worldSize); + + float width_unit = 1; + float height_unit = (float)height / width; //ofClear(125, 255, 125, 255); - glm::mat4 projection = transform.getProjectionMatrix((float)width / height); + //glm::mat4 projection = transform.getProjectionMatrix((float)width / height); + glm::mat4 projection = transform.getOrthoProjectionMatrix(width_unit, height_unit); glm::mat4 view = transform.getViewMatrix(); glm::mat4 model = glm::mat4(1.0f); @@ -132,19 +144,21 @@ void GPUFontAtlasLayerCombo::draw(){ glUniform1i(location, enableControlPointsVisualization); + float mx = ofMap(mouse.x, 0, width, -0.5 * width_unit, 0.5 * width_unit); + float my = ofMap(mouse.y, 0, height, -0.5 * height_unit, 0.5 * height_unit); cx = 0.5f * (bb.minX + bb.maxX); cy = 0.5f * (bb.minY + bb.maxY); //ofRectangle rectangle(0, 0, width, height); //ofDrawRectangle(rectangle); - font->draw(-cx, -cy, 0, mainText); + font->draw(mx, my, 0, mainText, vFlip == V_FLIP_ON); glUseProgram(currentProgram); } glDisable(GL_BLEND); - ofDrawBitmapStringHighlight( - "this is where your font could be" - , -cx, -cy, ofFloatColor::pink, ofFloatColor::black); + //ofDrawBitmapStringHighlight( + //(ofToString("and we know:") + ofToString("everything")) + //, 100 + mouse.x, mouse.y, ofFloatColor::pink, ofFloatColor::black); ofDrawBitmapStringHighlight( "fps: " + ofToString(ofGetFrameRate()) + "\n"