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.