Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

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?

share|improve this question
2  
This is not directly related, but you should not terminate string literals with an explicit "\0" like that. String literals in C (and C++) are implicitly null-terminated, so all those strings are double-terminated, which is pointless and wasteful. –  Josh Petrie Jan 9 '14 at 16:21
    
Thanks! I had no idea. Unfortunately, as you said, it makes no difference. –  Dan Nestor Jan 9 '14 at 16:23
2  
it means the normal and texcoord is not used to influence the final output that the compiler optimized it out –  ratchet freak Jan 9 '14 at 16:28
    
That's it! Thanks. –  Dan Nestor Jan 9 '14 at 16:31

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.