From dce5e7c57a26ca9c07fd414d04ed7bb97d29f14c Mon Sep 17 00:00:00 2001 From: themancalledjakob Date: Thu, 13 Apr 2023 12:56:17 +0200 Subject: [PATCH] fun with ofxGPUfont (single draw call for multiple texts) --- src/GPUFontAtlasLayerCombo.cpp | 49 +++++++++++++++++++++++++++------- 1 file changed, 39 insertions(+), 10 deletions(-) diff --git a/src/GPUFontAtlasLayerCombo.cpp b/src/GPUFontAtlasLayerCombo.cpp index c7bdfab..87ce86b 100644 --- a/src/GPUFontAtlasLayerCombo.cpp +++ b/src/GPUFontAtlasLayerCombo.cpp @@ -56,7 +56,7 @@ void GPUFontAtlasLayerCombo::update(){ //shaderCatalog->update(); //} //#endif - float animationSpeed = ofMap(sin(ofGetElapsedTimef() * 0.01), -1, 1, 0.1, 2); + float animationSpeed = 1.0; float threshold = 1.0; for(int i = 0; i < fontVariationAxes.size(); i++){ ofxGPUFont::Font::FontVariationAxis & axis = fontVariationAxes[i]; @@ -144,7 +144,7 @@ void GPUFontAtlasLayerCombo::draw(){ glUniform1f(location, z); location = glGetUniformLocation(fontShaderProgram, "color"); - glUniform4f(location, 1.0f, 0.0f, 0.0f, 0.5f); + glUniform4f(location, 1.0f, 1.0f, 1.0f, 0.5f); location = glGetUniformLocation(fontShaderProgram, "antiAliasingWindowSize"); glUniform1f(location, (float)antiAliasingWindowSize); @@ -156,18 +156,47 @@ void GPUFontAtlasLayerCombo::draw(){ //mouse.x = 0; //mouse.y = 0; - 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); + std::vector vertices; + std::vector indices; + string text = "whatever"; + int n_texts = 240; + vertices.resize(text.length() * n_texts * 4); + indices.resize(text.length() * n_texts * 6); cx = 0.5f * (bb.minX + bb.maxX); cy = 0.5f * (bb.minY + bb.maxY); + + for(int i = 0; i < n_texts - 1; i++){ + float pipi = ((PI * 2 * i) / (n_texts - 1)); + float shift = (400 * cos(ofGetElapsedTimef() * 0.125 + pipi)); + float shift_x = (600 * sin(ofGetElapsedTimef() * 0.125 + pipi)); + float shift_o = (100 * sin(ofGetElapsedTimef() * 0.4 + pipi)); + font->collectVerticesAndIndices( + glm::vec3(mouse.x + shift_x, + mouse.y + shift + shift_o, + 0), + text, + vertices, + indices, + true, + int(ofMap(sin(ofGetElapsedTimef() + pipi), -1, 1, 42, 96))); + } + font->collectVerticesAndIndices( + glm::vec3(mouse.x, + mouse.y, + 0), + text, + vertices, + indices, + true, + ofMap(sin(ofGetElapsedTimef() * 0.25f), -1.0f, 1.0f, 42.0f, 96.0f)); + font->draw(vertices, indices); //ofRectangle rectangle(0, 0, width, height); //ofDrawRectangle(rectangle); - font->draw(mouse.x, mouse.y - (200 * sin(ofGetElapsedTimef() * 0.25)), 0, "what", vFlip == V_FLIP_ON, 128.0f); - 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, 64.0f); - 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, 256.0f); + //font->draw(mouse.x, mouse.y - (200 * sin(ofGetElapsedTimef() * 0.25)), 0, "what", vFlip == V_FLIP_ON, 42.0f); + //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, 420.0f); + glUseProgram(currentProgram); }