3

the following simple fragment shader code fails, leaving me with 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 one works:

void main()
{
  glFragColor = gl_Color;
}

This boggles my mind, as in Lighthouse3D's tutorial gl_Color is said to be a vec4. Why can't I assign it to another vec4?

6
  • Is the error message really authentic? Is it normal/expected for it to miss the column/line number, and include the "syntax error" text twice? Commented May 19, 2009 at 13:00
  • yes, the error message is authentic (I have omitted an underscore in the examples, hence the edit). I don't really know what's normal/expected with GLSL info logs; in most of the cases the location of the error wasn't displayed, just the problematic variable / function name. (The environment is OS X, xcode, OpenGL 2.0 with an ATI driver v1.5) Commented May 19, 2009 at 13:13
  • bumpbump* Hey slacker! Did it work? ;) Commented May 21, 2009 at 13:40
  • sure did. I was hesitant whose answer shall I accept because both work just fine, but I ended up with yours for brevity / human-readability. Commented May 22, 2009 at 9:57
  • The second answer is just as correct really, but there isn't any need to use the vec4() constructor, since both are of the same type. If you had lets say a (r,g,b,w) tuple you could write: vec4 myOutputColor = vec4(r, g, b, w); Commented May 22, 2009 at 10:27

2 Answers 2

7

Try normal assignment. Like this:

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

Edit:

The second answer is just as correct really, but there isn't any need to use the vec4() constructor, since both are of the same type. If you had lets say a (r,g,b,w) tuple you could write:

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

or

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

etc

Sign up to request clarification or add additional context in comments.

Comments

4

Aparrently you should use slightly different syntax

(see OpenGL Shading Language Specification )

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

this unlike your sample compiles fine on my mashine (Windows, Nvidia card)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.