'glCreateShader' was not declared in this scope?

Viewed 19143

Why am I getting these errors?

error: 'GL_VERTEX_SHADER' was not declared in this scope
error: 'glCreateShader' was not declared in this scope

Code:

GLuint vs = glCreateShader(GL_VERTEX_SHADER);

And yes, I do have the includes to glut.

3 Answers

Make sure you are initializing your OpenGL context before you try to access any of the GL namespace. Eg. with GLAD:

// after initializing window

if (!gladLoadGLLoader((GLADloadproc)glfwGetProcAddress))
{
    std::cout << "Failed to initialize GLAD" << std::endl;
    return -1;
}
Related