Skip to content

Instantly share code, notes, and snippets.

@jsimmons
Created July 16, 2010 00:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jsimmons/477777 to your computer and use it in GitHub Desktop.
Save jsimmons/477777 to your computer and use it in GitHub Desktop.
opengl error checking
#include "gl.h"
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
void sgl_check_gl_error(const char *func, const char *file, int line)
{
GLenum error = glGetError();
bool had_error = false;
while(error != GL_NO_ERROR)
{
had_error = true;
char *err_msg = 0;
switch(error)
{
case GL_INVALID_ENUM:
err_msg = "GL_INVALID_ENUM error in function %s of %s:%i\n";
break;
case GL_INVALID_VALUE:
err_msg = "GL_INVALID_VALUE error in function %s of %s:%i\n";
break;
case GL_INVALID_OPERATION:
err_msg = "GL_INVALID_OPERATION error in function %s of %s:%i\n";
break;
case GL_OUT_OF_MEMORY:
err_msg = "GL_OUT_OF_MEMORY error in function %s of %s:%i\n";
break;
case GL_STACK_OVERFLOW:
err_msg = "GL_STACK_OVERFLOW error in function %s of %s:%i\n";
break;
case GL_STACK_UNDERFLOW:
err_msg = "GL_STACK_UNDERFLOW error in function %s of %s:%i\n";
break;
case GL_TABLE_TOO_LARGE:
err_msg = "GL_TABLE_TOO_LARGE error in function %s of %s:%i\n";
break;
default:
err_msg = "Unknown error in function %s of %s:%i\n";
break;
}
fprintf(stderr, err_msg, func, file, line);
error = glGetError();
}
if(had_error)
exit(1);
}
#ifndef SGL_GL_H
#define SGL_GL_H
#include <GL/glew.h>
void sgl_check_gl_error();
#ifdef SGL_DEBUG
#define SGL_CHECK_GL(Func) \
Func; \
sgl_check_gl_error(#Func, __FILE__, __LINE__); \
#else
#define SGL_CHECK_GL
#endif
#endif
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment