Hello,
I'm encountering an issue while rendering a Text on a RenderTexture, then binding it to a Sprite before drawing it on a RenderWindow. I'm not sure if I'm doing something wrong here or if I should file a bug report.
This is basically what I'm doing (this is a condensed version of my
GitHub hosted project) :
#include <iostream>
#include <string>
#include <SFML/Graphics/RenderWindow.hpp>
#include <SFML/Window/Event.hpp>
#include <SFML/Graphics/RenderTexture.hpp>
#include <SFML/Graphics/Sprite.hpp>
#include <SFML/Graphics/Text.hpp>
using namespace std;
int main()
{
sf::RenderWindow m_window;
sf::Event m_event;
sf::RenderTexture m_texture;
sf::Sprite m_sprite;
sf::Text m_text;
string m_title;
bool run;
run = true;
m_title = "Conversation";
m_window.create(sf::VideoMode(800,
600),
m_title);
m_window.setFramerateLimit(60);
m_window.setKeyRepeatEnabled(false);
m_text.setString(m_title);
m_text.setCharacterSize(60);
m_text.setColor(sf::Color(255, 127, 0));
m_text.setStyle(sf::Text::Regular);
// getGlobalBounds() does not return sufficient values.
m_texture.create(m_text.getGlobalBounds().width, m_text.getGlobalBounds().height);
m_texture.clear();
m_texture.draw(m_text);
m_texture.display();
m_sprite.setTexture(m_texture.getTexture(), true);
m_sprite.move(0, 0);
cout << "Text height : " << m_text.getGlobalBounds().height << std::endl;
cout << "Texture height : " << m_texture.getSize().y << std::endl;
cout << "Sprite height : " << m_sprite.getGlobalBounds().height << std::endl;
while (run)
{
m_window.clear();
while (m_window.pollEvent(m_event))
{
if (m_event.type == sf::Event::Closed)
{
run = false;
}
}
m_window.draw(m_sprite);
m_window.display();
}
return EXIT_SUCCESS;
}
Here is a screenshot showing the issue (I'm on a dual screen setup with boosted accessibility options turned on, don't be afraid)
As you can see, text is cut off, and there is even rendering glitches between "s" and "a". I'm using the default font though (and already tried others - such as Neverwinter.ttf - and saw the same remaining issue anyway).
I already saw bug reports about get{Local|Global}Bounds() not handling trailing white spaces, but I'm not sure this is related.
I'm using Arch Linux with Nvidia official driver, in case that would matters.
Thanks.