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

Author Topic: SFML2 PNG difference  (Read 1580 times)

0 Members and 1 Guest are viewing this topic.

Groogy

  • Hero Member
  • *****
  • Posts: 1469
    • MSN Messenger - groogy@groogy.se
    • View Profile
    • http://www.groogy.se
    • Email
SFML2 PNG difference
« on: December 28, 2010, 01:07:01 am »
I just noticed a thing when I tried to render a PNG image. What I expected was this image:

But what I got was this:


Don't mind the red background, just me trying something out.
Anyway I don't understand why the transparency doesn't work and why the edges are cut off? Is it something I've done wrong?

I noticed this when I for the first time tried rendering something trough my game engine. The code for my test class looks like this:
Code: [Select]
class ImageEntity : public GraphicalEntity
{
public:
static ImageEntity *New()
{
ImageEntity *object = new ImageEntity();
object->Init();
return object;
}

protected:
void Init()
{
GraphicalEntity::Init();
myImage.LoadFromFile("data/test.png");
mySprite.SetImage(myImage);
}

void InitReceiver()
{
myReceiver = new ImageReceiver(*this);
}

void Render(sf::RenderTarget &target, sf::Renderer &renderer) const
{
target.Draw(mySprite);
}

sf::Image myImage;
sf::Sprite mySprite;
};


There's a lot of more code involved but the engine is getting quite huge and has a asynchronous design so it's kinda hard to show all the relevant code.
Developer and Maker of rbSFML and Programmer at Paradox Development Studio

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
SFML2 PNG difference
« Reply #1 on: December 28, 2010, 08:01:56 am »
Well, if it's just loading a PNG and displaying it with a sprite, it shouldn't be hard to write a minimal code that reproduces this problem.
Laurent Gomila - SFML developer

Groogy

  • Hero Member
  • *****
  • Posts: 1469
    • MSN Messenger - groogy@groogy.se
    • View Profile
    • http://www.groogy.se
    • Email
SFML2 PNG difference
« Reply #2 on: December 28, 2010, 01:59:21 pm »
Aight okay, this code rendered exactly what it should produce.
Code: [Select]
int main()
{
sf::RenderWindow window(sf::VideoMode(800, 600), "Test");
sf::Image image;
sf::Sprite sprite;
image.LoadFromFile("data/test.png");
sprite.SetImage(image);
window.Clear(sf::Color(255, 0, 0));
window.Draw(sprite);
window.Display();
sf::Sleep(5);
return 0;
}


Could the error come from that a GraphicalEntity inherits from sf::Drawable?
*EDIT*
Tried but still worked like it should...


*REVELATION*
AAAAAH I'm so damn stupid.... The artifact comes from the fact that I do not clear every frame.... So the alpha transparency just stacks up for each frame and eventually reaches 255 making it totally opaque. And the cutoffs is not seen with the transparency but becomes visible when it turns opaque. Oooh damn what a huge mistake by me. I did the part managing the window so long ago that I forgot that it only cleared when the Rendering thread was created. So there actually is no error, just me that forgot :)
Developer and Maker of rbSFML and Programmer at Paradox Development Studio