GLSL fragment shader syntax error

The following simple fragmentary shader code failed, leaving an uninformative message in the log: ERROR: 0:1: 'gl_Color' : syntax error syntax error

void main()
{
  vec4 myOutputColor(gl_Color);
  gl_FragColor = myOutputColor;
}

while the following works:

void main()
{
  glFragColor = gl_Color;
}

This scares my mind, as in the Lighthouse3D Gl_Color Tutorial, vec4 is considered. Why can't I assign it to another vec4?

+3
source share
2 answers

Try to complete a regular task. Like this:

void main()
{
  vec4 myOutputColor = gl_Color;
  gl_FragColor = myOutputColor;
}

Edit:

The second answer is also right, but there is no need to use the vec4 () constructor, since both are of the same type. If you let the (r, g, b, w) tuple say, you can write:

vec4 myOutputColor = vec4(r, g, b, w);

or

// assuming myRgbColor is a vec3
vec4 myOutputColor = vec4(myRgbColor, w);

etc.

+7
source

(. OpenGL)

vec4 myOutputColor = vec4(gl_Color);
gl_FragColor = myOutputColor;

(Windows, Nvidia)

+4

Source: https://habr.com/ru/post/1708651/


All Articles