I found a case in which text rendering is broken. After spending most of my day minimizing the code, I came up with the following minimal example.
#include <SFML/Graphics.hpp>
#include <SFML/OpenGL.hpp>
int main()
{
sf::RenderWindow window(sf::VideoMode(800, 600), "SFML window");
sf::Font font;
font.loadFromFile("DejaVuSans.ttf");
sf::Text text("Hello", font, 17);
font.getGlyph('g', 130, false); // A character that does not occur in the text
for (const auto c : text.getString())
font.getGlyph(c, 130, false);
text.setCharacterSize(130);
sf::Text anotherText("Hello", font, 17); // Same string
anotherText.setCharacterSize(130);
while (window.isOpen())
{
sf::Event event;
while (window.pollEvent(event))
{
if (event.type == sf::Event::Closed)
window.close();
}
window.clear();
glEnable(GL_SCISSOR_TEST);
GLint m_scissor[4] = {};
glGetIntegerv(GL_SCISSOR_BOX, m_scissor);
glScissor(0, 150, 400, 450);
// Clear again with different color just to show clipping area
window.clear(sf::Color::Blue);
window.draw(anotherText);
glScissor(m_scissor[0], m_scissor[1], m_scissor[2], m_scissor[3]);
window.display();
}
return EXIT_SUCCESS;
}
Instead of showing "Hello", it shows only the top part of some letters (the "L"s are ccompletely gone). I've attached a screenshot showing the issue.
I traced back at which SFML version this problem was introduced and I found that it only started since
6b71456. SFML versions before this commit show the text correctly.
It looks like glScissor has an effect on the internal font rendering, calling glDisable(GL_SCISSOR_TEST) at the start of Font::loadGlyph and calling glEnable(GL_SCISSOR_TEST) at the end of the function seems to fix the issue.