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

Author Topic: Strange sprite rendering after rotation  (Read 1116 times)

0 Members and 1 Guest are viewing this topic.

dr.rock

  • Newbie
  • *
  • Posts: 2
    • View Profile
    • Email
Strange sprite rendering after rotation
« on: March 06, 2014, 06:58:55 pm »
Hi!

I have a problem with rendering sprites.
The are rendered OK unless they are rotated.

First image shows basic sprite rendering, the second - after rotation.



Also if rotation angle is 0, 90, 270 or 360 degree there's no problem.
I tried on two different PCs (but both running linux mint), i tried to turn on V Sync, anti-aliasing, texture smoothing but no result.

Here's a code example:
void test()
{
sf::ContextSettings settings;
settings.antialiasingLevel = 8;

    sf::RenderWindow mWindow(sf::VideoMode(1024, 768), "My window", sf::Style::Default, settings );
    mWindow.setVerticalSyncEnabled(true);
    mWindow.setFramerateLimit(60);

    sf::Texture back_texture;
    back_texture.loadFromFile("assets/back.png");
    back_texture.setSmooth(true);

    sf::Sprite bgSprite;
    bgSprite.setTexture(back_texture);
    sf::Texture m_texture;
    m_texture.loadFromFile("assets/missile_tmp.png");
    sf::Sprite mSprite;
    mSprite.setTexture(m_texture);

    //!!!!!!!!!!!PROBLEM IS HERE !!!!!!!!!!!!
     mSprite.setRotation(45);

    mSprite.setPosition(300,0);

    sf::Clock clock;
        sf::Time timeSinceLastUpdate = sf::Time::Zero;
        sf::Time timePerFrame = sf::seconds( 1.0f / 60.0f );

        while( mWindow.isOpen() )
        {
        sf::Time dt = clock.restart();
                timeSinceLastUpdate += dt;

                // run at constant time intervals
                while( timeSinceLastUpdate > timePerFrame )
                {
                        timeSinceLastUpdate -= timePerFrame;

            //processInput;
            sf::Event event;
            while( mWindow.pollEvent(event) )
            {
                if (event.type == sf::Event::Closed)
                    mWindow.close();
            }
            //some update here
                }
        mWindow.clear();
        mWindow.setView(mWindow.getDefaultView());
        mWindow.draw(bgSprite);
        mWindow.draw(mSprite);
        mWindow.display();
        }
}
 


What am i doing wrong?




zsbzsb

  • Hero Member
  • *****
  • Posts: 1409
  • Active Maintainer of CSFML/SFML.NET
    • View Profile
    • My little corner...
    • Email
Re: Strange sprite rendering after rotation
« Reply #1 on: March 06, 2014, 07:08:06 pm »
Try calling Texture.setSmooth(true);
Motion / MotionNET - Complete video / audio playback for SFML / SFML.NET

NetEXT - An SFML.NET Extension Library based on Thor

dr.rock

  • Newbie
  • *
  • Posts: 2
    • View Profile
    • Email
Re: Strange sprite rendering after rotation
« Reply #2 on: March 06, 2014, 07:11:24 pm »
Thanks zsbzsb!
I thought i already tried it, but it appears i enabled smoothing for background texture that is not rotated, it is so stupid  ;D
Now it seems to work OK))