Hi Folks,
So I have a sf::Image that I update. The image is quite large 5680 X 4178, so when I update the sf::Image, I ensure to pass in the sf::IntRect of the area that I am working on - see below. This works fine for my needs and it is pretty fast to update the IntRect area. (0.047 secs).
//set Pixel colour for all pixels in regionIntRect that match colourToCheck
void drawEngine::setImagePixelColour(sf::Image *passed_Image, sf::Color colourToCheck, sf::Color colourToSet, sf::IntRect regionIntRect)
{
for (int y = regionIntRect.top; y < (regionIntRect.height + regionIntRect.top); y++)
{
for (int x = regionIntRect.left; x < (regionIntRect.width + regionIntRect.left); x++)
{
if (passed_Image->getPixel(x, y) == colourToCheck)
{
passed_Image->setPixel(x, y, colourToSet);
}
}
}
}
However I am finding that update texture command is a bit slower. (0.27 secs) to run the below. Now I know the sf::Texture update method is having to load into the graphics memory so it will always be slower.
(regionLandHighlightTexture is the sf::Texture and landHighlightImageToDisplay is the sf::Image that I modified via the above method.)
regionLandHighlightTexture.update(landHighlightImageToDisplay);
Now I know the sf::Texture update method is having to load into the graphics memory so it will always be slower. I was wondering if there was a way to make to the update faster.
Basically I know the area of the texture that needs updating from the IntRect that I modified. However when I check the update methods, I don't see one where I can pass in an IntRect, i.e. only update this portion. I do see this method which is very similiar.
(What does "x X offset in the texture where to copy the source image" mean in regards to this method?)
void update (const Uint8 *pixels, unsigned int width, unsigned int height, unsigned int x, unsigned int y)
However I don't understand how I can get an array of pixels from my sf::Image using the sf::IntRect that I modified. I don't see any method that can pull out an array of pixels using sf::IntRect as part of the sf::Image class. I do see the below method but I don't really understand what it is doing. It seems to be pulling out the entire sf::Image pixel array? Whereas I only want a small portion of the sf::Image pixel array.
const Uint8 * getPixelsPtr () const