Hi everyone!

I want to write a simple fragment shader which multiplies an extra alpha value to each drawn object in a collection, no matter the type of the object. However, as I am new to shaders, my solution is rather clumsy:

Code :
uniform sampler2D testTexture;
// alpha value to use
uniform float alpha;
// to decide where the color of the fragment comes from
uniform int textured = 0;
void main(void) {
 if (gl_TexCoord[0].s < 0.0 || gl_TexCoord[0].s > 1.0) discard;
 if (gl_TexCoord[0].t < 0.0 || gl_TexCoord[0].t > 1.0) discard;
 if (textured > 0) {
  gl_FragColor = texture2D(testTexture, gl_TexCoord[0].xy);
  gl_FragColor = gl_FragColor * alpha;
 } else {
  gl_FragColor = gl_Color * alpha;

As there seem to be two sources for the color (textured and gl_Color, depending on the renderable object) and I do not know how to automatically tell which one to take, I have this extra field "textured" which I have to set manually for each object.

Is there a way to automatically identify the correct source of the fragment color?

Thanks a lot!