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

Author Topic: Different behavior of sf::Text with SFML 2.0 and SFML 2.1  (Read 2792 times)

0 Members and 1 Guest are viewing this topic.

Krssst

  • Newbie
  • *
  • Posts: 11
    • View Profile
    • Email
Different behavior of sf::Text with SFML 2.0 and SFML 2.1
« 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:


And with SFML 2.1:


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.
« Last Edit: August 17, 2013, 04:56:38 pm by Laurent »

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: Different behavior of sf::Text with SFML 2.0 and SFML 2.1
« Reply #1 on: August 17, 2013, 05:06:07 pm »
I see what's wrong, I'll fix it soon. Thanks for your feedback :)
Laurent Gomila - SFML developer

Krssst

  • Newbie
  • *
  • Posts: 11
    • View Profile
    • Email
Re: Different behavior of sf::Text with SFML 2.0 and SFML 2.1
« Reply #2 on: August 17, 2013, 06:04:09 pm »
Ok, thank you :)

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: Different behavior of sf::Text with SFML 2.0 and SFML 2.1
« Reply #3 on: August 17, 2013, 07:24:45 pm »
Done.
Laurent Gomila - SFML developer

Krssst

  • Newbie
  • *
  • Posts: 11
    • View Profile
    • Email
Re: Different behavior of sf::Text with SFML 2.0 and SFML 2.1
« Reply #4 on: August 17, 2013, 07:42:59 pm »
Just tested the fix: it works :)

 

anything