report_gl_error.h 847 B

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. #ifndef IGL_REPORT_GL_ERROR
  2. #define IGL_REPORT_GL_ERROR
  3. #ifdef __APPLE__
  4. # include <OpenGL/gl.h>
  5. # include <OpenGL/glu.h>
  6. #else
  7. # ifdef _WIN32
  8. # define NOMINMAX
  9. # include <Windows.h>
  10. # undef NOMINMAX
  11. # endif
  12. # include <GL/gl.h>
  13. # include <GL/glu.h>
  14. #endif
  15. #include <cstdio>
  16. #include <string>
  17. namespace igl
  18. {
  19. // Print last OpenGL error to stderr prefixed by specified id string
  20. // Inputs:
  21. // id string to appear before any error msgs
  22. // Returns result of glGetError()
  23. inline GLenum report_gl_error(const std::string id = std::string(""));
  24. }
  25. // Implementation
  26. #include "verbose.h"
  27. inline GLenum igl::report_gl_error(const std::string id)
  28. {
  29. GLenum err = glGetError();
  30. if(GL_NO_ERROR != err)
  31. {
  32. verbose("GL_ERROR: ");
  33. fprintf(stderr,"%s%s\n",id.c_str(),gluErrorString(err));
  34. }
  35. return err;
  36. }
  37. #endif