diff --git a/OpenGL.cpp b/OpenGL.cpp index 25e929b4..4cfe7323 100644 --- a/OpenGL.cpp +++ b/OpenGL.cpp @@ -823,3 +823,49 @@ bool checkFBO() { } return e == GL_FRAMEBUFFER_COMPLETE; } + +const char* GLErrorString(GLenum errorCode) +{ + static const struct { + GLenum code; + const char *string; + } errors[]= + { + /* GL */ + {GL_NO_ERROR, "no error"}, + {GL_INVALID_ENUM, "invalid enumerant"}, + {GL_INVALID_VALUE, "invalid value"}, + {GL_INVALID_OPERATION, "invalid operation"}, + {GL_STACK_OVERFLOW, "stack overflow"}, + {GL_STACK_UNDERFLOW, "stack underflow"}, + {GL_OUT_OF_MEMORY, "out of memory"}, + + {0, NULL } +}; + + int i; + + for (i=0; errors[i].string; i++) + { + if (errors[i].code == errorCode) + { + return errors[i].string; + } + } + + return NULL; +} + +bool isGLError() +{ + GLenum errCode; + const char* errString; + + if ((errCode = glGetError()) != GL_NO_ERROR) { + errString = GLErrorString(errCode); + if (errString != NULL) + fprintf (stderr, "OpenGL Error: %s\n", errString); + return true; + } + return false; +} diff --git a/OpenGL.h b/OpenGL.h index 4efb641f..9b966626 100644 --- a/OpenGL.h +++ b/OpenGL.h @@ -111,4 +111,6 @@ void OGL_ReadScreen( void **dest, long *width, long *height ); bool checkFBO(); +bool isGLError(); + #endif