Get pixel data from fbo

How would I get the pixel data from a fbo without displaying the fbo?
I want to check if the pixel on a given coordinate in the fbo has a certain color.

I found a way to do what I want in this thread: http://forum.openframeworks.cc/t/fbo-gt;-ofimage-gt;-save-to-file/3019/13">fbo > ofImage > save to file]http://forum.openframeworks.cc/t/fbo-gt;-ofimage-gt;-save-to-file/3019/13
It works fine. That is, if I create an ofImage with my pixeldata and safe it as a jpg, I get the right thing upside down. Just as described in the other thread.

But in my case I want to use the pixeldata as a mask. So I have a function isOver() which is supposed to check if a certain pixel is inside the (offscreen) mask or not.
n specifies which mask to use (there’s a vector with different masks)

  
  
bool testApp::isOver(int n, float x, float y) {  
    unsigned char * pixels1  = myImages[n].getPixels();  
  
    //just to make sure the point is really inside the valid range  
    x = CLAMP(x,0,ofGetWidth());  
    y = CLAMP(y,0,ofGetHeight());  
  
    //vertical flip, since the pixels are upside down  
    y = ofGetHeight() - y;  
  
    //the mask is green, everything else is black, so it checks for the green value on the specified position  
    if (pixels1[((int)x+(int)y*ofGetHeight())*3+1] != 0)   
          return true;  
    else  
         return false;  
}  
  

As I said, if I try to use those pixels to save a jpg, everything works as expected.
However my check doesn’t work. It kind of does, but sometimes I check for coordinates that are clearly on the green area of the mask and I get a false. I thought maybe the color mode is wrong and I have also alpha information so I have to multiply the thing by 4 instead of 3, but that’s not it. Also I tried to print the pixeldata to the console using cout << pixels1[i] and interate over the whole thing to see what the pixels actually look like but it just gives me a lot of blanks.
Any ideas? It seems my check (x+y*width)*3+1 is somehow off, but I dont see why. The size of the pixel data is width*height*3 and it’s RGB.

In case anyone is interested: I had y*ofGetHeight() instead of y*ofGetWidth() and since my window is almost square, it wasn’t off by much and thus it worked in most cases. But not always… :oops: