From a7807e5581077fe1a539f82da2a44f7da6c1e0ff Mon Sep 17 00:00:00 2001 From: Alexander Bock Date: Fri, 13 Nov 2015 18:18:42 -0500 Subject: [PATCH 1/4] Updated Ghoul version --- ext/ghoul | 2 +- src/engine/openspaceengine.cpp | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/ext/ghoul b/ext/ghoul index e2170b1bd2..f9fade558b 160000 --- a/ext/ghoul +++ b/ext/ghoul @@ -1 +1 @@ -Subproject commit e2170b1bd2acdd46a23029729b8fbad18fa39c69 +Subproject commit f9fade558b471e67371ee5e55442d9c397d3ff7c diff --git a/src/engine/openspaceengine.cpp b/src/engine/openspaceengine.cpp index 3410f646f9..71efb9b864 100644 --- a/src/engine/openspaceengine.cpp +++ b/src/engine/openspaceengine.cpp @@ -584,6 +584,7 @@ void OpenSpaceEngine::loadFonts2() { configurationManager()->getValue(ConfigurationManager::KeyFonts, fonts); _fontManager = new ghoul::fontrendering::FontManager; + for (const std::string& key : fonts.keys()) { std::string font; fonts.getValue(key, font); From 2cf7dfb27df87e77aa88d7e06d88995f95bfda15 Mon Sep 17 00:00:00 2001 From: Alexander Bock Date: Mon, 16 Nov 2015 19:21:05 -0500 Subject: [PATCH 2/4] Changed RenderEngine to use Ghoul fontrendering instead of SGCT --- ext/ghoul | 2 +- include/openspace/rendering/renderengine.h | 2 - src/engine/openspaceengine.cpp | 3 +- src/rendering/renderengine.cpp | 469 ++++++++++++--------- src/util/time.cpp | 1 - 5 files changed, 266 insertions(+), 211 deletions(-) diff --git a/ext/ghoul b/ext/ghoul index f9fade558b..f6dbd18a66 160000 --- a/ext/ghoul +++ b/ext/ghoul @@ -1 +1 @@ -Subproject commit f9fade558b471e67371ee5e55442d9c397d3ff7c +Subproject commit f6dbd18a665b3b13cef7f70310f1c6fc416a7c5f diff --git a/include/openspace/rendering/renderengine.h b/include/openspace/rendering/renderengine.h index ec05ed1035..c0a517ae1d 100644 --- a/include/openspace/rendering/renderengine.h +++ b/include/openspace/rendering/renderengine.h @@ -136,8 +136,6 @@ private: bool _doPerformanceMeasurements; ghoul::SharedMemory* _performanceMemory; - ghoul::fontrendering::Font* _mainFont; - void generateGlslConfig(); float _globalBlackOutFactor; diff --git a/src/engine/openspaceengine.cpp b/src/engine/openspaceengine.cpp index 71efb9b864..071dea96b5 100644 --- a/src/engine/openspaceengine.cpp +++ b/src/engine/openspaceengine.cpp @@ -583,7 +583,8 @@ void OpenSpaceEngine::loadFonts2() { ghoul::Dictionary fonts; configurationManager()->getValue(ConfigurationManager::KeyFonts, fonts); - _fontManager = new ghoul::fontrendering::FontManager; + const glm::ivec3 fontAtlasSize{1024, 1024, 1}; + _fontManager = new ghoul::fontrendering::FontManager(fontAtlasSize); for (const std::string& key : fonts.keys()) { std::string font; diff --git a/src/rendering/renderengine.cpp b/src/rendering/renderengine.cpp index da8a05b227..9d03f449bf 100644 --- a/src/rendering/renderengine.cpp +++ b/src/rendering/renderengine.cpp @@ -201,8 +201,6 @@ bool RenderEngine::initializeGL() { // development OsEng.windowWrapper().setNearFarClippingPlane(0.001f, 1000.f); - _mainFont = OsEng.fontManager().font(constants::fonts::keyMono, 20); - // ALL OF THIS HAS TO BE CHECKED // ---abock @@ -420,238 +418,297 @@ void RenderEngine::render(const glm::mat4 &projectionMatrix, const glm::mat4 &vi // Print some useful information on the master viewport if (OsEng.ref().isMaster() && OsEng.windowWrapper().isSimpleRendering()) { - // TODO: Adjust font_size properly when using retina screen - const int font_size_mono = 10; - const int font_size_time = 15; - const int font_size_light = 8; - const int font_with_light = static_cast(font_size_light*0.7); - const sgct_text::Font* fontLight = sgct_text::FontManager::instance()->getFont(constants::fonts::keyLight, font_size_light); - const sgct_text::Font* fontMono = sgct_text::FontManager::instance()->getFont(constants::fonts::keyMono, font_size_mono); - const sgct_text::Font* fontTime = sgct_text::FontManager::instance()->getFont(constants::fonts::keyMono, font_size_time); + // TODO: Adjust font_size properly when using retina screen + const float fontSizeMono = 10.f; + const float fontSizeTime = 15.f; - if (_showInfo) { - const sgct_text::Font* font = fontMono; - glm::ivec4 pixelCoords = OsEng.windowWrapper().viewportPixelCoordinates(); - int x1 = pixelCoords.x; - int xSize = pixelCoords.y; - int y1 = pixelCoords.z; - int ySize = pixelCoords.w; - int startY = ySize - 2 * font_size_time; - //const glm::vec2& scaling = _mainCamera->scaling(); - //const glm::vec3& viewdirection = _mainCamera->viewDirection(); - //const psc& position = _mainCamera->position(); - //const psc& origin = OsEng.interactionHandler()->focusNode()->worldPosition(); - //const PowerScaledScalar& pssl = (position - origin).length(); - - // Next 2 lines neccesary for instrument switching to work. - // GUI PRINT - // Using a macro to shorten line length and increase readability + using Font = ghoul::fontrendering::Font; + using ghoul::fontrendering::RenderFont; + + Font* fontMono = OsEng.fontManager().font(constants::fonts::keyMono, fontSizeMono); + Font* fontTime = OsEng.fontManager().font(constants::fonts::keyMono, fontSizeTime); + + if (fontMono && fontTime) { + if (_showInfo) { + double currentTime = Time::ref().currentTime(); + + glm::vec2 penPosition = glm::vec2(10.f, OsEng.windowWrapper().viewportPixelCoordinates().w); - int line = 0; - - double currentTime = Time::ref().currentTime(); + penPosition.y -= fontTime->height(); + RenderFont(fontTime, + penPosition, + "Date: %s", + Time::ref().currentTimeUTC().c_str() + ); + + penPosition.y -= fontMono->height(); + RenderFont(fontMono, + penPosition, + "Simulation increment (s): %.0f", + Time::ref().deltaTime() + ); - //PrintText(line++, "Date: %s", Time::ref().currentTimeUTC().c_str()); - std::string timeString = Time::ref().currentTimeUTC(); - if (timeString.size() > 11) - // This should never happen, but it's an emergency hack ---abock - timeString[11] = ' '; -// Freetype::print(fontTime, 10, static_cast(startY - font_size_mono * line++ * 2), glm::vec4(1), "Date: %s", timeString.c_str()); - Freetype::print(fontTime, 10, static_cast(startY - font_size_mono * line++ * 2), "Date: %s", timeString.c_str()); - - glm::vec4 targetColor(0.00, 0.75, 1.00, 1); - double dt = Time::ref().deltaTime(); - - if (_mainFont) { - using namespace ghoul::fontrendering; - FontRenderer::defaultRenderer().render( - *_mainFont, - glm::vec2(10.f, static_cast(startY - font_size_mono * line++ * 2)), - glm::vec4(1.f), - glm::vec4(0.f, 0.f, 0.f, 1.f), - "Simulation increment (s): %.0f", - dt - ); - } + + glm::vec4 targetColor(0.00, 0.75, 1.00, 1); -// PrintColorTextArg(line++, "Simulation increment (s): %.0f", 10, glm::vec4(1), dt); + psc nhPos; + double lt; + SpiceManager::ref().getTargetPosition("PLUTO", "NEW HORIZONS", "GALACTIC", "NONE", currentTime, nhPos, lt); + float a, b, c; + SpiceManager::ref().getPlanetEllipsoid("PLUTO", a, b, c); + float radius = (a + b) / 2.f; + float distToSurf = glm::length(nhPos.vec3()) - radius; + + penPosition.y -= fontMono->height(); + RenderFont(fontMono, + penPosition, + "Distance to Pluto: % .1f (KM)", + distToSurf + ); + + penPosition.y -= fontMono->height(); + RenderFont(fontMono, + penPosition, + "Avg. Frametime: %.5f", + OsEng.windowWrapper().averageDeltaTime() + ); + + + #ifdef OPENSPACE_MODULE_NEWHORIZONS_ENABLED + if (openspace::ImageSequencer2::ref().isReady()) { + double remaining = openspace::ImageSequencer2::ref().getNextCaptureTime() - currentTime; + float t = static_cast(1.0 - remaining / openspace::ImageSequencer2::ref().getIntervalLength()); + std::string progress = "|"; + int g = static_cast((t* 24) + 1); + g = std::max(g, 0); + for (int i = 0; i < g; i++) + progress.append("-"); + progress.append(">"); + for (int i = 0; i < 25 - g; i++) + progress.append(" "); - psc nhPos; - double lt; - SpiceManager::ref().getTargetPosition("PLUTO", "NEW HORIZONS", "GALACTIC", "NONE", currentTime, nhPos, lt); - //nhPos[3] += 3; - float a, b, c; - SpiceManager::ref().getPlanetEllipsoid("PLUTO", a, b, c); - float radius = (a + b) / 2.f; + std::string str = ""; + openspace::SpiceManager::ref().getDateFromET(openspace::ImageSequencer2::ref().getNextCaptureTime(), str, "YYYY MON DD HR:MN:SC"); - float distToSurf = glm::length(nhPos.vec3()) - radius; - PrintText(line++, "Distance to Pluto: % .1f (KM)", distToSurf); + glm::vec4 active(0.6, 1, 0.00, 1); + glm::vec4 brigther_active(0.9, 1, 0.75, 1); - PrintText(line++, "Avg. Frametime: %.5f", OsEng.windowWrapper().averageDeltaTime()); - - //PrintText(line++, "Drawtime: %.5f", sgct::Engine::instance()->getDrawTime()); - //PrintText(line++, "Frametime: %.5f", sgct::Engine::instance()->getDt()); - //PrintText(i++, "Origin: (% .5f, % .5f, % .5f, % .5f)", origin[0], origin[1], origin[2], origin[3]); - //PrintText(i++, "Cam pos: (% .5f, % .5f, % .5f, % .5f)", position[0], position[1], position[2], position[3]); - //PrintText(i++, "View dir: (% .5f, % .5f, % .5f)", viewdirection[0], viewdirection[1], viewdirection[2]); - //PrintText(i++, "Cam->origin: (% .15f, % .4f)", pssl[0], pssl[1]); - //PrintText(i++, "Scaling: (% .5f, % .5f)", scaling[0], scaling[1]); + progress.append("|"); + if (remaining > 0) { + brigther_active *= (1 - t); + + penPosition.y -= fontMono->height(); + RenderFont(fontMono, + penPosition, + active * t + brigther_active, + "Next instrument activity:" + ); + + penPosition.y -= fontMono->height(); + RenderFont(fontMono, + penPosition, + active * t + brigther_active, + "%.0f s %s %.1f %%", + remaining, progress.c_str(), t * 100 + ); -#ifdef OPENSPACE_MODULE_NEWHORIZONS_ENABLED - if (openspace::ImageSequencer2::ref().isReady()) { - double remaining = openspace::ImageSequencer2::ref().getNextCaptureTime() - currentTime; - float t = static_cast(1.0 - remaining / openspace::ImageSequencer2::ref().getIntervalLength()); - std::string progress = "|"; - int g = static_cast((t* 24) + 1); - g = std::max(g, 0); - for (int i = 0; i < g; i++) - progress.append("-"); - progress.append(">"); - for (int i = 0; i < 25 - g; i++) - progress.append(" "); + penPosition.y -= fontMono->height(); + RenderFont(fontMono, + penPosition, + active, + "Data acquisition time: %s", + str.c_str() + ); + } + std::pair nextTarget = ImageSequencer2::ref().getNextTarget(); + std::pair currentTarget = ImageSequencer2::ref().getCurrentTarget(); - std::string str = ""; - openspace::SpiceManager::ref().getDateFromET(openspace::ImageSequencer2::ref().getNextCaptureTime(), str, "YYYY MON DD HR:MN:SC"); + if (currentTarget.first > 0.0) { + int timeleft = static_cast(nextTarget.first - currentTime); - glm::vec4 active(0.6, 1, 0.00, 1); - glm::vec4 brigther_active(0.9, 1, 0.75, 1); + int hour = timeleft / 3600; + int second = timeleft % 3600; + int minute = second / 60; + second = second % 60; - progress.append("|"); - if (remaining > 0) { - brigther_active *= (1 - t); - PrintColorText(line++, "Next instrument activity:", 10, active*t + brigther_active); - PrintColorTextArg(line++, "%.0f s %s %.1f %%", 10, active*t + brigther_active, remaining, progress.c_str(), t * 100); - PrintColorTextArg(line++, "Data acquisition time: %s", 10, active, str.c_str()); - } - std::pair nextTarget = ImageSequencer2::ref().getNextTarget(); - std::pair currentTarget = ImageSequencer2::ref().getCurrentTarget(); + std::string hh, mm, ss, coundtown; - if (currentTarget.first > 0.0) { - int timeleft = static_cast(nextTarget.first - currentTime); + if (hour < 10) hh.append("0"); + if (minute < 10) mm.append("0"); + if (second < 10) ss.append("0"); - int hour = timeleft / 3600; - int second = timeleft % 3600; - int minute = second / 60; - second = second % 60; + hh.append(std::to_string(hour)); + mm.append(std::to_string(minute)); + ss.append(std::to_string(second)); + + penPosition.y -= fontMono->height(); + RenderFont(fontMono, + penPosition, + targetColor, + "Data acquisition adjacency: [%s:%s:%s]", + hh.c_str(), mm.c_str(), ss.c_str() + ); - std::string hh, mm, ss, coundtown; + + penPosition.y -= fontMono->height(); + std::pair> incidentTargets = ImageSequencer2::ref().getIncidentTargetList(2); + std::string space; + glm::vec4 color; + size_t isize = incidentTargets.second.size(); + for (size_t p = 0; p < isize; p++){ + double t = static_cast(p + 1) / static_cast(isize + 1); + t = (p > isize / 2) ? 1 - t : t; + t += 0.3; + color = (p == isize / 2) ? targetColor : glm::vec4(t, t, t, 1); + + RenderFont(fontMono, + penPosition, + color, + "%s%s", + space.c_str(), incidentTargets.second[p].c_str() + ); + + + for (int k = 0; k < incidentTargets.second[p].size() + 2; k++) + space += " "; + } + + std::map activeMap = ImageSequencer2::ref().getActiveInstruments(); + glm::vec4 firing(0.58-t, 1-t, 1-t, 1); + glm::vec4 notFiring(0.5, 0.5, 0.5, 1); - if (hour < 10) hh.append("0"); - if (minute < 10) mm.append("0"); - if (second < 10) ss.append("0"); + penPosition.y -= fontMono->height(); + RenderFont(fontMono, + penPosition, + active, + "Active Instruments:" + ); - hh.append(std::to_string(hour)); - mm.append(std::to_string(minute)); - ss.append(std::to_string(second)); - - PrintColorTextArg(line++, "Data acquisition adjacency: [%s:%s:%s]", 10, targetColor, hh.c_str(), mm.c_str(), ss.c_str()); - - std::pair> incidentTargets = ImageSequencer2::ref().getIncidentTargetList(2); - std::string space; - glm::vec4 color; - size_t isize = incidentTargets.second.size(); - for (size_t p = 0; p < isize; p++){ - double t = static_cast(p + 1) / static_cast(isize + 1); - t = (p > isize / 2) ? 1 - t : t; - t += 0.3; - color = (p == isize / 2) ? targetColor : glm::vec4(t, t, t, 1); - PrintColorTextArg(line, "%s%s", 10, color, space.c_str(), incidentTargets.second[p].c_str()); - for (int k = 0; k < incidentTargets.second[p].size() + 2; k++) - space += " "; - } - line++; - - std::map activeMap = ImageSequencer2::ref().getActiveInstruments(); - glm::vec4 firing(0.58-t, 1-t, 1-t, 1); - glm::vec4 notFiring(0.5, 0.5, 0.5, 1); - PrintColorText(line++, "Active Instruments: ", 10, active); - for (auto t : activeMap){ - if (t.second == false){ - PrintColorText(line, "| |", 10, glm::vec4(0.3, 0.3, 0.3, 1)); - PrintColorTextArg(line++, " %5s", 10, glm::vec4(0.3, 0.3, 0.3, 1), t.first.c_str()); - } - else{ - PrintColorText(line, "|", 10, glm::vec4(0.3, 0.3, 0.3, 1)); - if (t.first == "NH_LORRI"){ - PrintColorText(line, " + ", 10, firing); - } - PrintColorText(line, " |", 10, glm::vec4(0.3, 0.3, 0.3, 1)); - PrintColorTextArg(line++, " %5s", 10, active, t.first.c_str()); - } - } + for (auto t : activeMap){ + penPosition.y -= fontMono->height(); + if (t.second == false) { + RenderFont(fontMono, + penPosition, + glm::vec4(0.3, 0.3, 0.3, 1), + "| |" + ); + RenderFont(fontMono, + penPosition, + glm::vec4(0.3, 0.3, 0.3, 1), + " %5s", + t.first.c_str() + ); + + } + else{ + RenderFont(fontMono, + penPosition, + glm::vec4(0.3, 0.3, 0.3, 1), + "|" + ); + if (t.first == "NH_LORRI") { + RenderFont(fontMono, + penPosition, + firing, + " + " + ); + } + RenderFont(fontMono, + penPosition, + glm::vec4(0.3, 0.3, 0.3, 1), + " |" + ); + RenderFont(fontMono, + penPosition, + active, + " %5s", + t.first.c_str() + ); + } + } + } } - } -#endif + #endif -#undef PrintText - } + #undef PrintText + } + if (_showScreenLog) { + const float fontSizeLight = 7.f; + Font* fontLight = OsEng.fontManager().font(constants::fonts::keyLight, 7.f); + const int max = 10; + const int category_length = 20; + const int msg_length = 140; + const float ttl = 15.f; + const float fade = 5.f; + auto entries = _log->last(max); - if (_showScreenLog) - { - const sgct_text::Font* font = fontLight; - const int max = 10; - const int category_length = 20; - const int msg_length = 140; - const float ttl = 15.f; - const float fade = 5.f; - auto entries = _log->last(max); + const glm::vec4 white(0.9, 0.9, 0.9, 1); + const glm::vec4 red(1, 0, 0, 1); + const glm::vec4 yellow(1, 1, 0, 1); + const glm::vec4 green(0, 1, 0, 1); + const glm::vec4 blue(0, 0, 1, 1); - const glm::vec4 white(0.9, 0.9, 0.9, 1); - const glm::vec4 red(1, 0, 0, 1); - const glm::vec4 yellow(1, 1, 0, 1); - const glm::vec4 green(0, 1, 0, 1); - const glm::vec4 blue(0, 0, 1, 1); + size_t nr = 1; + for (auto& it = entries.first; it != entries.second; ++it) { + const ScreenLog::LogEntry* e = &(*it); - size_t nr = 1; - for (auto& it = entries.first; it != entries.second; ++it) { - const ScreenLog::LogEntry* e = &(*it); + const double t = OsEng.windowWrapper().time(); + float diff = static_cast(t - e->timeStamp); - const double t = OsEng.windowWrapper().time(); - float diff = static_cast(t - e->timeStamp); + // Since all log entries are ordered, once one is exceeding TTL, all have + if (diff > ttl) + break; - // Since all log entries are ordered, once one is exceeding TTL, all have - if (diff > ttl) - break; + float alpha = 1; + float ttf = ttl - fade; + if (diff > ttf) { + diff = diff - ttf; + float p = 0.8f - diff / fade; + alpha = (p <= 0.f) ? 0.f : pow(p, 0.3f); + } - float alpha = 1; - float ttf = ttl - fade; - if (diff > ttf) { - diff = diff - ttf; - float p = 0.8f - diff / fade; - alpha = (p <= 0.f) ? 0.f : pow(p, 0.3f); - } + // Since all log entries are ordered, once one exceeds alpha, all have + if (alpha <= 0.0) + break; - // Since all log entries are ordered, once one exceeds alpha, all have - if (alpha <= 0.0) - break; + const std::string lvl = "(" + ghoul::logging::LogManager::stringFromLevel(e->level) + ")"; + const std::string& message = e->message.substr(0, msg_length); + nr += std::count(message.begin(), message.end(), '\n'); - const std::string lvl = "(" + ghoul::logging::LogManager::stringFromLevel(e->level) + ")"; - const std::string& message = e->message.substr(0, msg_length); - nr += std::count(message.begin(), message.end(), '\n'); + RenderFont(fontLight, + glm::vec2(10.f, fontSizeLight * nr * 2), + white * alpha, + "%-14s %s%s", // Format + e->timeString.c_str(), // Time string + e->category.substr(0, category_length).c_str(), // Category string (up to category_length) + e->category.length() > 20 ? "..." : ""); // Pad category with "..." if exceeds category_length + + glm::vec4 color = white; + if (e->level == ghoul::logging::LogManager::LogLevel::Debug) + color = green; + if (e->level == ghoul::logging::LogManager::LogLevel::Warning) + color = yellow; + if (e->level == ghoul::logging::LogManager::LogLevel::Error) + color = red; + if (e->level == ghoul::logging::LogManager::LogLevel::Fatal) + color = blue; - Freetype::print(font, 10.f, static_cast(font_size_light * nr * 2), white*alpha, - "%-14s %s%s", // Format - e->timeString.c_str(), // Time string - e->category.substr(0, category_length).c_str(), // Category string (up to category_length) - e->category.length() > 20 ? "..." : ""); // Pad category with "..." if exceeds category_length + const float font_with_light = 5; + RenderFont(fontLight, + glm::vec2(static_cast(10 + 39 * font_with_light), fontSizeLight * nr * 2), + color * alpha, + "%s", // Format + lvl.c_str()); // Pad category with "..." if exceeds category_length - glm::vec4 color = white; - if (e->level == ghoul::logging::LogManager::LogLevel::Debug) - color = green; - if (e->level == ghoul::logging::LogManager::LogLevel::Warning) - color = yellow; - if (e->level == ghoul::logging::LogManager::LogLevel::Error) - color = red; - if (e->level == ghoul::logging::LogManager::LogLevel::Fatal) - color = blue; - - Freetype::print(font, static_cast(10 + 39 * font_with_light), static_cast(font_size_light * nr * 2), color*alpha, "%s", lvl.c_str()); - - - Freetype::print(font, static_cast(10 + 53 * font_with_light), static_cast(font_size_light * nr * 2), white*alpha, "%s", message.c_str()); - ++nr; - } - } + RenderFont(fontLight, + glm::vec2(static_cast(10 + 53 * font_with_light), fontSizeLight * nr * 2), + white * alpha, + "%s", // Format + message.c_str()); // Pad category with "..." if exceeds category_length + ++nr; + } + } + } } #endif } diff --git a/src/util/time.cpp b/src/util/time.cpp index 89c1c796cc..362d6ecc33 100644 --- a/src/util/time.cpp +++ b/src/util/time.cpp @@ -123,7 +123,6 @@ void Time::setTime(std::string time, bool requireJump) { std::string Time::currentTimeUTC() const { std::string date; - //SpiceManager::ref().getDateFromET(_time, date); SpiceManager::ref().getDateFromET(_syncedTime, date); return date; } From 5ce55c1ba497fbca389f2e21d0ab3f5b558d6506 Mon Sep 17 00:00:00 2001 From: Alexander Bock Date: Mon, 16 Nov 2015 19:21:49 -0500 Subject: [PATCH 3/4] Remove unnecessary Boost libraries from libtorrent compilation --- apps/Launcher/ext/libtorrent/CMakeLists.txt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/apps/Launcher/ext/libtorrent/CMakeLists.txt b/apps/Launcher/ext/libtorrent/CMakeLists.txt index 1cbdeb7355..a326a058e9 100644 --- a/apps/Launcher/ext/libtorrent/CMakeLists.txt +++ b/apps/Launcher/ext/libtorrent/CMakeLists.txt @@ -187,10 +187,11 @@ endif () # Boost set(Boost_USE_STATIC_LIBS ON) if (NOT DEFINED Boost_INCLUDE_DIR OR NOT DEFINED Boost_LIBRARIES) - find_package(Boost COMPONENTS system thread date_time chrono) + find_package(Boost COMPONENTS system chrono REQUIRED) endif () target_include_directories(libtorrent PUBLIC ${Boost_INCLUDE_DIR}) target_link_libraries(libtorrent ${Boost_LIBRARIES}) +message(${Boost_LIBRARIES}) if (WIN32) target_link_libraries(libtorrent wsock32 ws2_32 Iphlpapi.lib) From 4f7ab5321ff6ec391b7c8a263af919f3ea6b9b45 Mon Sep 17 00:00:00 2001 From: Alexander Bock Date: Tue, 17 Nov 2015 17:31:43 -0500 Subject: [PATCH 4/4] Cleanup RenderEngine to completely rely on Ghoul font rendering --- ext/ghoul | 2 +- include/openspace/rendering/renderengine.h | 4 + src/rendering/renderengine.cpp | 381 ++++++++++----------- 3 files changed, 186 insertions(+), 201 deletions(-) diff --git a/ext/ghoul b/ext/ghoul index f6dbd18a66..19c3dcc66e 160000 --- a/ext/ghoul +++ b/ext/ghoul @@ -1 +1 @@ -Subproject commit f6dbd18a665b3b13cef7f70310f1c6fc416a7c5f +Subproject commit 19c3dcc66e7fa55637c80142da6ce56eb50b6e8a diff --git a/include/openspace/rendering/renderengine.h b/include/openspace/rendering/renderengine.h index c0a517ae1d..5164ebd4da 100644 --- a/include/openspace/rendering/renderengine.h +++ b/include/openspace/rendering/renderengine.h @@ -143,6 +143,10 @@ private: float _currentFadeTime; int _fadeDirection; // bool _sgctRenderStatisticsVisible; + + ghoul::fontrendering::Font* _fontInfo = nullptr; + ghoul::fontrendering::Font* _fontDate = nullptr; + ghoul::fontrendering::Font* _fontLog = nullptr; bool _visualizeABuffer; ABufferVisualizer* _visualizer; diff --git a/src/rendering/renderengine.cpp b/src/rendering/renderengine.cpp index 9d03f449bf..6e440b9c70 100644 --- a/src/rendering/renderengine.cpp +++ b/src/rendering/renderengine.cpp @@ -52,6 +52,7 @@ #include #include #include +#include #include #ifdef GHOUL_USE_DEVIL @@ -201,6 +202,17 @@ bool RenderEngine::initializeGL() { // development OsEng.windowWrapper().setNearFarClippingPlane(0.001f, 1000.f); + + const float fontSizeTime = 15.f; + _fontDate = OsEng.fontManager().font(constants::fonts::keyMono, fontSizeTime); + const float fontSizeMono = 10.f; + _fontInfo = OsEng.fontManager().font(constants::fonts::keyMono, fontSizeMono); + const float fontSizeLight = 8.f; + _fontLog = OsEng.fontManager().font(constants::fonts::keyLight, fontSizeLight); + + + + // ALL OF THIS HAS TO BE CHECKED // ---abock @@ -396,27 +408,7 @@ void RenderEngine::render(const glm::mat4 &projectionMatrix, const glm::mat4 &vi } } -#if 1 -#define PrintText(__i__, __format__, ...) Freetype::print(font, 10.f, static_cast(startY - font_size_mono * __i__ * 2), __format__, __VA_ARGS__); - //#define PrintColorTextArg(__i__, __format__, __size__, __color__, ...) Freetype::print(font, __size__, static_cast(startY - font_size_mono * __i__ * 2), __format__, __VA_ARGS__); - //#define PrintColorText(__i__, __format__, __size__, __color__) Freetype::print(font, __size__, static_cast(startY - font_size_mono * __i__ * 2), __format__); - #define PrintColorTextArg(__i__, __format__, __size__, __color__, ...) Freetype::print(font, __size__, static_cast(startY - font_size_mono * __i__ * 2), __color__, __format__, __VA_ARGS__); - #define PrintColorText(__i__, __format__, __size__, __color__) Freetype::print(font, __size__, static_cast(startY - font_size_mono * __i__ * 2), __color__, __format__); - - if (_onScreenInformation._node != -1) { - //int thisId = sgct_core::ClusterManager::instance()->getThisNodeId(); - - //if (thisId == _onScreenInformation._node) { - //const unsigned int font_size_mono = _onScreenInformation._size; - //int x1, xSize, y1, ySize; - //const sgct_text::Font* font = sgct_text::FontManager::instance()->getFont(constants::fonts::keyMono, font_size_mono); - //sgct::Engine::instance()->getActiveWindowPtr()->getCurrentViewportPixelCoords(x1, y1, xSize, ySize); - //int startY = ySize - 2 * font_size_mono; - //} - } - // Print some useful information on the master viewport - if (OsEng.ref().isMaster() && OsEng.windowWrapper().isSimpleRendering()) { // TODO: Adjust font_size properly when using retina screen const float fontSizeMono = 10.f; @@ -425,29 +417,37 @@ void RenderEngine::render(const glm::mat4 &projectionMatrix, const glm::mat4 &vi using Font = ghoul::fontrendering::Font; using ghoul::fontrendering::RenderFont; - Font* fontMono = OsEng.fontManager().font(constants::fonts::keyMono, fontSizeMono); - Font* fontTime = OsEng.fontManager().font(constants::fonts::keyMono, fontSizeTime); - if (fontMono && fontTime) { - if (_showInfo) { - double currentTime = Time::ref().currentTime(); - - glm::vec2 penPosition = glm::vec2(10.f, OsEng.windowWrapper().viewportPixelCoordinates().w); + if (_showInfo && _fontDate && _fontInfo) { + double currentTime = Time::ref().currentTime(); + + glm::vec2 penPosition = glm::vec2( + 10.f, + OsEng.windowWrapper().viewportPixelCoordinates().w + ); + penPosition.y -= _fontDate->height(); - penPosition.y -= fontTime->height(); - RenderFont(fontTime, - penPosition, - "Date: %s", - Time::ref().currentTimeUTC().c_str() - ); - - penPosition.y -= fontMono->height(); - RenderFont(fontMono, - penPosition, - "Simulation increment (s): %.0f", - Time::ref().deltaTime() - ); + RenderFontCr(_fontDate, + penPosition, + "Date: %s", + Time::ref().currentTimeUTC().c_str() + ); + + RenderFontCr(_fontInfo, + penPosition, + "Simulation increment (s): %.0f", + Time::ref().deltaTime() + ); + RenderFontCr(_fontInfo, + penPosition, + "Avg. Frametime: %.5f", + OsEng.windowWrapper().averageDeltaTime() + ); + +#ifdef OPENSPACE_MODULE_NEWHORIZONS_ENABLED + if (openspace::ImageSequencer2::ref().isReady()) { + penPosition.y -= 25.f; glm::vec4 targetColor(0.00, 0.75, 1.00, 1); @@ -459,182 +459,163 @@ void RenderEngine::render(const glm::mat4 &projectionMatrix, const glm::mat4 &vi float radius = (a + b) / 2.f; float distToSurf = glm::length(nhPos.vec3()) - radius; - penPosition.y -= fontMono->height(); - RenderFont(fontMono, + RenderFont(_fontInfo, penPosition, "Distance to Pluto: % .1f (KM)", distToSurf ); + penPosition.y -= _fontInfo->height(); + - penPosition.y -= fontMono->height(); - RenderFont(fontMono, - penPosition, - "Avg. Frametime: %.5f", - OsEng.windowWrapper().averageDeltaTime() - ); - - - #ifdef OPENSPACE_MODULE_NEWHORIZONS_ENABLED - if (openspace::ImageSequencer2::ref().isReady()) { - double remaining = openspace::ImageSequencer2::ref().getNextCaptureTime() - currentTime; - float t = static_cast(1.0 - remaining / openspace::ImageSequencer2::ref().getIntervalLength()); - std::string progress = "|"; - int g = static_cast((t* 24) + 1); - g = std::max(g, 0); - for (int i = 0; i < g; i++) - progress.append("-"); - progress.append(">"); - for (int i = 0; i < 25 - g; i++) - progress.append(" "); + double remaining = openspace::ImageSequencer2::ref().getNextCaptureTime() - currentTime; + float t = static_cast(1.0 - remaining / openspace::ImageSequencer2::ref().getIntervalLength()); + std::string progress = "|"; + int g = static_cast((t* 24) + 1); + g = std::max(g, 0); + for (int i = 0; i < g; i++) + progress.append("-"); + progress.append(">"); + for (int i = 0; i < 25 - g; i++) + progress.append(" "); - std::string str = ""; - openspace::SpiceManager::ref().getDateFromET(openspace::ImageSequencer2::ref().getNextCaptureTime(), str, "YYYY MON DD HR:MN:SC"); + std::string str = ""; + openspace::SpiceManager::ref().getDateFromET(openspace::ImageSequencer2::ref().getNextCaptureTime(), str, "YYYY MON DD HR:MN:SC"); - glm::vec4 active(0.6, 1, 0.00, 1); - glm::vec4 brigther_active(0.9, 1, 0.75, 1); + glm::vec4 active(0.6, 1, 0.00, 1); + glm::vec4 brigther_active(0.9, 1, 0.75, 1); - progress.append("|"); - if (remaining > 0) { - brigther_active *= (1 - t); + progress.append("|"); + if (remaining > 0) { + brigther_active *= (1 - t); + + RenderFontCr(_fontInfo, + penPosition, + active * t + brigther_active, + "Next instrument activity:" + ); + + RenderFontCr(_fontInfo, + penPosition, + active * t + brigther_active, + "%.0f s %s %.1f %%", + remaining, progress.c_str(), t * 100 + ); + + RenderFontCr(_fontInfo, + penPosition, + active, + "Data acquisition time: %s", + str.c_str() + ); + } + std::pair nextTarget = ImageSequencer2::ref().getNextTarget(); + std::pair currentTarget = ImageSequencer2::ref().getCurrentTarget(); + + if (currentTarget.first > 0.0) { + int timeleft = static_cast(nextTarget.first - currentTime); + + int hour = timeleft / 3600; + int second = timeleft % 3600; + int minute = second / 60; + second = second % 60; + + std::string hh, mm, ss, coundtown; + + if (hour < 10) hh.append("0"); + if (minute < 10) mm.append("0"); + if (second < 10) ss.append("0"); + + hh.append(std::to_string(hour)); + mm.append(std::to_string(minute)); + ss.append(std::to_string(second)); + + RenderFontCr(_fontInfo, + penPosition, + targetColor, + "Data acquisition adjacency: [%s:%s:%s]", + hh.c_str(), mm.c_str(), ss.c_str() + ); + + + std::pair> incidentTargets = ImageSequencer2::ref().getIncidentTargetList(2); + std::string space; + glm::vec4 color; + size_t isize = incidentTargets.second.size(); + for (size_t p = 0; p < isize; p++){ + double t = static_cast(p + 1) / static_cast(isize + 1); + t = (p > isize / 2) ? 1 - t : t; + t += 0.3; + color = (p == isize / 2) ? targetColor : glm::vec4(t, t, t, 1); - penPosition.y -= fontMono->height(); - RenderFont(fontMono, + RenderFont(_fontInfo, penPosition, - active * t + brigther_active, - "Next instrument activity:" + color, + "%s%s", + space.c_str(), incidentTargets.second[p].c_str() ); - penPosition.y -= fontMono->height(); - RenderFont(fontMono, - penPosition, - active * t + brigther_active, - "%.0f s %s %.1f %%", - remaining, progress.c_str(), t * 100 - ); - - penPosition.y -= fontMono->height(); - RenderFont(fontMono, - penPosition, - active, - "Data acquisition time: %s", - str.c_str() - ); + + for (int k = 0; k < incidentTargets.second[p].size() + 2; k++) + space += " "; } - std::pair nextTarget = ImageSequencer2::ref().getNextTarget(); - std::pair currentTarget = ImageSequencer2::ref().getCurrentTarget(); + penPosition.y -= _fontInfo->height(); + + std::map activeMap = ImageSequencer2::ref().getActiveInstruments(); + glm::vec4 firing(0.58-t, 1-t, 1-t, 1); + glm::vec4 notFiring(0.5, 0.5, 0.5, 1); - if (currentTarget.first > 0.0) { - int timeleft = static_cast(nextTarget.first - currentTime); + RenderFontCr(_fontInfo, + penPosition, + active, + "Active Instruments:" + ); - int hour = timeleft / 3600; - int second = timeleft % 3600; - int minute = second / 60; - second = second % 60; - - std::string hh, mm, ss, coundtown; - - if (hour < 10) hh.append("0"); - if (minute < 10) mm.append("0"); - if (second < 10) ss.append("0"); - - hh.append(std::to_string(hour)); - mm.append(std::to_string(minute)); - ss.append(std::to_string(second)); - - penPosition.y -= fontMono->height(); - RenderFont(fontMono, - penPosition, - targetColor, - "Data acquisition adjacency: [%s:%s:%s]", - hh.c_str(), mm.c_str(), ss.c_str() - ); - - - penPosition.y -= fontMono->height(); - std::pair> incidentTargets = ImageSequencer2::ref().getIncidentTargetList(2); - std::string space; - glm::vec4 color; - size_t isize = incidentTargets.second.size(); - for (size_t p = 0; p < isize; p++){ - double t = static_cast(p + 1) / static_cast(isize + 1); - t = (p > isize / 2) ? 1 - t : t; - t += 0.3; - color = (p == isize / 2) ? targetColor : glm::vec4(t, t, t, 1); - - RenderFont(fontMono, + for (auto t : activeMap){ + if (t.second == false) { + RenderFont(_fontInfo, penPosition, - color, - "%s%s", - space.c_str(), incidentTargets.second[p].c_str() + glm::vec4(0.3, 0.3, 0.3, 1), + "| |" + ); + RenderFontCr(_fontInfo, + penPosition, + glm::vec4(0.3, 0.3, 0.3, 1), + " %5s", + t.first.c_str() ); - - for (int k = 0; k < incidentTargets.second[p].size() + 2; k++) - space += " "; } - - std::map activeMap = ImageSequencer2::ref().getActiveInstruments(); - glm::vec4 firing(0.58-t, 1-t, 1-t, 1); - glm::vec4 notFiring(0.5, 0.5, 0.5, 1); - - penPosition.y -= fontMono->height(); - RenderFont(fontMono, - penPosition, - active, - "Active Instruments:" - ); - - for (auto t : activeMap){ - penPosition.y -= fontMono->height(); - if (t.second == false) { - RenderFont(fontMono, + else{ + RenderFont(_fontInfo, + penPosition, + glm::vec4(0.3, 0.3, 0.3, 1), + "|" + ); + if (t.first == "NH_LORRI") { + RenderFont(_fontInfo, penPosition, - glm::vec4(0.3, 0.3, 0.3, 1), - "| |" - ); - RenderFont(fontMono, - penPosition, - glm::vec4(0.3, 0.3, 0.3, 1), - " %5s", - t.first.c_str() - ); - - } - else{ - RenderFont(fontMono, - penPosition, - glm::vec4(0.3, 0.3, 0.3, 1), - "|" - ); - if (t.first == "NH_LORRI") { - RenderFont(fontMono, - penPosition, - firing, - " + " - ); - } - RenderFont(fontMono, - penPosition, - glm::vec4(0.3, 0.3, 0.3, 1), - " |" - ); - RenderFont(fontMono, - penPosition, - active, - " %5s", - t.first.c_str() + firing, + " + " ); } + RenderFont(_fontInfo, + penPosition, + glm::vec4(0.3, 0.3, 0.3, 1), + " |" + ); + RenderFontCr(_fontInfo, + penPosition, + active, + " %5s", + t.first.c_str() + ); } } } - #endif - - #undef PrintText + } +#endif } if (_showScreenLog) { - const float fontSizeLight = 7.f; - Font* fontLight = OsEng.fontManager().font(constants::fonts::keyLight, 7.f); const int max = 10; const int category_length = 20; const int msg_length = 140; @@ -656,8 +637,8 @@ void RenderEngine::render(const glm::mat4 &projectionMatrix, const glm::mat4 &vi float diff = static_cast(t - e->timeStamp); // Since all log entries are ordered, once one is exceeding TTL, all have - if (diff > ttl) - break; +// if (diff > ttl) +// break; float alpha = 1; float ttf = ttl - fade; @@ -666,6 +647,8 @@ void RenderEngine::render(const glm::mat4 &projectionMatrix, const glm::mat4 &vi float p = 0.8f - diff / fade; alpha = (p <= 0.f) ? 0.f : pow(p, 0.3f); } + + alpha = 1.f; // Since all log entries are ordered, once one exceeds alpha, all have if (alpha <= 0.0) @@ -675,8 +658,8 @@ void RenderEngine::render(const glm::mat4 &projectionMatrix, const glm::mat4 &vi const std::string& message = e->message.substr(0, msg_length); nr += std::count(message.begin(), message.end(), '\n'); - RenderFont(fontLight, - glm::vec2(10.f, fontSizeLight * nr * 2), + RenderFont(_fontLog, + glm::vec2(10.f, _fontLog->pointSize() * nr * 2), white * alpha, "%-14s %s%s", // Format e->timeString.c_str(), // Time string @@ -693,24 +676,22 @@ void RenderEngine::render(const glm::mat4 &projectionMatrix, const glm::mat4 &vi if (e->level == ghoul::logging::LogManager::LogLevel::Fatal) color = blue; - const float font_with_light = 5; - RenderFont(fontLight, - glm::vec2(static_cast(10 + 39 * font_with_light), fontSizeLight * nr * 2), +// const float font_with_light = 5; + RenderFont(_fontLog, + glm::vec2(static_cast(10 + 39 * _fontLog->pointSize()), _fontLog->pointSize() * nr * 2), color * alpha, "%s", // Format lvl.c_str()); // Pad category with "..." if exceeds category_length - RenderFont(fontLight, - glm::vec2(static_cast(10 + 53 * font_with_light), fontSizeLight * nr * 2), + RenderFont(_fontLog, + glm::vec2(static_cast(10 + 53 * _fontLog->pointSize()), _fontLog->pointSize() * nr * 2), white * alpha, "%s", // Format message.c_str()); // Pad category with "..." if exceeds category_length ++nr; } - } } } -#endif } void RenderEngine::postDraw() {