Skip to content

Instantly share code, notes, and snippets.

@mortennobel mortennobel/GLError.cpp
Last active Sep 27, 2018

Embed
What would you like to do?
Simple error check of open gl (write readable error description to cerr stream including file name and line number)
#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();
}
}
#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
You can’t perform that action at this time.