i wrote a simple shader, in the vertex shader ,i declare a variable: in vect4 color;
i use it like that gl_FrontColor = color;
However , i want to change the value of color, so i wrote
the following code ,but it does not change the color to red.
why???can someone explain this to me ?
void Shader::init(const char *vsFile, const char *fsFile)
{
…;
glShaderSource(…);
glCompileShader(…);
glAttachShader(…);
glGetAttribLocation queries the location assigned when you link the program. You haven’t linked it yet.
If you’d rather assign the location yourself instead of letting OpenGL assign it, use glBindAttribLocation before link.
You should only call one or the other, not both. Take your pick – whichever way you want to do it is fine. But make the call at the appropriate point relative to LinkProgram.
There’s also GLSL syntax to bind an attribute to a specific location in the shader, if you prefer. If you use that, you don’t have to call either one of the above APIs.