I'm working in openFrameworks, a set of C++ libraries.

What I'm trying to do is simply 'erase' certain pixels of an ofImage (a class that loads/displays an image, and has access to it's pixel array) when a shape (an eraser) passes over the appropriate pixels of the image. Pretty simple stuff - I think - but I'm having a mental block!

ofImage has two methods - getPixels() and getPixelsRef() that seem to approach what I am trying to do, but the methodology I am using is not quite giving me the results I want.

Here is an example of an attempt to update the pixels of a foreground image from the pixels of a background image:

ofPixelsRef fore = foreground.getPixelsRef();
ofPixelsRef back = background.getPixelsRef();

for(int x = 0; x < foreground.getWidth()/2; x++) {
    for (int y = 0; y < foreground.getHeight(); y++) {
        ofColor c = back.getColor(x, y);
        fore.setColor(x, y, c);
    }
}

foreground.setFromPixels(fore);

and here is an attempt to statically colour the foreground with a predetermined colour (which I think is what I want to do, with a transparent white ?!?):

ofPixelsRef fore = foreground.getPixelsRef();
ofColor c(0, 127);
for(int x = 0; x < foreground.getWidth(); x++) {
    for (int y = 0; y < foreground.getHeight(); y++) {
        fore.setColor(x, y, c);
    }
}

foreground.setFromPixels(fore);

Neither are quite where I want to get to, but I think they're a stab in the right direction. If anyone has any ideas on where to proceed, I'm all ears.

I'd consider moving to the ofFbo class, or even GLSL if there's a clean lead/example. Feel free to post vanilla C++ as well, and I'll see what I can do about porting it to oF.

Thanks,

~ Jesse

有帮助吗?

解决方案

FYI, I've found a solution detailed at this page: http://forum.openframeworks.cc/index.php/topic,12899.0.html

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top