1
\$\begingroup\$

For some reason, the color isn't applying to the object. Here's my fragment shader code. There's probably something obvious wrong with it that i'm not seeing.

#version 330 core
out vec3 Color;

uniform int InColor;

void main()
{
        Color = vec3(float(127 / 255), 0, 0);
}
\$\endgroup\$
2
\$\begingroup\$

The value 127 / 255 is an integer division and always has the value zero.

You want vec3(127.0 / 255.0, 0.0, 0.0) instead.

\$\endgroup\$
  • \$\begingroup\$ You can't divide integers? \$\endgroup\$ – user2687781 Apr 2 '14 at 0:46
  • \$\begingroup\$ I mean integers, sorry. \$\endgroup\$ – user2687781 Apr 2 '14 at 0:49
  • \$\begingroup\$ Glsl integer division will give an integer result. So 127/255 = 0.49 which is rounded to 0. \$\endgroup\$ – Thebluefish Apr 2 '14 at 0:51
  • \$\begingroup\$ You can divide integers, but in GLSL, as is the case in C, C++ and many other languages, the result of 127 / 255 will be 0. \$\endgroup\$ – sam hocevar Apr 2 '14 at 0:51

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.