Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Mirroring a texture  (Read 2403 times)

0 Members and 1 Guest are viewing this topic.

Tez

  • Newbie
  • *
  • Posts: 4
    • View Profile
Mirroring a texture
« on: June 07, 2018, 07:02:23 am »
I know that you can flip a sprite along its axes with setScale, but is it possible to flip a texture? I need to mirror a texture along its vertical axis.

Update: As a temporary solution I have implemented my own mirroring method. However this requires converting the texture to an image and back again. A solution which would manipulate the texture itself would be preferable.
sf::Image UTIL_flipImage(sf::Image *pImage)
{
        sf::Vector2u sourceImageDimensions = pImage->getSize();
        sf::Image result;
        result.create(sourceImageDimensions.x, sourceImageDimensions.y);

        for ( int16_t sourceImageRowIndex = 0; sourceImageRowIndex < sourceImageDimensions.y; sourceImageRowIndex++ )
        {
                for( int16_t rowPixelIndex = 0; rowPixelIndex < sourceImageDimensions.x; rowPixelIndex++ )
                {
                        result.setPixel(rowPixelIndex, sourceImageRowIndex, pImage->getPixel(sourceImageDimensions.x - (rowPixelIndex + 1), sourceImageRowIndex) );
                }
        }
        return result;
}
« Last Edit: June 07, 2018, 07:37:35 am by Tez »

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 10947
    • View Profile
    • development blog
    • Email
Re: Mirroring a texture
« Reply #1 on: June 07, 2018, 07:54:59 am »
You can use a shader for it. And why not use setScale on a sprite?
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

Tez

  • Newbie
  • *
  • Posts: 4
    • View Profile
Re: Mirroring a texture
« Reply #2 on: June 07, 2018, 08:02:11 am »
This texture is added to a list of layers to render into a single texture using a RenderTexture. Due to this organization it would be difficult to use a sprite.

Could you elaborate on the use of shaders to mirror textures?

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 10947
    • View Profile
    • development blog
    • Email
Re: Mirroring a texture
« Reply #3 on: June 07, 2018, 08:12:38 am »
Is it always mirrored? Then you could also just edit the texture in an image editor.

If you have a list, then you may need to store a mirrored property alongside which then would work again with a sprite. I think you could also achive it in a vertex array.

Check the tutorial on shaders to understand the concept: https://www.sfml-dev.org/tutorials/2.5/graphics-shader.php
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/