From bbb622f555cca2a682563ee67ae648f19419c94c Mon Sep 17 00:00:00 2001 From: Alexander Bock Date: Mon, 2 Nov 2015 21:40:45 -0500 Subject: [PATCH] Initial work on integrating fontrendering into ghoul --- ext/ghoul | 2 +- include/openspace/engine/openspaceengine.h | 11 ++++++- include/openspace/rendering/renderengine.h | 8 ++++- include/openspace/util/keys.h | 3 ++ src/engine/openspaceengine.cpp | 37 ++++++++++++++++++++++ src/rendering/renderengine.cpp | 16 +++++++++- 6 files changed, 73 insertions(+), 4 deletions(-) diff --git a/ext/ghoul b/ext/ghoul index f9c8ce793b..42837d0083 160000 --- a/ext/ghoul +++ b/ext/ghoul @@ -1 +1 @@ -Subproject commit f9c8ce793b58062b2b6c8973f50f22b9ecd89436 +Subproject commit 42837d00835a618643a5e237241d9e3310feaf4d diff --git a/include/openspace/engine/openspaceengine.h b/include/openspace/engine/openspaceengine.h index 62ea47e478..f44b4cb4ad 100644 --- a/include/openspace/engine/openspaceengine.h +++ b/include/openspace/engine/openspaceengine.h @@ -27,12 +27,14 @@ #include -#include #include #include #include +#include +#include + #include #include @@ -40,6 +42,10 @@ namespace ghoul { namespace cmdparser { class CommandlineParser; } +namespace fontrendering { + class FontManager; +} + } namespace openspace { @@ -95,6 +101,7 @@ public: network::ParallelConnection* parallelConnection(); properties::PropertyOwner* globalPropertyOwner(); WindowWrapper& windowWrapper(); + ghoul::fontrendering::FontManager& fontManager(); gui::GUI* gui(); @@ -128,6 +135,7 @@ private: bool gatherCommandlineArguments(); bool loadSpiceKernels(); void loadFonts(); + void loadFonts2(); void runScripts(const ghoul::Dictionary& scripts); void runStartupScripts(); void configureLogging(); @@ -145,6 +153,7 @@ private: gui::GUI* _gui; network::ParallelConnection* _parallelConnection; WindowWrapper* _windowWrapper; + ghoul::fontrendering::FontManager*_fontManager; properties::PropertyOwner* _globalPropertyNamespace; diff --git a/include/openspace/rendering/renderengine.h b/include/openspace/rendering/renderengine.h index df1a5651fa..ec05ed1035 100644 --- a/include/openspace/rendering/renderengine.h +++ b/include/openspace/rendering/renderengine.h @@ -31,7 +31,11 @@ #include namespace ghoul { - class SharedMemory; +namespace fontrendering { + class Font; +} + +class SharedMemory; } namespace openspace { @@ -131,6 +135,8 @@ private: bool _doPerformanceMeasurements; ghoul::SharedMemory* _performanceMemory; + + ghoul::fontrendering::Font* _mainFont; void generateGlslConfig(); diff --git a/include/openspace/util/keys.h b/include/openspace/util/keys.h index 60ba85011b..65cde31f49 100644 --- a/include/openspace/util/keys.h +++ b/include/openspace/util/keys.h @@ -57,6 +57,9 @@ // All values that are defined here are compatible with (and are based on) the // definitions GLFW v3.1 +#include +#include + namespace openspace { enum class KeyAction { diff --git a/src/engine/openspaceengine.cpp b/src/engine/openspaceengine.cpp index aaffd14cae..27d21eaaf2 100644 --- a/src/engine/openspaceengine.cpp +++ b/src/engine/openspaceengine.cpp @@ -57,6 +57,7 @@ #include #include #include +#include // std #include @@ -405,6 +406,7 @@ bool OpenSpaceEngine::initialize() { // Load a light and a monospaced font loadFonts(); + loadFonts2(); LINFO("Initializing GUI"); _gui->initialize(); @@ -577,6 +579,36 @@ void OpenSpaceEngine::loadFonts() { } } +void OpenSpaceEngine::loadFonts2() { + ghoul::Dictionary fonts; + configurationManager()->getValue(ConfigurationManager::KeyFonts, fonts); + + _fontManager = new ghoul::fontrendering::FontManager; + for (const std::string& key : fonts.keys()) { + std::string font; + fonts.getValue(key, font); + font = absPath(font); + + if(!FileSys.fileExists(font)) { + LERROR("Could not find font '" << font << "'"); + continue; + } + + LINFO("Registering font '" << font << "' with key '" << key << "'"); + bool success = _fontManager->registerFont(key, font); + + if (!success) + LERROR("Error registering font '" << font << "' with key '" << key << "'"); + } + + bool initSuccess = ghoul::fontrendering::FontRenderer::initialize(); + if (!initSuccess) + LERROR("Error initializing default font renderer"); + + ghoul::fontrendering::FontRenderer::defaultRenderer()->setWindowSize(glm::vec2(_windowWrapper->currentWindowSize())); + +} + void OpenSpaceEngine::configureLogging() { if (configurationManager()->hasKeyAndValue(ConfigurationManager::KeyLogLevel)) { std::string logLevel; @@ -837,5 +869,10 @@ WindowWrapper& OpenSpaceEngine::windowWrapper() { ghoul_assert(_windowWrapper, "Window Wrapper"); return *_windowWrapper; } + +ghoul::fontrendering::FontManager& OpenSpaceEngine::fontManager() { + ghoul_assert(_fontManager, "Font Manager"); + return *_fontManager; +} } // namespace openspace diff --git a/src/rendering/renderengine.cpp b/src/rendering/renderengine.cpp index cae6430530..e9e9553d00 100644 --- a/src/rendering/renderengine.cpp +++ b/src/rendering/renderengine.cpp @@ -50,6 +50,8 @@ #include #include #include +#include +#include #include #ifdef GHOUL_USE_DEVIL @@ -199,6 +201,8 @@ bool RenderEngine::initializeGL() { // development OsEng.windowWrapper().setNearFarClippingPlane(0.001f, 1000.f); + _mainFont = OsEng.fontManager().font(constants::fonts::keyMono, 10); + // ALL OF THIS HAS TO BE CHECKED // ---abock @@ -457,7 +461,17 @@ void RenderEngine::render(const glm::mat4 &projectionMatrix, const glm::mat4 &vi glm::vec4 targetColor(0.00, 0.75, 1.00, 1); double dt = Time::ref().deltaTime(); - PrintColorTextArg(line++, "Simulation increment (s): %.0f", 10, glm::vec4(1), dt); + + using namespace ghoul::fontrendering; + FontRenderer::defaultRenderer()->render( + *_mainFont, + glm::vec2(10.f, static_cast(startY / 2 - font_size_mono * line++ * 2)), + glm::vec4(1.f), + "Simulation increment (s): %.0f", + dt + ); + +// PrintColorTextArg(line++, "Simulation increment (s): %.0f", 10, glm::vec4(1), dt); psc nhPos; double lt;