re-enable animation

This commit is contained in:
jrkb 2023-04-12 16:25:43 +02:00
parent b4fe28b7d5
commit 358452f98e

View file

@ -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> 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, &currentProgram);
@ -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);
}