I want to add to my game the functionality to change window stuff, and in this example I will refer to resolution. I did it some months / years ago, but now I'm failing. Below is some code to understand what I'm doing. Comments before each block exaplains where the calls happen
// Beginning of main()
scene::window = new sf::RenderWindow(sf::VideoMode(1600, 900), "Test");
scene::view = new sf::View(scene::window->getView());
scene::view->setSize(sf::Vector2f(scene::size.x, scene::size.y)); // Pixel-art game, so I want bigger units (size.x < 1600)
// In a network thread
void setPos(float x) {
player->sprite->setPosition(x, scene::band * 1.5f);
scene::view->setCenter(x, 0);
scene::window->setView(*scene::view); // All of these makes the camera follow the local player; also is the first one who sets a custom sf::View on the window
}
// After handling window events, clearing the screen, drawing SFML related stuff, but before drawing (ImGUI is a lib that handles button clicks at the same time with drawing, and I draw ImGui stuff after all my sprites); happens on a click
scene::window->create(sf::VideoMode(900, 900), "Test");
The usage of network *thread* doesn't seem to have negative impact, since before pressing everything works right. What happens: after the last block is ran, the window is recreated with the right resolution, but everything is black. I tried resetting the view:
scene::window->create(sf::VideoMode(900, 900), "Test");
scene::view = new sf::View(scene::window->getView());
scene::view->setSize(sf::Vector2f(scene::size.x, scene::size.y));
scene::window->setView(*scene::view); // I assure that at (0, 0) is stuff drawn
I tried recreatting a sprite with its texture:
scene::window->create(sf::VideoMode(900, 900), "Test");
scene::view = new sf::View(scene::window->getView());
scene::view->setSize(sf::Vector2f(scene::size.x, scene::size.y));
scene::window->setView(*scene::view);
// The block is copied from the initial generation, only the final instruction is changed from push_back() to modifying the original one, so I can assure there's no problems with loading it
auto bgTex = new sf::Texture;
bgTex->loadFromFile("texs/bg.png");
auto bg = new sf::Sprite(*bgTex);
bg->setPosition(sf::Vector2f(-scene::size.x / 2.f, -scene::size.y / 2.f));
scene::metal[0] = bg; // The background is supposed to take the whole screen on (1600, 900)
The same result. If it helps, ImGui actually still works like nothing happened, it's just on top of a black screen. Everything is up to date, running on VS2019, SFML_STATIC. I have another SFML instance in the system background since the server uses its network capabilities (no window)