If you do not have a valid texture specified for the sampler, the texture2D
call will return transparent black — vec4(0.0, 0.0, 0.0, 0.0)
. Multiplying by that value will always produce black again.
Instead of trying to use “no texture”, use a texture which has exactly one pure white texel. This will cause the multiplication to yield the u_color
.
Or, you can simply switch between two shader programs, one for untextured geometry and one for textured geometry. Switching programs (gl.useProgram
) is not very expensive.