diff --git a/src/fmri/RenderingState.cpp b/src/fmri/RenderingState.cpp index bf65e71..3a1b3f1 100644 --- a/src/fmri/RenderingState.cpp +++ b/src/fmri/RenderingState.cpp @@ -92,7 +92,7 @@ void RenderingState::handleKey(unsigned char x) glutPostRedisplay(); } -std::string RenderingState::infoLine()const +std::string RenderingState::debugInfo()const { std::stringstream buffer; buffer << "Pos(x,y,z) = (" << pos[0] << ", " << pos[1] << ", " << pos[2] << ")\n"; @@ -217,17 +217,30 @@ void RenderingState::render(float time) const glPopMatrix(); - renderDebugInfo(); + renderOverlayText(); glutSwapBuffers(); } -void RenderingState::renderDebugInfo() const +void RenderingState::renderOverlayText() const { + std::stringstream overlayText; + if (options.showDebug) { + overlayText << debugInfo() << "\n"; + } + + if (options.showHelp) { + overlayText << "Controls:\n" + "WASD: move\n" + "shift: move faster\n" + "F1: toggle this help message\n" + "F2: toggle debug info\n"; + } + glLoadIdentity(); setOrthographicProjection(); glColor3f(1, 1, 0); - renderText(infoLine(), 2, 10); + renderText(overlayText.str(), 2, 10); restorePerspectiveProjection(); } @@ -261,6 +274,15 @@ void RenderingState::handleSpecialKey(int key) updateVisualisers(); break; + case GLUT_KEY_F1: + options.showHelp = !options.showHelp; + glutPostRedisplay(); + break; + + case GLUT_KEY_F2: + options.showDebug = !options.showDebug; + break; + default: LOG(INFO) << "Received keystroke " << key; } diff --git a/src/fmri/RenderingState.hpp b/src/fmri/RenderingState.hpp index 61f53a6..ee99ac5 100644 --- a/src/fmri/RenderingState.hpp +++ b/src/fmri/RenderingState.hpp @@ -43,6 +43,10 @@ namespace fmri static RenderingState& instance(); private: + struct { + bool showDebug = false; + bool showHelp = true; + } options; std::array pos; std::array angle; std::map layerInfo; @@ -58,8 +62,8 @@ namespace fmri void move(unsigned char key); void updateVisualisers(); - std::string infoLine()const; - void renderDebugInfo() const; + std::string debugInfo() const; + void renderOverlayText() const; void renderLayerName(const std::string& name) const; }; }