SFML community forums

Help => Graphics => Topic started by: cwkx on April 23, 2012, 01:02:19 pm

Title: Efficient way to work ontop of a static image each frame
Post by: cwkx on April 23, 2012, 01:02:19 pm
Hi,

I'm doing something which is similar, but not quite the same as, rendering a movie.

Every frame, I need to override pixel data with CPU operations on top of a read-only sf::Image "staticImage" (this never changes over all frames) - e.g. i'm looking to copy, change, and send the data of the static image extremely efficiently.

Currently i'm just doing:
   
Code: [Select]
dynamicImage.create(staticImage.getWidth(), staticImage.getHeight(), sf::Color(0,0,0,0));
dynamicImage.copy(staticImage, 0, 0);

dynamicImage.setPixel(...);

dynamicTexture.loadFromImage(dynamicImage);


- Could anyone help explain to me to a faster way to do this: I looked at sf::RenderTexture but wasn't sure whether or how I could use this in my situation. I'd like to support larger images, e.g. 8192 x 8192, but currently copying in the way above is about 1 FPS for such sizes.

Thanks
Title: Re: Efficient way to work ontop of a static image each frame
Post by: Laurent on April 23, 2012, 01:04:13 pm
Don't use sf::Image, setPixel is too slow. Use your own raw array of pixels.

Then use Texture::update instead of Texture::loadFromImage to update the texture.
Title: Re: Efficient way to work ontop of a static image each frame
Post by: cwkx on April 23, 2012, 02:10:35 pm
Thanks for the suggestion! I'll experiment with this.