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

Author Topic: Grey box displaying around sprite's loaded image.  (Read 3085 times)

0 Members and 1 Guest are viewing this topic.

XBigTK13X

  • Newbie
  • *
  • Posts: 3
    • View Profile
Grey box displaying around sprite's loaded image.
« 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

netdragon

  • Newbie
  • *
  • Posts: 1
    • View Profile
Grey box displaying around sprite's loaded image.
« Reply #1 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):

Svenstaro

  • Full Member
  • ***
  • Posts: 222
    • View Profile
Grey box displaying around sprite's loaded image.
« Reply #2 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.

OniLinkPlus

  • Hero Member
  • *****
  • Posts: 500
    • View Profile
Grey box displaying around sprite's loaded image.
« Reply #3 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.
I use the latest build of SFML2

CyanPrime

  • Newbie
  • *
  • Posts: 18
    • View Profile
Grey box displaying around sprite's loaded image.
« Reply #4 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):
This helped me. Thank you. :)