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

Author Topic: Resizing sprite in SFML2  (Read 5312 times)

0 Members and 1 Guest are viewing this topic.

l0ud

  • Newbie
  • *
  • Posts: 23
    • View Profile
Resizing sprite in SFML2
« on: September 25, 2009, 08:58:48 pm »
Hello, I had migrated to the newest wersion of SFML and noticed a weird thing with positioning resized sprites.

The resized sprite looks to be moved at some pixels, what gives me unexpected results:
http://img143.imageshack.us/img143/573/wrong.png

In the previous SFML version (1.5) I've got the correct effect:
http://img143.imageshack.us/img143/5971/correct.png

Is there a bug in the new version of SFML? Or maybe i don't know about some changes in api? :)

Thanks for help.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Resizing sprite in SFML2
« Reply #1 on: September 25, 2009, 10:33:35 pm »
Can you show a short source code that shows this problem?
Laurent Gomila - SFML developer

l0ud

  • Newbie
  • *
  • Posts: 23
    • View Profile
Resizing sprite in SFML2
« Reply #2 on: September 25, 2009, 10:52:47 pm »
Code: [Select]
#include <SFML/Graphics.hpp>

int main()
{
    // Create the main rendering window
    sf::RenderWindow App(sf::VideoMode(800, 600, 32), "SFML Graphics");

    // Load the sprite image from a file
    sf::Image Image;
    Image.SetSmooth(false);
    if (!Image.LoadFromFile("gui_button_c.png"))
        return EXIT_FAILURE;

    // Create the sprite
    sf::Sprite Sprite(Image);
    Sprite.SetSubRect(sf::IntRect(2,0,3,23));
Sprite.Resize(300,23);

    Sprite.SetPosition(0.f, 0.f);

    // Start game loop
    while (App.IsOpened())
    {
        // Process events
        sf::Event Event;
        while (App.GetEvent(Event))
        {
            // Close window : exit
            if (Event.Type == sf::Event::Closed)
                App.Close();
        }

        // Clear screen
        App.Clear(sf::Color::White);

        // Display sprite in our window
        App.Draw(Sprite);

        // Display window contents on screen
        App.Display();
    }

    return EXIT_SUCCESS;
}


And the sprite:
http://img148.imageshack.us/img148/9381/guibuttonc.png

The image should stick in the corner of the window...

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Resizing sprite in SFML2
« Reply #3 on: September 25, 2009, 11:03:09 pm »
This program works for me with the latest sfml2 revision (the sprite is in 0, 0).

Make sure that you don't have an old version of the SFML binaries that may conflict. Make sure you recompiled completely the sources.

Or, if it doesn't help and if you have some time to waste, you can try to find the revision in the sfml2 branch at which the problem appeared ;)
Laurent Gomila - SFML developer

l0ud

  • Newbie
  • *
  • Posts: 23
    • View Profile
Resizing sprite in SFML2
« Reply #4 on: September 26, 2009, 10:36:07 pm »
Wel... I had downloaded the newest revision from http://sfml.svn.sourceforge.net/viewvc/sfml/trunk.tar.gz?view=tar

and compiled it with Code::Blocks (mingw). I also ran the batch-build script to link other libraries. Unfortunately, the problem still appears.

Can you find some time to test my compilation? I have no idea, what I'm doing wrong. I have included static version and the binary of example.
http://www.sendspace.com/file/0sf8pd

Thanks

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Resizing sprite in SFML2
« Reply #5 on: September 27, 2009, 11:41:21 am »
Quote
Wel... I had downloaded the newest revision from http://sfml.svn.sourceforge.net/viewvc/sfml/trunk.tar.gz?view=tar

This is not SFML 2, this is a snapshot of the trunk.

Anyway, I downloaded your compiled program and indeed the sprite is offseted. I have to do more tests.
Laurent Gomila - SFML developer

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Resizing sprite in SFML2
« Reply #6 on: September 27, 2009, 12:04:47 pm »
I've found the problem. It appears in SFML 1.6, not SFML 2...
And actually it is fixed in SFML 2 ;)
Laurent Gomila - SFML developer

l0ud

  • Newbie
  • *
  • Posts: 23
    • View Profile
Resizing sprite in SFML2
« Reply #7 on: September 27, 2009, 01:26:09 pm »
Ok, I downloaded the correct version. Everything (excluding fonts) in working now :)