I need to implement a class (inherited from sf::Image) that allows me to find 'distance' between two images. By that I mean a measure of how the images differ from each other pixel by pixel (the specifics don't matter). The main idea is to take an image, draw something on it and look at how much it changed. To draw something I need to convert my image into an sf::RenderTexture (probably?). The problem is that I can't draw on sf::RenderTexture inside of a class (only in the main loop directly), it just shows me an empty dark blue background for some reason. How can I fix that?
You really shouldn't derive from sf::Image
(see also Composition over Inheritance).
To go from a sf::RenderTexture
to an sf::Image
you can use renderTexture.getTexture().copyToImage()
, but keep in mind that requires transferring of data from the GPU's VRAM to the CPU's RAM and as such it can be rather slow, meaning you may not want to do that every frame, but only when you need it.
To then compare images, you can access the pixel information with getPixelsPtr()
on the sf::Image
instance.
Don't hesitate to check out the official documentation on how to use sf::Image
or sf::RenderTexture
.