Last active
September 27, 2018 07:14
-
-
Save mortennobel/4648058 to your computer and use it in GitHub Desktop.
Simple error check of open gl (write readable error description to cerr stream including file name and line number)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "GLError.h" | |
#include <iostream> | |
#include <string> | |
#ifdef WIN32 | |
# include <GL/glew.h> | |
#elif __APPLE__ | |
# include <OpenGL/gl3.h> | |
#else | |
# include <GL3/gl3.h> | |
#endif | |
using namespace std; | |
void _check_gl_error(const char *file, int line) { | |
GLenum err (glGetError()); | |
while(err!=GL_NO_ERROR) { | |
string error; | |
switch(err) { | |
case GL_INVALID_OPERATION: error="INVALID_OPERATION"; break; | |
case GL_INVALID_ENUM: error="INVALID_ENUM"; break; | |
case GL_INVALID_VALUE: error="INVALID_VALUE"; break; | |
case GL_OUT_OF_MEMORY: error="OUT_OF_MEMORY"; break; | |
case GL_INVALID_FRAMEBUFFER_OPERATION: error="INVALID_FRAMEBUFFER_OPERATION"; break; | |
} | |
cerr << "GL_" << error.c_str() <<" - "<<file<<":"<<line<<endl; | |
err=glGetError(); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#ifndef GLERROR_H | |
#define GLERROR_H | |
void _check_gl_error(const char *file, int line); | |
/// | |
/// Usage | |
/// [... some opengl calls] | |
/// check_gl_error(); | |
/// | |
#define check_gl_error() _check_gl_error(__FILE__,__LINE__) | |
#endif // GLERROR_H |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment