Making an options menu I realized .setVerticalSyncEnabled() resets when .create() is called.
I think this may be a bug, because for example setFramerateLimit doesnt reset at all
Below I provide small examples to show what I mean.
this is the code to show setFramerateLimit doesn't reset (to "unlimited" FPS) when create() is called
#include <SFML/Graphics.hpp>
#include <sstream>
using namespace sf;
using namespace std;
int main()
{
RenderWindow app(VideoMode(800, 600, 32), "SFML Test");
app.setFramerateLimit(60);
app.create(VideoMode(800, 600, 32), "SFML Test");
Clock myClock;
float fps = 1 / myClock.restart().asSeconds();
stringstream ssFPS;
ssFPS << "fps: " << fps;
Text myText(ssFPS.str());
while (app.isOpen()){
Event evento;
while (app.pollEvent(evento)){
if (evento.type == Event::Closed){
app.close();
}
}
fps = 1 / myClock.restart().asSeconds();
stringstream ssFPS;
ssFPS << "fps: " << fps;
Text myText(ssFPS.str());
app.clear();
app.draw(myText);
app.display();
}
return 0;
}
This is the code to show that setVerticalSyncEnabled does reset to false if create() is called
#include <SFML/Graphics.hpp>
#include <sstream>
using namespace sf;
using namespace std;
int main()
{
RenderWindow app(VideoMode(800, 600, 32), "SFML Test");
app.setVerticalSyncEnabled(true);
app.create(VideoMode(800, 600, 32), "SFML Test");
Clock myClock;
float fps = 1 / myClock.restart().asSeconds();
stringstream ssFPS;
ssFPS << "fps: " << fps;
Text myText(ssFPS.str());
while (app.isOpen()){
Event evento;
while (app.pollEvent(evento)){
if (evento.type == Event::Closed){
app.close();
}
}
fps = 1 / myClock.restart().asSeconds();
stringstream ssFPS;
ssFPS << "fps: " << fps;
Text myText(ssFPS.str());
app.clear();
app.draw(myText);
app.display();
}
return 0;
}
a simple fix is to set setVerticalSyncEnabled to true, every time you call .create(), like this:
//code here
app.create(VideoMode(800, 600, 32), "SFML Test");
app.setVerticalSyncEnabled(true);
//rest of the code