Vertex colors in the shader

Vertex colors don’t seem to show up in my fragment shader:

void main (void)
{
gl_FragColor=gl_Color;
}

Is there anything else I have to do? They show up fine in non-shader mode.

That’s because they are only available from the vertex shader, to get the vertex colors in the fragment shader you must pass it to the fragment shader using an varying variable.

But if you want you can add
gl_FrontColor=gl_Color;
in the vertex shader and it should work (it actually does the same thing but with built in variables).

I actually already had that, and it didn’t see to do anything.

So would it be like this?:

vert:
void main (void)
{
gl_FragColor=gl_Color;
}

frag:
void main (void)
{
gl_FragColor=gl_Color;
}

This is what it was before, and it doesn’t work. It just draws dark gray (32,32,32).

How odd. I removed some unrelated code and now it works fine. One of those ghost bugs that happen so often in shaders.

does it make sense to write to gl_FragColor in a vertex shader?

No, but that was just s typo (only in my forum post). I meant gl_FrontColor.

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