Reading FBO data to ofPixels - weird error

Hi,

I’m trying to understand the gpuParticleSystem example and have been playing around loading data to FBOs and reading them back, but there is a problem that I cannot figure out.

When I load data to an FBO with getTextureReference().loadData(.....) everything is fine. But when I try to read it back like this in update() and print just for debugging, some of the pixels are always changing. I tried to wrap it to fbo.begin()/end() as well but didn’t make any difference.

ofPixels pixels;
fbo1.getTextureReference().readToPixels(pixels);

ofLog(OF_LOG_NOTICE) << "FBO1";
for(int x = 0; x < textureRes; x++){
    for(int y = 0; y < textureRes; y++){
        ofLog(OF_LOG_NOTICE) << x << " " << y << ": " << pixels.getColor(x, y);
    }
}

And the output is something like:

[notice ] FBO1
[notice ] 0 0: 82, 62, 0, 255
[notice ] 0 1: 47, 32, 74, 255
[notice ] 1 0: 166, 149, 0, 255
[notice ] 1 1: 94, 0, 241, 255
[notice ] FBO1
[notice ] 0 0: 82, 62, 0, 255
[notice ] 0 1: 10, 32, 74, 255
[notice ] 1 0: 166, 149, 0, 255
[notice ] 1 1: 94, 0, 241, 255
[notice ] FBO1
[notice ] 0 0: 82, 62, 0, 255
[notice ] 0 1: 11, 160, 74, 255
[notice ] 1 0: 166, 149, 0, 255
[notice ] 1 1: 94, 0, 241, 255

I’m attaching the example code.

Thanks so much for the help!

pingPongExample.zip (35.2 KB)

1 Like

This is a bit of a funny one, but what you’re seeing is a weird eccentricity (my lack of low-level graphics knowledge prevents a better word) resulting from data formats.

Since you allocate your FBO as a float-based type here

fbo1.allocate(textureRes,textureRes,GL_RGB32F);

you must load the data into float pixels like so

ofFloatPixels pixels;
fbo1.getTextureReference().readToPixels(pixels);

so, go ahead and change that one line, and you’ll see your pixels stop changing!

1 Like

Haha, yes, thanks so much @robotconscience , spent so much time trying to understand what was going on and could not simplify the original example more than this on the way.