getting pixels from a texture

Hello guys!

Is there a way for getting pixels from a texture. I mean, I have an ofTexture and I want to put the pixels from this texture into a ofxCvColorImage.
Is this possible?

Thank you so much!


hey Berio,

it’s not so easy. an ofTexture doesn’t store its pixels - it just uploads them to the graphics card and then holds an ID that is used to access those pixels on the graphics card. AFAIK the only way to do this is with a buffer read-back: write the pixels to screen or to an FBO and then read back the pixel data using the grabScreen() method on an ofImage. but this is very slow.

it’d be better if you could somehow intercept the pixel data before it gets uploaded to the video card: where are you calling loadData on the ofTexture? can you make a copy of the pixel data there?

Thanks Damian, I understand now

I will see what can I do.


Reading back texture/FBO data is best done with pixel buffer objects (PBOs). It’s actually quite fast if properly applied. I’ve had good luck with the split readback technique, which uses 2 PBOs to read 1/2 of the image each asynchronously. There’s a good tutorial here:

There was a similar question posted at where i posted a simple (but in retrospect primitive) solution. wow, never used PBO’s before, but that article really does sell it :stuck_out_tongue: thanks!