report_gl_error.h 969 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  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);
  24. // No prefix
  25. inline GLenum report_gl_error();
  26. }
  27. // Implementation
  28. #include "verbose.h"
  29. inline GLenum igl::report_gl_error(const std::string id)
  30. {
  31. GLenum err = glGetError();
  32. if(GL_NO_ERROR != err)
  33. {
  34. verbose("GL_ERROR: ");
  35. fprintf(stderr,"%s%s\n",id.c_str(),gluErrorString(err));
  36. }
  37. return err;
  38. }
  39. inline GLenum igl::report_gl_error()
  40. {
  41. return igl::report_gl_error(std::string(""));
  42. }
  43. #endif