From 51bb04dd802c1fba4c4f7ca1efa7c1949ac95609 Mon Sep 17 00:00:00 2001 From: themancalledjakob Date: Sun, 19 Mar 2023 11:59:19 +0100 Subject: [PATCH] gles 3, use cam --- example-atlas/src/main.cpp | 2 +- example-atlas/src/ofApp.cpp | 76 +++++++++++++++++++++---------------- example-atlas/src/ofApp.h | 20 ++++++++++ 3 files changed, 64 insertions(+), 34 deletions(-) diff --git a/example-atlas/src/main.cpp b/example-atlas/src/main.cpp index 8e940e9..3577e9b 100644 --- a/example-atlas/src/main.cpp +++ b/example-atlas/src/main.cpp @@ -6,7 +6,7 @@ int main(){ #ifdef OF_TARGET_OPENGLES ofGLESWindowSettings settings; //settings.setSize(1920, 1080); - settings.glesVersion = 2; + settings.glesVersion = 3; #else ofGLWindowSettings settings; settings.setSize(1920, 1080); diff --git a/example-atlas/src/ofApp.cpp b/example-atlas/src/ofApp.cpp index 7689dd8..50653fc 100644 --- a/example-atlas/src/ofApp.cpp +++ b/example-atlas/src/ofApp.cpp @@ -2,25 +2,31 @@ #include "conversion.h" #include "import-font.h" #include "ofAppRunner.h" +#include "ofGraphics.h" #include "ofGraphicsBaseTypes.h" #include "ofUtils.h" //-------------------------------------------------------------- void ofApp::setup(){ + ofSetFrameRate(30); + ofSetVerticalSync(false); //string fontName = "RobotoFlex.ttf"; //string fontPath = "data/fonts/" + fontName; - //string fontPath = "data/celines-fonts/testing2VF.ttf"; - string fontPath = "data/celines-fonts/Cottagecore.ttf"; + string fontPath = "data/celines-fonts/testing2VF.ttf"; + //string fontPath = "data/celines-fonts/Cottagecore.ttf"; ofxMsdfgen::AtlasSettings settings; - //settings.characters = "ABCDEFGHIJKL"; + settings.characters = "ABCDEFGHIJKL"; atlas.setup(fontPath, settings); atlasImage = atlas.getAtlasImage(); glyphGeometries = atlas.getGlyphGeometries(); #ifdef TARGET_EMSCRIPTEN - shader.load("ofxMsdfgen/shaders/simple/ES3/shader"); + shader.load("ofxMsdfgen/shaders/unitRange/ES3/shader"); #else - shader.load("ofxMsdfgen/shaders/simple/GL3/shader"); + shader.load("ofxMsdfgen/shaders/unitRange/GL3/shader"); #endif + + cam.setPosition(ofGetWidth() / 2, ofGetHeight() / 2, -1000); + cam.lookAt(glm::vec3(ofGetWidth() / 2, ofGetHeight() / 2, 0)); } //-------------------------------------------------------------- @@ -31,6 +37,9 @@ void ofApp::update(){ //-------------------------------------------------------------- void ofApp::draw(){ ofBackground(ofColor::lightBlue); + cam.begin(); + ofEnableDepthTest(); + ofEnableAlphaBlending(); ofPushMatrix(); ofTranslate( ofMap(sin(ofGetElapsedTimeMillis() * 0.0001), -1, 1, 0, ofGetWidth() - atlasImage.getWidth()), @@ -52,42 +61,43 @@ void ofApp::draw(){ //for(int c = 0; c < word.length(); c++){ //unicode_t character = word[c]; //const ofxMsdfgen::GlyphGeometry & glyphGeometry = glyphGeometries[0]; - float pxRange = 2.0; - for(const auto & glyphGeometry : glyphGeometries){ - //if(glyphGeometry.getCodepoint() == character){ - word += glyphGeometry.getCodepoint(); - float x = 0; - float y = 0; - float w = glyphGeometry.getBoxRect().w; - float h = glyphGeometry.getBoxRect().h; - glm::vec2 unitRange = glm::vec2(pxRange) / glm::vec2(w, h); - shader.setUniform2f("unitRange", unitRange); - float sx = glyphGeometry.getBoxRect().x; - float sy = glyphGeometry.getBoxRect().y; - float sw = glyphGeometry.getBoxRect().w; - float sh = glyphGeometry.getBoxRect().h; - if(tx + w > ofGetWidth()){ - ty += 100; - tx = 0; + int amount = 0; + float mouser = ofGetMousePressed() ? ofMap(ofGetMouseX(), 0, ofGetWidth(), 0.001, 1) : 1; + for(int iz = 0; iz < 3; iz++){ + tx = 0; + ty = 0; + for(int i = 0; i < 42; i++){ + for(const auto & glyphGeometry : glyphGeometries){ + word += glyphGeometry.getCodepoint(); + int x, y, w, h; + glyphGeometry.getBoxRect(x, y, w, h); + glm::vec2 unitRange = glm::vec2(atlas.settings.pixelRange) / glm::vec2(w, h); + shader.setUniform2f("unitRange", unitRange * mouser); + if(tx + w > ofGetWidth()){ + ty += atlas.settings.scale * 2; + tx = 0; + } + ofPushMatrix(); + ofTranslate(tx, ty, 0); + atlasImage.drawSubsection(0, 0, w, h, x, y, w, h); + ofPopMatrix(); + tx += atlas.settings.scale; + amount++; + } } - ofPushMatrix(); - //ofTranslate(tx, ty, 0); - atlasImage.drawSubsection(x, y, w, h, sx, sy, sw, sh); - ofPopMatrix(); - //ofTranslate(glyphGeometry.getAdvance() * atlas.settings.scale, 0, 0); - ofTranslate(atlas.settings.scale, 0, 0); - tx += glyphGeometry.getAdvance() * atlas.settings.scale; - //} + ofTranslate(0, 0, 100); } - //} ofPopMatrix(); + ofDisableAlphaBlending(); + ofDisableDepthTest(); + cam.end(); shader.end(); ofPushStyle(); ofSetColor(ofColor::purple); - ofDrawBitmapString("pxRange: " + ofToString(pxRange) + "\n" - + "glyph amount: " + ofToString(glyphGeometries.size()) + "\n" + ofDrawBitmapString("glyph amount: " + ofToString(amount) + "\n" + "word: " + word + "\n" + + "mouser: " + ofToString(mouser) + "\n" + "fps: " + ofToString(ofGetFrameRate()), 20, 20); ofPopStyle(); } diff --git a/example-atlas/src/ofApp.h b/example-atlas/src/ofApp.h index d647508..64c3b77 100644 --- a/example-atlas/src/ofApp.h +++ b/example-atlas/src/ofApp.h @@ -3,10 +3,26 @@ #include "Atlas.h" #include "conversion.h" #include "ofMain.h" +#include "ofQuaternion.h" #include "ofxMsdfgen.h" +#include using namespace msdfgen; +struct AtlasLetter { + int x, y, w, h; + glm::vec2 unitRange; + void draw(const ofImage & image, + const ofShader & shader){ + shader.setUniform2f("unitRange", unitRange); + image.drawSubsection(0, 0, w, h, x, y, w, h); + } +}; +struct DrawnLetter { + glm::vec3 position; + glm::quat orientation; +}; + class ofApp : public ofBaseApp { public: @@ -30,4 +46,8 @@ class ofApp : public ofBaseApp { ofImage atlasImage; vector glyphGeometries; ofShader shader; + ofEasyCam cam; + unordered_map atlasLetters; + std::vector drawnLetters; + std::vector drawOrder; };