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

Author Topic: Sprite clipping  (Read 413 times)

0 Members and 1 Guest are viewing this topic.

CZmisaCZ

  • Newbie
  • *
  • Posts: 1
    • View Profile
Sprite clipping
« 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


Render


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);

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 10821
    • View Profile
    • development blog
    • Email
Re: Sprite clipping
« Reply #1 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.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

 

anything