I have a cube which has a texture on it (picture on each face of it), which I want to retain.
Also, I have a sphere that orbits the cube, which I just want to color.
Now, I can display the textures, or color the items with the fragment/vertex shader, but I would like to change the color of just the sphere, but leave the cube unchanged.
Ultimately, then, I want to apply lighting and shading to both objects, equally. But, want to start out with baby steps.
Here are my vertex and fragment shaders
//fragment
//varying vec4 color;
//image texture
uniform sampler2D myTexture;
varying vec2 vTexCoord;
void main (void) {
//gl_FragColor = vec4(1.0, 0.5, 0.0, 0.0);
//one or the other gives me the desired results
gl_FragColor = texture2D(myTexture, vTexCoord);
}
It looks like you’ve just about got the vertex color plumbed into your shader already.
Once you have that, you have options.
You could pass in a uniform that tells you whether to apply the texture or apply the color. But it might be simpler to just apply both, modulating them together (e.g. color * texture). Consider that 1 * X = X and X * 1 = X.
Here’s a wiki page in the OpenGL Wiki on them: Uniform (GLSL). Basically, they’re values you can pass in from your C++ program that are effectively constant for all of the primitives in a draw call. You can use them to pass in state that doesn’t need to change vertex-to-vertex or fragment-to-fragment.
However, if you just use the modulate approach, you probably don’t need one.
If you don’t have a good book on OpenGL programming, I’d suggest you pick one up. Alternatively, you can consult the online OpenGL Wiki, the OpenGL man pages, and various OpenGL tutorials around the net.