SFML community forums

Help => Graphics => Topic started by: CZmisaCZ on July 07, 2023, 11:11:43 am

Title: Sprite clipping
Post by: CZmisaCZ on July 07, 2023, 11:11:43 am
Im loading this texture and cutting it to sprites,
but for some reason it is showing these white lines from the sprite next to it

Texture
(https://cdn.discordapp.com/attachments/175298431294636032/1126791106873536562/image.png)

Render
(https://cdn.discordapp.com/attachments/175298431294636032/1126791107280379904/image.png)

Im using this to load
    GUItexture = new sf::Texture;
    grayout = new sf::Sprite;

    GUItexture->loadFromFile("./data/GUI.png");
    grayout->setTextureRect(sf::IntRect(Tile_scale * 3, 5 * Tile_scale, Tile_scale, Tile_scale));
    GUItexture->setSmooth(true);

and this to render:
    //top grayot
    grayout->setPosition(sf::Vector2f(0 ,  -((float)Tile_scale )));
    grayout->setRotation(0);
    window->draw(*grayout);

    //left
    grayout->setPosition(sf::Vector2f( -Tile_scale,  + ((floatTile_scale  * (mapa->mapy))));
    grayout->setRotation(270);
    window->draw(*grayout);
Title: Re: Sprite clipping
Post by: eXpl0it3r on July 07, 2023, 12:57:14 pm
It's called texture bleeding and can have different causes and solutions.
When OpenGL decides to use part of a texture, but then has to move it around to positioning it on non-integer positions, it might end up using some of the surrounding texture pixels to fill in the gap.

First make sure you're always rendering on integer positions and move views only on integer positions.
One way to prevent this is to leave a 1px space between the tiles.
Another way that is usually the most stable one, is to render your tilemap onto a render texture and use that to render to your window. That way OpenGL has to fully rasterize the texture beforehand.