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\$

1 Answer 1

3
\$\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\$
4
  • \$\begingroup\$ You can't divide integers? \$\endgroup\$ Commented Apr 2, 2014 at 0:46
  • \$\begingroup\$ I mean integers, sorry. \$\endgroup\$ Commented Apr 2, 2014 at 0:49
  • 1
    \$\begingroup\$ Glsl integer division will give an integer result. So 127/255 = 0.49 which is rounded to 0. \$\endgroup\$
    – user39686
    Commented Apr 2, 2014 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\$ Commented Apr 2, 2014 at 0:51

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .