Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // import stdio and rendering libraries
- #include <cstdio>
- #include <GL/glew.h>
- #include <GLFW/glfw3.h>
- // given an error, put it into the error buffer
- #define GL_ERROR_CASE(glerror) \
- case glerror: \
- snprintf(error, sizeof(error), "%s", #glerror)
- // while there are errors, print error, which file it came from, and which line of code.
- inline void gl_debug(const char *file, int line)
- {
- GLenum err;
- while ((err = glGetError()) != GL_NO_ERROR)
- {
- char error[128];
- // put error description in the buffer
- switch (err)
- {
- GL_ERROR_CASE(GL_INVALID_ENUM);
- break;
- GL_ERROR_CASE(GL_INVALID_VALUE);
- break;
- GL_ERROR_CASE(GL_INVALID_OPERATION);
- break;
- GL_ERROR_CASE(GL_INVALID_FRAMEBUFFER_OPERATION);
- break;
- GL_ERROR_CASE(GL_OUT_OF_MEMORY);
- break;
- default:
- snprintf(error, sizeof(error), "%s", "UNKNOWN_ERROR");
- break;
- }
- // print "error - file: line\n"
- fprintf(stderr, "%s - %s: %d\n", error, file, line);
- }
- }
- #undef GL_ERROR_CASE
- // ...
- // if we see the below log statements, we've successfully attached OpenGL to the window
- // query the openGL version
- int glVersion[2] = {-1, 1};
- glGetIntegerv(GL_MAJOR_VERSION, &glVersion[0]);
- glGetIntegerv(GL_MINOR_VERSION, &glVersion[1]);
- gl_debug(__FILE__, __LINE__);
- // print some information about our version of OpenGL.
- printf("Using OpenGL: %d.%d\n", glVersion[0], glVersion[1]);
- printf("Renderer used: %s\n", glGetString(GL_RENDERER));
- printf("Shading Language: %s\n", glGetString(GL_SHADING_LANGUAGE_VERSION));
- // ...
Advertisement
Add Comment
Please, Sign In to add comment