diff --git a/example-atlas/addons.make b/example-atlas/addons.make new file mode 100644 index 0000000..ea49f4c --- /dev/null +++ b/example-atlas/addons.make @@ -0,0 +1 @@ +ofxMsdfgen diff --git a/example-atlas/bin/data/fonts/RobotoFlex.ttf b/example-atlas/bin/data/fonts/RobotoFlex.ttf new file mode 100644 index 0000000..f7cda47 Binary files /dev/null and b/example-atlas/bin/data/fonts/RobotoFlex.ttf differ diff --git a/example-atlas/src/main.cpp b/example-atlas/src/main.cpp new file mode 100644 index 0000000..8e940e9 --- /dev/null +++ b/example-atlas/src/main.cpp @@ -0,0 +1,21 @@ +#include "ofMain.h" +#include "ofApp.h" + +//======================================================================== +int main(){ + #ifdef OF_TARGET_OPENGLES + ofGLESWindowSettings settings; + //settings.setSize(1920, 1080); + settings.glesVersion = 2; + #else + ofGLWindowSettings settings; + settings.setSize(1920, 1080); + settings.setGLVersion(3, 2); + #endif + ofCreateWindow(settings); + + // this kicks off the running of my app + // can be OF_WINDOW or OF_FULLSCREEN + // pass in width and height too: + ofRunApp(new ofApp()); +} diff --git a/example-atlas/src/ofApp.cpp b/example-atlas/src/ofApp.cpp new file mode 100644 index 0000000..d6fc53d --- /dev/null +++ b/example-atlas/src/ofApp.cpp @@ -0,0 +1,84 @@ +#include "ofApp.h" +#include "ofGraphicsBaseTypes.h" +#include "ofUtils.h" + +//-------------------------------------------------------------- +void ofApp::setup(){ + string fontName = "RobotoFlex.ttf"; + string fontPath = "data/fonts/" + fontName; + atlas.setup(fontPath); + atlasImage = atlas.getAtlasImage(); +} + +//-------------------------------------------------------------- +void ofApp::update(){ + +} + +//-------------------------------------------------------------- +void ofApp::draw(){ + ofBackground(ofColor::black); + ofPushMatrix(); + ofTranslate( + ofMap(sin(ofGetElapsedTimeMillis() * 0.0001), -1, 1, 0, ofGetWidth() - atlasImage.getWidth()), + ofMap(cos(ofGetElapsedTimeMillis() * 0.0001), -1, 1, 0, ofGetHeight() - atlasImage.getHeight()), + 0); + atlasImage.draw(0, 0); + ofPopMatrix(); +} + +//-------------------------------------------------------------- +void ofApp::keyPressed(int key){ + if(key == 's'){ + } +} + +//-------------------------------------------------------------- +void ofApp::keyReleased(int key){ + +} + +//-------------------------------------------------------------- +void ofApp::mouseMoved(int x, int y){ + +} + +//-------------------------------------------------------------- +void ofApp::mouseDragged(int x, int y, int button){ + +} + +//-------------------------------------------------------------- +void ofApp::mousePressed(int x, int y, int button){ + +} + +//-------------------------------------------------------------- +void ofApp::mouseReleased(int x, int y, int button){ + +} + +//-------------------------------------------------------------- +void ofApp::mouseEntered(int x, int y){ + +} + +//-------------------------------------------------------------- +void ofApp::mouseExited(int x, int y){ + +} + +//-------------------------------------------------------------- +void ofApp::windowResized(int w, int h){ + +} + +//-------------------------------------------------------------- +void ofApp::gotMessage(ofMessage msg){ + +} + +//-------------------------------------------------------------- +void ofApp::dragEvent(ofDragInfo dragInfo){ + +} diff --git a/example-atlas/src/ofApp.h b/example-atlas/src/ofApp.h new file mode 100644 index 0000000..d5c6b69 --- /dev/null +++ b/example-atlas/src/ofApp.h @@ -0,0 +1,30 @@ +#pragma once + +#include "Atlas.h" +#include "ofMain.h" +#include "ofxMsdfgen.h" + +using namespace msdfgen; + +class ofApp : public ofBaseApp { + + public: + void setup(); + void update(); + void draw(); + + void keyPressed(int key); + void keyReleased(int key); + void mouseMoved(int x, int y); + void mouseDragged(int x, int y, int button); + void mousePressed(int x, int y, int button); + void mouseReleased(int x, int y, int button); + void mouseEntered(int x, int y); + void mouseExited(int x, int y); + void windowResized(int w, int h); + void dragEvent(ofDragInfo dragInfo); + void gotMessage(ofMessage msg); + + ofxMsdfgen::Atlas atlas; + ofImage atlasImage; +}; diff --git a/example/addons.make b/example/addons.make new file mode 100644 index 0000000..ea49f4c --- /dev/null +++ b/example/addons.make @@ -0,0 +1 @@ +ofxMsdfgen diff --git a/example/bin/data/fonts/RobotoFlex.ttf b/example/bin/data/fonts/RobotoFlex.ttf new file mode 100644 index 0000000..f7cda47 Binary files /dev/null and b/example/bin/data/fonts/RobotoFlex.ttf differ diff --git a/example/src/main.cpp b/example/src/main.cpp new file mode 100644 index 0000000..8e940e9 --- /dev/null +++ b/example/src/main.cpp @@ -0,0 +1,21 @@ +#include "ofMain.h" +#include "ofApp.h" + +//======================================================================== +int main(){ + #ifdef OF_TARGET_OPENGLES + ofGLESWindowSettings settings; + //settings.setSize(1920, 1080); + settings.glesVersion = 2; + #else + ofGLWindowSettings settings; + settings.setSize(1920, 1080); + settings.setGLVersion(3, 2); + #endif + ofCreateWindow(settings); + + // this kicks off the running of my app + // can be OF_WINDOW or OF_FULLSCREEN + // pass in width and height too: + ofRunApp(new ofApp()); +} diff --git a/example/src/ofApp.cpp b/example/src/ofApp.cpp new file mode 100644 index 0000000..0587b3a --- /dev/null +++ b/example/src/ofApp.cpp @@ -0,0 +1,160 @@ +#include "ofApp.h" +#include "generator-config.h" +#include "ofGraphics.h" +#include "ofUtils.h" +#include "save-bmp.h" + +//-------------------------------------------------------------- +void ofApp::setup(){ + string fontName = "RobotoFlex.ttf"; + fontPath = "data/fonts/" + fontName; + + int dimension = 64; + int width = dimension; + int height = dimension; + + FreetypeHandle * ft = initializeFreetype(); + if(ft){ + const char * fontPath_c_str = fontPath.c_str(); + FontHandle * font = loadFont(ft, fontPath_c_str); + if(font){ + Shape shape; + if(loadGlyph(shape, font, 'a')){ + shape.normalize(); + Shape::Bounds bounds = shape.getBounds(); + + double pxRange = 2; + Vector2 translate; + Vector2 scale = 1; + double range = 1; + double avgScale = .5 * (scale.x + scale.y); + + // Auto-frame + double l = bounds.l, b = bounds.b, r = bounds.r, t = bounds.t; + Vector2 frame(width, height); + double m = .5 + (double)0; + frame -= 2 * m * pxRange; + if(l >= r || b >= t){ + l = 0, b = 0, r = 1, t = 1; + } + if(frame.x <= 0 || frame.y <= 0){ + ofLogError("Cannot fit the specified pixel range."); + } + Vector2 dims(r - l, t - b); + if(dims.x * frame.y < dims.y * frame.x){ + translate.set(.5 * (frame.x / frame.y * dims.y - dims.x) - l, -b); + scale = avgScale = frame.y / dims.y; + }else{ + translate.set(-l, .5 * (frame.y / frame.x * dims.x - dims.y) - b); + scale = avgScale = frame.x / dims.x; + } + translate += m * pxRange / scale; + range = pxRange / std::min(scale.x, scale.y); + + // max. angle + edgeColoringSimple(shape, 3.0); + // image width, height + Bitmap msdf(dimension, dimension); + msdfgen::Projection projection(scale, translate); + msdfgen::MSDFGeneratorConfig generatorConfig; + generateMSDF(msdf, shape, projection, range, generatorConfig); + + ofxMsdfgen::toOfImage(msdf, image); + + msdfgen::saveBmp(msdf, "data/outpurt.bmp"); + + } + destroyFont(font); + } + deinitializeFreetype(ft); + } + + shader.load("ofxMsdfgen/shaders/simple/GL3/shader"); +} + +//-------------------------------------------------------------- +void ofApp::update(){ + +} + +//-------------------------------------------------------------- +void ofApp::draw(){ + ofBackground(ofColor::lightGreen); + + shader.begin(); + float pxRange = ofMap(sin(ofGetElapsedTimeMillis() * 0.001), + -1, 1, + 1, 100); + shader.setUniform1f("pxRange", pxRange); + shader.setUniformTexture("msdf", image.getTexture(), 0); + shader.setUniform4f("fontColor", ofFloatColor::white); + + image.draw(0, 0, ofGetHeight(), ofGetHeight()); + + shader.end(); + ofPushStyle(); + ofSetColor(ofColor::purple); + ofDrawBitmapString("pxRange: " + ofToString(pxRange), 20, 20); + ofPopStyle(); + + image.draw(0, 0, 64 * 4, 64 * 4); +} + +//-------------------------------------------------------------- +void ofApp::keyPressed(int key){ + if(key == 's'){ + ofSaveImage(image, "output.png"); + ofSaveImage(image, "output.jpg"); + image.save("outerput.png"); + } +} + +//-------------------------------------------------------------- +void ofApp::keyReleased(int key){ + +} + +//-------------------------------------------------------------- +void ofApp::mouseMoved(int x, int y){ + +} + +//-------------------------------------------------------------- +void ofApp::mouseDragged(int x, int y, int button){ + +} + +//-------------------------------------------------------------- +void ofApp::mousePressed(int x, int y, int button){ + +} + +//-------------------------------------------------------------- +void ofApp::mouseReleased(int x, int y, int button){ + +} + +//-------------------------------------------------------------- +void ofApp::mouseEntered(int x, int y){ + +} + +//-------------------------------------------------------------- +void ofApp::mouseExited(int x, int y){ + +} + +//-------------------------------------------------------------- +void ofApp::windowResized(int w, int h){ + +} + +//-------------------------------------------------------------- +void ofApp::gotMessage(ofMessage msg){ + +} + +//-------------------------------------------------------------- +void ofApp::dragEvent(ofDragInfo dragInfo){ + +} diff --git a/example/src/ofApp.h b/example/src/ofApp.h new file mode 100644 index 0000000..6213325 --- /dev/null +++ b/example/src/ofApp.h @@ -0,0 +1,31 @@ +#pragma once + +#include "ofMain.h" +#include "ofxMsdfgen.h" + +using namespace msdfgen; + +class ofApp : public ofBaseApp { + + public: + void setup(); + void update(); + void draw(); + + void keyPressed(int key); + void keyReleased(int key); + void mouseMoved(int x, int y); + void mouseDragged(int x, int y, int button); + void mousePressed(int x, int y, int button); + void mouseReleased(int x, int y, int button); + void mouseEntered(int x, int y); + void mouseExited(int x, int y); + void windowResized(int w, int h); + void dragEvent(ofDragInfo dragInfo); + void gotMessage(ofMessage msg); + + string fontPath; + ofImage image; + ofFloatImage fimage; + ofShader shader; +};