I want to write a shader program which will render each triangle of the mesh in distinct color (so I could pick one triangle). I tried to use gl_PrimitiveID, but it always returns 0, for example:
#version 330
out uvec3 FragColor;
void main()
{
FragColor = uvec3(0.0, 0.0, gl_PrimitiveID);
}
This shader always renders black color.
To achieve what you want in a simplest way I would pass additional vertex array as color attribute containing colors per triangle into vertex shader.Then pass it as varying output into your fragment shader.That's it.This way you can specify exactly colors for each vertex.