diff --git a/src/glutils.cpp b/src/glutils.cpp index 4e521e4..229bc8e 100644 --- a/src/glutils.cpp +++ b/src/glutils.cpp @@ -111,3 +111,17 @@ void fmri::renderText(std::string_view text) glutBitmapCharacter(font, c); } } + +void fmri::checkGLErrors() +{ + while (auto error = glGetError()) { + switch (glGetError()) { + case GL_NO_ERROR: + // Should not get here, but whatever. + return; + + default: + cerr << "OpenGL error: " << (const char*) glewGetErrorString(error) << endl; + } + } +} diff --git a/src/glutils.hpp b/src/glutils.hpp index a8c3561..34462b4 100644 --- a/src/glutils.hpp +++ b/src/glutils.hpp @@ -41,4 +41,9 @@ namespace fmri { * @param text The text to draw. */ void renderText(std::string_view text); + + /** + * Check if there are OpenGL errors and report them. + */ + void checkGLErrors(); } diff --git a/src/main.cpp b/src/main.cpp index 027488c..365d5e7 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -110,6 +110,11 @@ static void updateVisualisers(unsigned int dataset) } } +static void idleFunc() +{ + checkGLErrors(); +} + int main(int argc, char *argv[]) { google::InitGoogleLogging(argv[0]); @@ -126,7 +131,7 @@ int main(int argc, char *argv[]) // Register callbacks glutDisplayFunc(render); - glutIdleFunc(glutPostRedisplay); + glutIdleFunc(idleFunc); glutReshapeFunc(changeWindowSize); Camera::instance().registerControls();