SFML community forums

Help => Graphics => Topic started by: Krssst on August 17, 2013, 04:36:37 pm

Title: Different behavior of sf::Text with SFML 2.0 and SFML 2.1
Post by: Krssst on August 17, 2013, 04:36:37 pm
Hello,

When compiling a game I wrote with SFML 2.1 instead of SFML 2.0, I noticed that text alignment was messed up. I then ran an experiment with a simple program :
#include <stdio.h>
#include "SFML/Window.hpp"
#include "SFML/Graphics.hpp"

int main(int argc, char *argv[])
{
        sf::RenderWindow window;
        window.create(sf::VideoMode(640, 480), "Manger");
        sf::Font font;
        font.loadFromFile("font.ttf");
        sf::Text text("Manger", font);
        text.setColor(sf::Color(255, 255, 255));
        text.setCharacterSize(60);
        sf::FloatRect bounds = text.getLocalBounds();
        sf::RectangleShape rectangle(sf::Vector2f(bounds.width, bounds.height));
        rectangle.setOrigin((int)(bounds.width/2), (int)(bounds.height/2));
        rectangle.setFillColor(sf::Color(0, 0, 0, 0));
        rectangle.setOutlineColor(sf::Color(255, 0, 0));
        rectangle.setOutlineThickness(1.0f);
        text.setOrigin((int)(bounds.left+bounds.width/2), (int)(bounds.top+bounds.height/2));
        text.setPosition(320, 240);
        rectangle.setPosition(320, 240);

        while(true)
        {
                window.clear();
                window.draw(rectangle);
                window.draw(text);
                window.display();
                sf::sleep(sf::milliseconds(100));
        }
        return 0;
}
 

Here is what I have with SFML 2.0:
(http://s21.postimg.org/89c26pmjr/sfml2_0.png)

And with SFML 2.1:
(http://s13.postimg.org/a45muakiv/sfml2_1.png)

Am I missing something?
I never really understood bounding boxes with text, so I may be doing something wrong...
The rectangle is supposed to represent the bounding box of the text (and, hopefully, is precisely at the center of the window). With SFML 2.1, the bottom of the 'g' is cropped, and there is a small whitespace on the left of the 'M'.

I am using the SFML 2.1 precompiled binaries for Visual C++ 11 (32 bits)

EDIT: tested on Linux with git version versus 2.0 ; same problem.
Title: Re: Different behavior of sf::Text with SFML 2.0 and SFML 2.1
Post by: Laurent on August 17, 2013, 05:06:07 pm
I see what's wrong, I'll fix it soon. Thanks for your feedback :)
Title: Re: Different behavior of sf::Text with SFML 2.0 and SFML 2.1
Post by: Krssst on August 17, 2013, 06:04:09 pm
Ok, thank you :)
Title: Re: Different behavior of sf::Text with SFML 2.0 and SFML 2.1
Post by: Laurent on August 17, 2013, 07:24:45 pm
Done.
Title: Re: Different behavior of sf::Text with SFML 2.0 and SFML 2.1
Post by: Krssst on August 17, 2013, 07:42:59 pm
Just tested the fix: it works :)