AllenYuan

window - debug - specific

Apr 21st, 2020
273
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.63 KB | None | 0 0
  1. // import stdio and rendering libraries
  2. #include <cstdio>
  3. #include <GL/glew.h>
  4. #include <GLFW/glfw3.h>
  5.  
  6. // given an error, put it into the error buffer
  7. #define GL_ERROR_CASE(glerror) \
  8.   case glerror:                \
  9.     snprintf(error, sizeof(error), "%s", #glerror)
  10.  
  11. // while there are errors, print error, which file it came from, and which line of code.
  12. inline void gl_debug(const char *file, int line)
  13. {
  14.   GLenum err;
  15.   while ((err = glGetError()) != GL_NO_ERROR)
  16.   {
  17.     char error[128];
  18.     // put error description in the buffer
  19.     switch (err)
  20.     {
  21.       GL_ERROR_CASE(GL_INVALID_ENUM);
  22.       break;
  23.       GL_ERROR_CASE(GL_INVALID_VALUE);
  24.       break;
  25.       GL_ERROR_CASE(GL_INVALID_OPERATION);
  26.       break;
  27.       GL_ERROR_CASE(GL_INVALID_FRAMEBUFFER_OPERATION);
  28.       break;
  29.       GL_ERROR_CASE(GL_OUT_OF_MEMORY);
  30.       break;
  31.     default:
  32.       snprintf(error, sizeof(error), "%s", "UNKNOWN_ERROR");
  33.       break;
  34.     }
  35.     // print "error - file: line\n"
  36.     fprintf(stderr, "%s - %s: %d\n", error, file, line);
  37.   }
  38. }
  39.  
  40. #undef GL_ERROR_CASE
  41.  
  42. // ...
  43.  
  44.   // if we see the below log statements, we've successfully attached OpenGL to the window
  45.   // query the openGL version
  46.   int glVersion[2] = {-1, 1};
  47.   glGetIntegerv(GL_MAJOR_VERSION, &glVersion[0]);
  48.   glGetIntegerv(GL_MINOR_VERSION, &glVersion[1]);
  49.  
  50.   gl_debug(__FILE__, __LINE__);
  51.  
  52.   // print some information about our version of OpenGL.
  53.   printf("Using OpenGL: %d.%d\n", glVersion[0], glVersion[1]);
  54.   printf("Renderer used: %s\n", glGetString(GL_RENDERER));
  55.   printf("Shading Language: %s\n", glGetString(GL_SHADING_LANGUAGE_VERSION));
  56.  
  57. // ...
Advertisement
Add Comment
Please, Sign In to add comment