'glCreateShader' was not declared in this scope?
Asked Answered
E

3

9

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.

Exemption answered 15/8, 2012 at 0:24 Comment(3)
Have you included the openGL interface headers?Kaliski
Do I need to? I thought that glut included those. It works fine for other gl commands.Exemption
You need to be running 2.0 or higher.Kaliski
O
7

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.

Officer answered 15/8, 2012 at 0:34 Comment(8)
glGetString(GL_VERSION) returns 2.0.5279 WinXP Release It still doesn't work with an include to gl.h The strange thing is that glCreateShader is NOT in the gl.h Why would it not have it?Exemption
The OpenGL headers included with your compiler must be for 1.1 (or another version less than 2.0) -- which compiler are you using?Officer
Apparently MinGW has 1.x headers, too. Updated my answer.Officer
I setup GLEW, and included it but now I get this error: undefined reference to '_imp____glewCreateShader'Exemption
hmm, it's been a while since I used it. Are you linking against the appropriate library?Officer
#include <windows.h> #include <GL/glew.h> #include <GL/glut.h> that's all I'm including.Exemption
That's compiling. You need to include libraries while linking as well. Something along the lines of -lglew, perhaps?Officer
I don't know what you're talking about. Would you mind giving me some steps?Exemption
H
4

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.

Hunk answered 15/8, 2012 at 1:10 Comment(0)
H
-1

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;
}
Hysterotomy answered 7/8, 2020 at 15:27 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.