Code Yarns ‍👨‍💻
Tech BlogPersonal Blog

How to check error in GLEW

📅 2015-Sep-14 ⬩ ✍️ Ashwin Nanjappa ⬩ 📚 Archive

You typically check for error after initializing GLEW by calling glewInit(). It returns an error value of type GLenum. Note that GLEW merely uses this data type, it has defined its own error values based on it.

By looking at GLEW header files, I find that the error values currently supported are:

#define GLEW_OK 0
#define GLEW_NO_ERROR 0
#define GLEW_ERROR_NO_GL_VERSION 1  /* missing GL version */
#define GLEW_ERROR_GL_VERSION_10_ONLY 2  /* Need at least OpenGL 1.1 */
#define GLEW_ERROR_GLX_VERSION_11_ONLY 3  /* Need at least GLX 1.2 */

So, you typically first check if the value returned from glewInit() is GLEW_OK. If not, you further investigate what the error might be.

GLEW provides an utility function glewGetErrorString() that provides an error string given the error value.

Putting all the above together, this is how we could check for error in GLEW:

const GLenum err = glewInit();

if (GLEW_OK != err)
    std::cout << "GLEW Error: " << glewGetErrorString(err) << std::endl;

Tried with: GLEW 1.10 and Ubuntu 14.04