-3
\$\begingroup\$

I get this error while trying to add lighting

Message: Error has been generated. GL error GL_INVALID_OPERATION in Uniform1i: (ID: 2882512024) GL error GL_INVALID_OPERATION: mismatched type setting uniform of location "4" in program 1, "" using shaders, 2, "", 3, ""
type: ERROR --- id: 1282 --- severity: HIGH

this is my fragmentshader

out vec4 color;

in VS_OUT
{
    vec2 tc;
    vec3 normals;
} 

fs_in;


layout(binding=0)uniform sampler2D tex; 

uniform vec3 lightColor;

void main(void)
{
color= texture(tex, fs_in.tc)* vec4(lightColor, 1.0);

}

I have this in my render

GLint lightColor_location = glGetUniformLocation(program, "lightColor");
    glUniform1i(lightColor_location, 0);
    glUniform3f(lightColor_location, lightColor.r, lightColor.g, lightColor.b);

and this declared

glm::vec3 lightColor = glm::vec3(1.0f, 1.0f, 1.0f);
```
\$\endgroup\$
1
  • 2
    \$\begingroup\$ "mismatched type" seems like a fairly clear error message. What have you tried to do to solve the error? \$\endgroup\$
    – Tyyppi_77
    Nov 24 at 16:22
1
\$\begingroup\$
glUniform1i(lightColor_location, 0);

This says "set lightColor to the single number value zero".

But lightColor isn't a single number - it's three numbers! You can't set a variable that wants three numbers by giving it only one.

The line immediately after that looks more correct:

glUniform3f(lightColor_location, lightColor.r, lightColor.g, lightColor.b);

Here we're trying to set a 3-component variable by giving it 3 numbers, so we've matched the input to the intended output.

\$\endgroup\$
1
  • \$\begingroup\$ The glUniform1i call possibly intends to set "tex" to 0, which is not actually necessary as it's already declared with binding 0. \$\endgroup\$ Nov 24 at 17:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy