#pragma once #include "ofMain.h" #include "ofxGPUFont.h" #include "gpufont/font.hpp" #include "gpufont/shader_catalog.hpp" static std::unique_ptr loadFont(FT_Library & library, const std::string & filename, float worldSize = 1.0f, bool hinting = false){ std::string error; FT_Face face = Font::loadFace(library, filename, error); if(error != ""){ std::cerr << "[font] failed to load " << filename << ": " << error << std::endl; return std::unique_ptr {}; } return std::make_unique (face, worldSize, hinting); } static void tryUpdateMainFont(FT_Library & library, const std::string & filename, const string & mainText, unique_ptr & mainFont, Font::BoundingBox & bb){ { auto font = loadFont(library, filename, 0.05f); if(!font){ return; } font->dilation = 0.1f; font->prepareGlyphsForText(mainText); mainFont = std::move(font); bb = mainFont->measure(0, 0, mainText); } } class ofApp : public ofBaseApp { public: struct Transform { float fovy = glm::radians(60.0f); float distance = 0.42f; glm::mat3 rotation = glm::mat3(1.0f); glm::vec3 position = glm::vec3(0.0f); glm::mat4 getProjectionMatrix(float aspect){ return glm::perspective( /* fovy = */ glm::radians(60.0f), aspect, 0.002f, 12.000f); } glm::mat4 getViewMatrix(){ auto translation = glm::translate(position); return glm::lookAt(glm::vec3(0, 0, distance), glm::vec3(0, 0, 0), glm::vec3(0, 1, 0)) * glm::mat4(rotation) * translation; } }; 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); unique_ptr font; FT_Library library; // Empty VAO used when the vertex shader has no input and only uses gl_VertexID, // because OpenGL still requires a non-zero VAO to be bound for the draw call. GLuint emptyVAO; std::unique_ptr shaderCatalog; //std::shared_ptr backgroundShader; std::shared_ptr fontShader; Font::BoundingBox bb; Transform transform; string currentFontPath; string mainText; float helpFontBaseSize = 20.0f; // Size of the window (in pixels) used for 1-dimensional anti-aliasing along each rays. // 0 - no anti-aliasing // 1 - normal anti-aliasing // >=2 - exaggerated effect int antiAliasingWindowSize = 1; // Enable a second ray along the y-axis to achieve 2-dimensional anti-aliasing. bool enableSuperSamplingAntiAliasing = true; // Draw control points for debugging (green - on curve, magenta - off curve). bool enableControlPointsVisualization = false; bool showHelp = true; };