How to check error in GLFW

To check for errors in GLFW, we register an error callback function with GLFW and it is called automatically when there is an error. This is a cleaner method than having to check explicitly for errors, like in OpenGL or GLEW.

This callback can be registered with GLFW even before GLFW has been initialized. This is useful because errors in initialization can also be caught.

The error values I found in GLFW are:


A typical usage of GLFW with error callback:

void ErrorCallback(int, const char* err_str)
    std::cout << "GLFW Error: " << err_str << std::endl;

void SomeInitFunction()
    // Register error callback first

    // Start GLFW next
    const int ret = glfwInit();
    if (GL_FALSE == ret)
        std::cout << "GLFW Error!n";

    // Other GLFW functions go here ...

Tried with: GLFW 3.1.1 and Ubuntu 14.04

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.