Problem with ofFbo

I have drawn something on my ofFbo object. Then I loaded the ofFbo object content into an ofImage object, using the ofFbo readToPixels function and the ofImage setFromPixels function. When I draw the ofImage on the screen everything works, but when i try to access its pixels, I obtain a weird behavior. I attach the output I obtain when the following code runs:

  
ofFbo fbo;  
fbo.allocate(320, 240);  
  
fbo.begin();  
//draw something  
fbo.end();  
  
ofPixels p;  
fbo.readToPixels(p);  
  
ofImage *im1 = new ofImage;  
im1->setFromPixels(p);  
  
ofImage *im2 = new ofImage;  
im2->allocate(320, 240, OF_IMAGE_COLOR);  
  
for(int i = 0; i < 320*240*3; ++i) im2->getPixelsRef()[i] = im1->getPixelsRef()[i];  
  
im2->reloadTexture();  
  
im1->draw(0,0);  
im2->draw(320,0);  

Why this happens? I need to draw somenthing on a buffer and then drawing on the screen some of the pixels contained in the buffer…how can I do that? Thanks.

the problem is how you are copying the pixels, to make it easier you can use:

  
  
img1->getPixelsRef().cropTo(img2->getPixelsRef(),0,0,320,240);  
img2->update();  
  

which will copy an area from 0,0 and width,height 320,240 in img2

Nothing changed. This way I can copy the whole im1 into im2 and drawing it on the screen, but I was already able to do that. I need to store only some pixels of im1 into im2. For example, if I want to store a third of im1 in im2 with

  
for(int i = 0; i < 320*240; ++i) im2->getPixelsRef()[i] = im1->getPixelsRef()[i];    

I obtain the following output. In general i would like to select any single pixel of im1 and put it in the same location in im2. Another strange thing is that im2 seems to overlap im1 (you can see the stripes in trasparency) even if im2 is drawn from (320, 0), end when I don’t draw im1 these overlapping stripes disappear. I also noticed that, since im1 is an image that changes over time, the stripes seems to vary imperceptibly too, it’s like im2 is drawn “spread” on the windows.

Solved. The problem was that fbo.readToPixels() return a OF_IMAGE_COLOR_ALPHA, and i stored it in a OF_IMAGE_COLOR.