Counting pixels of a given color

I would like to count the pixels that are on the screen of a given color lets say represented by variables r g and b

I think the way I should do this is something like the following, but I can’t seem to be able to finish

buff=(unsigned char ) calloc(1,wh*3)
glReadPixels(0,0,w,h,GL_RGB,GL_UNSIGNED_BYTE,buff)

is that right?
what do I do now with buff to get each pixel information out of it?

Thanks
Joan

Hi !

In the buffer you get 3 bytes for each pixel pos=((y*width+x)*3) the first byte (pos) is the red color component in the range 0-255 the next (pos+1) is green and the last one (pos+2) is blue.

Mikael

To make your life a little easier make your buffer an array of structs of…
typedef struct RGB
{
GLubyte r, g, b;
}SRGB;

and malloc your array
(SRGB*) malloc(sizeof(SRGB) * width*height);

ok… so then you access pixels

myarray[i + (j*width)].r