ofTexture vs ofImage, which is more efficient?

Hi, I’m trying to make a Button with ofRectRounded, and I would like to apply color gradient to it.

After some research, I found out I could either use ofTexture or ofImage for coloring pixel by pixel.

As a newbie, I have no idea what the difference is between two for this job, and I would like to know which one is at least more efficient cpu wise.

1 Like

the main difference is where the data is maintained.

ofimage is maintained in the cpu memory, or ram.
oftexture in the gpu, this one is faster.

actually ofImage maintains a copy in memory and another in ram, sp both ofTexture and ofImage are equally fast. ofImage is just a convenience class that knows how to load an image from disk, contains ofPixels (ram) and then upload those to the graphics card through an ofTexture.

The only difference between using your own pixels to create the image and then upload manually to an ofTexture is that you can get rid of the pixels when you don’t need them any more while ofImage keeps the ram copy so it takes more memory.

If you don’t need to care about ram usage it’s usually easier and as fast to use ofImage, if you have ram usage problems then ofTexture can help

3 Likes