I am trying to set up a shader which takes three input parameters. I have the following code:
GLuint vert = glCreateShader(GL_VERTEX_SHADER);
GLuint frag = glCreateShader(GL_FRAGMENT_SHADER);
const GLchar* vertsrc = src.vertex.c_str();
const GLchar* fragsrc = src.fragment.c_str();
glShaderSource(vert, 1, &vertsrc, NULL);
glShaderSource(frag, 1, &fragsrc, NULL);
glCompileShader(vert);
glCompileShader(frag);
GLuint program = glCreateProgram();
glAttachShader(program, vert);
glAttachShader(program, frag);
glBindAttribLocation(program, 0, "position");
if (glGetError() != GL_NO_ERROR) ...
glBindAttribLocation(program, 1, "normal");
if (glGetError() != GL_NO_ERROR) ...
glBindAttribLocation(program, 2, "texcoord");
if (glGetError() != GL_NO_ERROR) ...
glLinkProgram(program);
//...check linking errors
auto p = glGetAttribLocation(program, "position");
auto n = glGetAttribLocation(program, "normal");
auto t = glGetAttribLocation(program, "texcoord");
GL_MAX_VERTEX_ATTRIBS
is 16. I don't understand why, after this code executes, the values I get from glGetAttribLocation
are as follows:
- p = 0
- n = -1
- t = -1
Needless to say, I am unable to pass anything beyond vertex attrib array no. 0 to my shader. What am I doing wrong?