Q:

Colouring 3D objects

I have many objects in my scene and I want to colour every object with different colours. Now, my fragment shader consists of :
void main (void)\
{\
     gl_FragColor = vec4(0.82, 0.41, 0.12 ,1.0);\
}";

and the vertex shader consists of :
attribute highp vec4    myVertex;\
uniform mediump mat4    myPMVMatrix;\

void main(void)\
{\
gl_Position = myPMVMatrix * myVertex;\
}";

and hence it colours each object with the same colour. Can anyone tell how can I colour differently ? I have prepared a 2D array consisting of the colours for all the objects. I can't figure out how to pass them to the fragment shader or how to change the fragment shader and vertex shader code ?

A:

The best way to color objects individually is to pass a uniform (like you did with myPMVMatrix) containing the color you want, for each object.
You would have a uniform vec4 objectColor in the fragment shader that you can directly use inf gl_FragColor.
The fragment shader would look like:
uniform mediump vec4 myColor;\
void main (void)\
{\
     gl_FragColor = myColor;\
}";

and you would pass it exactly like you passed your myPMVMatrix, just with the word myColor instead of myPMVMatrix.

