Reputation: 113
I want to write a GLSL Fragment Shader that can do texture mapping and vertex coloring. Is it possible to do both in the one shader?
At the moment, I can do this:
gl_FragColor = texture2D(tex, gl_TexCoord[0].st);
Which causes textured verts to be drawn, but not colored verts. (which looks like this: http://www.tiikoni.com/tis/view/?id=124eb69)
I can also do this:
gl_FragColor = gl_Color;
Which causes colored verts to be drawn but not textured verts. (Which looks like this: http://www.tiikoni.com/tis/view/?id=5bcd838)
If I do this:
gl_FragColor = texture2D(tex, gl_TexCoord[0].st) * gl_Color;
(which looks like the first code snippet)
Only textured verts get drawn... which is my problem.
Upvotes: 0
Views: 1016
Reputation: 473487
What I expect to see is the textured and non-textured verts to all show up, in the last code snippet.
You shouldn't expect that.
There's no such thing as a "textured vert" or a "non-textured vert". There is only a color, whatever that color may be. That's the whole point of shaders: to use arbitrary code to compute a color however you want.
You are computing the color by multiplying the result of a texture fetch with a per-vertex interpolated color. The result will be a combination of the two colors. Namely, the product of them. Therefore, the resultant color will look somewhat like the original texture.
Upvotes: 1