This is hard to explain. Whenever my game goes fullscreen, whatever is being drawn by the main RenderWindow gets erased patches over it, in a pattern. The following drawing illustrates what would happen if my window was drawing a sprite with a black background and a red smile, if the window had a 64 bits per pixel depth VideoMode (so that the sprite could be centered in such a way) and was calling clear(sf::Color::White).
The patterns go up and down through the sprite, but in a low framerate, it appears to be rather appearing in random spots through it.
These patterns only show up when I call clear() for the RenderWindow every tick. If I don't, no patterns show up, but the game still runs "choppy". I suspect that my window is skipping one every two frames.
Everything runs perfectly when windowed.
I can show some code if the community would like, but I would rather first have some insight of what could be the possibilities. It's somewhat messy code. Can a missing .clear() call have such an effect? .display()? As in, does this have any relation to double-buffering? Has anyone even seen this before?
---
edit:
Apparently, this was the excerpt of code that was making everything go haywire:
{
static const float separation = 3.5f;
static const unsigned char white = 160;
sf::Text continueText("Continuar", lib::defaultFont(), lib::defaultFontSize());
// continueText.setColor(sf::Color::White);
// auto continueLocal = continueText.getLocalBounds(); /*1*/
// auto continueBounds = continueText.getGlobalBounds(); /*1*/ /*2*/
// continueText.setPosition(
// windowWidth / 2 - continueBounds.width / 2.f - continueLocal.left,
// windowHeight / 2 - continueBounds.height - continueLocal.top - separation);
sf::Text quitText("Sair", lib::defaultFont(), lib::defaultFontSize());
// quitText.setColor(sf::Color(white, white, white));
// auto quitLocal = quitText.getLocalBounds(); /*3*/
// auto quitBounds = quitText.getGlobalBounds(); /*3*/ /*2*/
// quitText.setPosition(
// windowWidth / 2 - quitBounds.width / 2.f - quitLocal.left,
// continueText.getPosition().y + continueLocal.height + separation);
sf::Text disclaimerText(L"O jogo está pausado", lib::defaultFont(), lib::defaultFontSize());
disclaimerText.move(5, 0);
m_pauseTex.create(windowWidth, windowHeight);
m_pauseTex.setSmooth(true);
m_pauseTex.clear(::pausedBlack);
// m_pauseTex.draw(disclaimerText);
// m_pauseTex.draw(continueText);
// m_pauseTex.draw(quitText);
m_pauseTex.display();
m_pauseScreen.setTexture(m_pauseTex.getTexture());
} // This block (and subsequent deaths of the Texts) isn't actually necessary, as the bug shows up even if the following 'while' is right below the m_pauseScreen.setTexture above.
Variables with the m_ prefix are indeed member variables. m_pauseTex is an sf::RenderTexture and m_pauseScreen is an sf::Sprite.
lib::defaultFont() returns a const sf::Font& reference to a font stored in static resources. lib::defaultFontSize() returns a simple int.
This m_pauseScreen is drawn every tick by something as simple as:
while (m_window.isOpen()) {
sf::Event event;
while (m_window.pollEvent(event));
m_window.clear();
m_window.draw(m_pauseScreen);
m_window.display();
}
The error shows up whenever I uncomment any of the line combinations with the numbers. For example, if I uncomment only the two lines with that /*1*/, the error would show up. If I uncommented only the two lines with the /*2*/ in the end, the error would show up as well. Same for /*3*/
In the end, it's all because of calls to sf::Text::getLocalBounds() and getGlobalBounds(). I haven't yet nailed what exactly causes the problem, and I don't think I'd even be able to. I knew sf::Text had specially buggy boundary management, but I didn't know it was extreme enough that it could interfere with completely unrelated instances; even commenting the m_renderTex.draw calls doesn't prevent the bug.
Can anyone reproduce the situation with only what I've provided? The window is created with .create(sf::VideoMode(640, 480, 64), "", sf::Style::Fullscreen);