Add debug info in the top left corner.
This commit is contained in:
@@ -21,6 +21,24 @@ static void handleMouseMove(int x, int y)
|
|||||||
glutPostRedisplay();
|
glutPostRedisplay();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static float getFPS()
|
||||||
|
{
|
||||||
|
static int frames = 0;
|
||||||
|
static float fps = 0;
|
||||||
|
static auto timeBase = glutGet(GLUT_ELAPSED_TIME);
|
||||||
|
|
||||||
|
++frames;
|
||||||
|
const auto time = glutGet(GLUT_ELAPSED_TIME);
|
||||||
|
if (time - timeBase > 2000) {
|
||||||
|
fps = frames * 1000.0f / (time - timeBase);
|
||||||
|
frames = 0;
|
||||||
|
timeBase = time;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
return fps;
|
||||||
|
}
|
||||||
|
|
||||||
static void move(unsigned char key)
|
static void move(unsigned char key)
|
||||||
{
|
{
|
||||||
float speed = 0.5;
|
float speed = 0.5;
|
||||||
@@ -80,6 +98,7 @@ std::string Camera::infoLine()
|
|||||||
stringstream buffer;
|
stringstream buffer;
|
||||||
buffer << "Pos(x,y,z) = (" << pos[0] << ", " << pos[1] << ", " << pos[2] << ")\n";
|
buffer << "Pos(x,y,z) = (" << pos[0] << ", " << pos[1] << ", " << pos[2] << ")\n";
|
||||||
buffer << "Angle(p,y) = (" << angle[0] << ", " << angle[1] << ")\n";
|
buffer << "Angle(p,y) = (" << angle[0] << ", " << angle[1] << ")\n";
|
||||||
|
buffer << "FPS = " << getFPS() << "\n";
|
||||||
return buffer.str();
|
return buffer.str();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -83,12 +83,17 @@ void fmri::changeWindowSize(int w, int h)
|
|||||||
glMatrixMode(GL_MODELVIEW);
|
glMatrixMode(GL_MODELVIEW);
|
||||||
}
|
}
|
||||||
|
|
||||||
void fmri::renderText(std::string_view text)
|
void fmri::renderText(std::string_view text, int x, int y)
|
||||||
{
|
{
|
||||||
constexpr auto font = GLUT_BITMAP_HELVETICA_10;
|
constexpr auto font = GLUT_BITMAP_HELVETICA_10;
|
||||||
glRasterPos2i(0, 0);
|
glRasterPos2i(x, y);
|
||||||
for (char c : text) {
|
for (char c : text) {
|
||||||
glutBitmapCharacter(font, c);
|
if (c == '\n') {
|
||||||
|
y += 12;
|
||||||
|
glRasterPos2i(x, y);
|
||||||
|
} else {
|
||||||
|
glutBitmapCharacter(font, c);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -117,3 +122,32 @@ void fmri::throttleIdleFunc()
|
|||||||
|
|
||||||
lastCalled = now;
|
lastCalled = now;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void fmri::restorePerspectiveProjection() {
|
||||||
|
|
||||||
|
glMatrixMode(GL_PROJECTION);
|
||||||
|
// restore previous projection matrix
|
||||||
|
glPopMatrix();
|
||||||
|
|
||||||
|
// get back to modelview mode
|
||||||
|
glMatrixMode(GL_MODELVIEW);
|
||||||
|
}
|
||||||
|
|
||||||
|
void fmri::setOrthographicProjection() {
|
||||||
|
|
||||||
|
// switch to projection mode
|
||||||
|
glMatrixMode(GL_PROJECTION);
|
||||||
|
|
||||||
|
// save previous matrix which contains the
|
||||||
|
//settings for the perspective projection
|
||||||
|
glPushMatrix();
|
||||||
|
|
||||||
|
// reset matrix
|
||||||
|
glLoadIdentity();
|
||||||
|
|
||||||
|
// set a 2D orthographic projection
|
||||||
|
gluOrtho2D(0, glutGet(GLUT_WINDOW_WIDTH), glutGet(GLUT_WINDOW_HEIGHT), 0);
|
||||||
|
|
||||||
|
// switch back to modelview mode
|
||||||
|
glMatrixMode(GL_MODELVIEW);
|
||||||
|
}
|
||||||
|
|||||||
@@ -34,7 +34,7 @@ namespace fmri {
|
|||||||
*
|
*
|
||||||
* @param text The text to draw.
|
* @param text The text to draw.
|
||||||
*/
|
*/
|
||||||
void renderText(std::string_view text);
|
void renderText(std::string_view text, int x = 0, int y = 0);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Check if there are OpenGL errors and report them.
|
* Check if there are OpenGL errors and report them.
|
||||||
@@ -45,4 +45,8 @@ namespace fmri {
|
|||||||
* Slow down until the idle func is being called a reasonable amount of times.
|
* Slow down until the idle func is being called a reasonable amount of times.
|
||||||
*/
|
*/
|
||||||
void throttleIdleFunc();
|
void throttleIdleFunc();
|
||||||
|
|
||||||
|
void setOrthographicProjection();
|
||||||
|
|
||||||
|
void restorePerspectiveProjection();
|
||||||
}
|
}
|
||||||
|
|||||||
11
src/main.cpp
11
src/main.cpp
@@ -63,6 +63,15 @@ static void loadSimulationData(const Options &options)
|
|||||||
|
|
||||||
static void renderLayerName(const LayerData &data);
|
static void renderLayerName(const LayerData &data);
|
||||||
|
|
||||||
|
static void renderDebugInfo()
|
||||||
|
{
|
||||||
|
glLoadIdentity();
|
||||||
|
setOrthographicProjection();
|
||||||
|
glColor3f(1, 1, 0);
|
||||||
|
renderText(Camera::instance().infoLine(), 2, 10);
|
||||||
|
restorePerspectiveProjection();
|
||||||
|
}
|
||||||
|
|
||||||
static void render()
|
static void render()
|
||||||
{
|
{
|
||||||
// Clear Color and Depth Buffers
|
// Clear Color and Depth Buffers
|
||||||
@@ -92,6 +101,8 @@ static void render()
|
|||||||
|
|
||||||
glPopMatrix();
|
glPopMatrix();
|
||||||
|
|
||||||
|
renderDebugInfo();
|
||||||
|
|
||||||
glutSwapBuffers();
|
glutSwapBuffers();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user