i try to write a simple shader using glVertexAttrib(…) ,but it does not work.
in the vertex shader ,i declared a variable:
in vect4 color;
i use it like that
gl_FrontColor = color;
in the fragment shader:
gl_FragColor = color* diffuse_value;
if i use gl_Color instead of color ,it works well,
However , i want to change the value of color by using glVertexAttrib(…), 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(…);
…;
GLfloat c[]={1.0,0.0,0.0,1.0};
GLint loc;
loc=glGetAttribLocation(shader_id,“color”);
glVertexAttrib3fv(loc,c);
glBindAttribLocation(shader_id,loc,“color”);
glLinkProgram(shader_id);
}