Create a configurable overlay.

This commit is contained in:
2018-03-29 14:13:32 +02:00
parent 4f3099bc60
commit c495a60c4d
2 changed files with 32 additions and 6 deletions

View File

@@ -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;
}

View File

@@ -43,6 +43,10 @@ namespace fmri
static RenderingState& instance();
private:
struct {
bool showDebug = false;
bool showHelp = true;
} options;
std::array<float, 3> pos;
std::array<float, 2> angle;
std::map<std::string, LayerInfo> 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;
};
}