system
November 10, 2002, 4:29pm
1
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,w h*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
Gavin
November 12, 2002, 3:02am
3
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