Why does not gl_Color work?

I am trying to create a simple shader. Can you tell me why gl_FragData[2] = vec4(1,0,0,0) works as expected, but gl_FragData[2] = gl_Color don’t. When using gl_Color nothing(except objects rendered whit another shader program ) shows up on the screen.

  1 varying vec3 position, normal;
  3 void main(void) {
  4     position = vec3(gl_ModelViewMatrix * gl_Vertex);
  5     normal = gl_NormalMatrix * gl_Normal;
  6     gl_Position = ftransform();
  7 }

1 #extension GL_ARB_draw_buffers : enable
  3 varying vec3 position, normal;
  5 void main(void) {
  6     gl_FragData[0] = vec4(position.xyz, 0.0);
  7     gl_FragData[1] = vec4(normalize(normal.xyz), 0.0);
  8     gl_FragData[2] = gl_Color;//vec4(1,0,0,0); //wont the current color;
  9 }

Because your vertex shader did not write to the color.

How do I write the glColor I am currently rendering with to the fragment shader?

gl_FrontColor = gl_Color;

This will give gl_FrontColor the value of gl_Color not the other way around?

	void main() {     
    // Set the front color to the color passed through with glColor*f 
    gl_FrontColor = gl_Color;        
    // Set the position of the current vertex 
    gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;

Edit: Well gl_FrontColor = gl_Color; works but how?

gl_Color is atrtibute name in vertex shader.
gl_FrontColor and gl_BackColor are varying names in vertex shader.
gl_Color is varying name in fragment shader (its computed based on frontface status of your triangle and gl_FrontColor & gl_BackColor).

Use your own varying and avoid the confusion.

This topic was automatically closed 183 days after the last reply. New replies are no longer allowed.