Daniel
Daniel

Reputation: 6842

'glCreateShader' was not declared in this scope?

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.

Upvotes: 10

Views: 22640

Answers (3)

jackw11111
jackw11111

Reputation: 1547

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;
}

Upvotes: -1

aib
aib

Reputation: 46961

What does glGetString(GL_VERSION) return?

CreateShader is not in GLUT but OpenGL 2.0. If your "includes to glut" are not including gl.h for some reason or your GL version is less than 2.0, the headers will not declare it.

I'd also check your gl.h to see if CreateShader is actually declared there.

Edit: This OpenGL header version thing seems to be a general problem in Windows. Most people suggest using GLEW or another extension loader library to get around it.

Upvotes: 7

Nicol Bolas
Nicol Bolas

Reputation: 473537

You need to either use an OpenGL loading library to load OpenGL functions, or manually load the functions yourself. You can't just use gl.h and expect to get everything.

Upvotes: 5

Related Questions