SFML community forums

Help => Graphics => Topic started by: XBigTK13X on April 01, 2011, 12:57:42 am

Title: Grey box displaying around sprite's loaded image.
Post by: XBigTK13X on April 01, 2011, 12:57:42 am
I am loading a PNG file into an instance of Sprite and then calling draw. The image displays at the proper location, but also has a grey bounding box that is not part of the image itself. This box resizes with the sprite when the window is resized. How can this box be disabled/hidden?

Code where the error originates:
Code: [Select]
   
    sf::Image sfi;
    sf::Sprite sprite;
    if (!sfi.LoadFromFile(filename))
    {
        Log::debug("Failed to load file");
        return;
    }
    sprite.SetPosition(origin.x,origin.y);
    sprite.SetImage(sfi);
    target.Draw(sprite);


A screenshot showing the bounding box.
http://imgur.com/sEAsq
Title: Grey box displaying around sprite's loaded image.
Post by: netdragon on April 01, 2011, 01:26:58 am
I'm a teammate of the OP and have new information. I just found a solution of calling SetSmooth(false) but not sure why that prevented the artifact. It'd be great if we still had the option of smoothing. Any ideas?

Code: [Select]

void ViewBase::drawImage(sf::RenderWindow & target, const std::string & filename, const Point & origin)
{
    sf::Image sfi;
    sfi.SetSmooth(false);
    sf::Sprite sprite;
    if (!sfi.LoadFromFile(filename))
    {
        Log::debug("Failed to load file");
        return;
    }
    sprite.SetImage(sfi);
    sprite.SetPosition(origin.x,origin.y);
    target.Draw(sprite);
}


The image in question (as on disk, without the artifact created when displayed in SFML): (http://img130.imageshack.us/img130/7774/cursormask.png)
Title: Grey box displaying around sprite's loaded image.
Post by: Svenstaro on April 01, 2011, 02:15:59 am
Try to make the graphical content of your image a little bit (5px or so) smaller than the canvas and make the rest completely transparent.
Title: Grey box displaying around sprite's loaded image.
Post by: OniLinkPlus on April 01, 2011, 04:05:22 am
It's the stupid Bilinear filtering that Laurent set to be turned on by default. The gray border happens because it's blending the image with the surroundings.
Title: Grey box displaying around sprite's loaded image.
Post by: CyanPrime on April 01, 2011, 04:27:33 am
Quote from: "netdragon"
I'm a teammate of the OP and have new information. I just found a solution of calling SetSmooth(false) but not sure why that prevented the artifact. It'd be great if we still had the option of smoothing. Any ideas?

Code: [Select]

void ViewBase::drawImage(sf::RenderWindow & target, const std::string & filename, const Point & origin)
{
    sf::Image sfi;
    sfi.SetSmooth(false);
    sf::Sprite sprite;
    if (!sfi.LoadFromFile(filename))
    {
        Log::debug("Failed to load file");
        return;
    }
    sprite.SetImage(sfi);
    sprite.SetPosition(origin.x,origin.y);
    target.Draw(sprite);
}


The image in question (as on disk, without the artifact created when displayed in SFML): (http://img130.imageshack.us/img130/7774/cursormask.png)
This helped me. Thank you. :)