I’m using a selection mechanism which assigns an ID color to every primitive in the backbuffer so that it can be identified (picked) with the mouse. But my code is a fudge and only generates a limited number of colors. Can anyone provide code for generating unique colors for each object (10000 or more). 32 bit color is assumed.
If you have an unsigned integer value for representing the primitive IDs, you can try
GLuint id;
//assign id
red = id & 255;
green = (id>>8) & 255;
blue = (id>>12) & 255;
alpha = (id>>16) & 255;
>> is the right bit-shift operator and &255 is a masking of the 8 least significant bits.
This results in a binary like representation of the id, but with basis 256 instead of 2. red represents the least significant byte and alpha the most significant byte.
Use glColor4ub(red,green,blue,alpha) and replace the arguments with the values from my previous post. You can represent all possible unique 32 bit values.
I guess gl picking should at least be mentioned here as an alternative. In my experience, a good picking setup simply can’t be beaten. While somewhat more difficult to implement, it avoids some of the pitfalls of the color ID method.