Talk:OpenGL Selection Using Unique Color IDs

From GPWiki
Jump to: navigation, search

Why don't you use glColorub() to set the color?


In my projects, I use code that looks more like this: if (render_colours) { GLbyte colour[3]; int id = 1; /* make this your desired id, but if clear colour is black then start from 1 not 0 */ colour[0] = id; colour[1] = id >> 8; colour[2] = id >> 16; glColor3ub(colour[0], colour[1], colour[2]); }

And to reform the ID from the picked colour: int id = pixel[0] + (pixel[1] << 8) + (pixel[2] << 16);