From 358452f98efb632306adffc46d125ca78fbccbcd Mon Sep 17 00:00:00 2001 From: themancalledjakob Date: Wed, 12 Apr 2023 16:25:43 +0200 Subject: [PATCH] re-enable animation --- src/GPUFontAtlasLayerCombo.cpp | 43 ++++++++++++++++++++-------------- 1 file changed, 26 insertions(+), 17 deletions(-) diff --git a/src/GPUFontAtlasLayerCombo.cpp b/src/GPUFontAtlasLayerCombo.cpp index 1722e8c..7882c28 100644 --- a/src/GPUFontAtlasLayerCombo.cpp +++ b/src/GPUFontAtlasLayerCombo.cpp @@ -2,6 +2,8 @@ #include "Utils.h" #include "ofColor.h" #include "ofEvents.h" +#include "ofGraphics.h" +#include "ofUtils.h" namespace ofxVariableLab { @@ -47,20 +49,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.1, 2); + float threshold = 1.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){ } @@ -80,7 +82,7 @@ void GPUFontAtlasLayerCombo::draw(){ int height = ofGetHeight(); glm::vec2 mouse = glm::vec2(ofGetMouseX(), ofGetMouseY()); - float targetFontSize = ofGetFrameNum() % 100 < 50 ? 42 : 420; + float targetFontSize = 128; float worldSize = targetFontSize / (float)width; @@ -111,6 +113,8 @@ void GPUFontAtlasLayerCombo::draw(){ glEnable(GL_BLEND); glBlendEquation(GL_FUNC_ADD); glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA); + ofDisableDepthTest(); + ofEnableAlphaBlending(); int currentProgram; glGetIntegerv(GL_CURRENT_PROGRAM, ¤tProgram); @@ -136,7 +140,7 @@ void GPUFontAtlasLayerCombo::draw(){ glUniform1f(location, z); location = glGetUniformLocation(fontShaderProgram, "color"); - glUniform4f(location, 1.0f, 0.0f, 1.0f, 1.0f); + glUniform4f(location, 1.0f, 0.0f, 0.0f, 0.5f); location = glGetUniformLocation(fontShaderProgram, "antiAliasingWindowSize"); glUniform1f(location, (float)antiAliasingWindowSize); @@ -152,7 +156,12 @@ void GPUFontAtlasLayerCombo::draw(){ cy = 0.5f * (bb.minY + bb.maxY); //ofRectangle rectangle(0, 0, width, height); //ofDrawRectangle(rectangle); - font->draw(mouse.x, mouse.y, 0, mainText, vFlip == V_FLIP_ON); + font->draw(mouse.x, mouse.y - (200 * sin(ofGetElapsedTimef() * 0.25)), 0, "what", vFlip == V_FLIP_ON); + location = glGetUniformLocation(fontShaderProgram, "color"); + glUniform4f(location, 0.0f, 1.0f, 0.0f, 0.5f); + font->draw(mouse.x, mouse.y, 0, "ever", vFlip == V_FLIP_ON); + glUniform4f(location, 0.0f, 0.0f, 1.0f, 0.5f); + font->draw(mouse.x, mouse.y + (200 * sin(ofGetElapsedTimef() * 0.25)), 0, "verraw", vFlip == V_FLIP_ON); glUseProgram(currentProgram); }