I am attempting to add hotkeys for changing window resolution as well as toggling full screen.
I am using something similar to the working solution suggested in this thread:
http://en.sfml-dev.org/forums/index.php?topic=2580.msg16913#msg16913Here is the setup function:
void setUpWindow(int newWindowWidth, int newWindowHeight, int newZoom, bool fullScreen) {
sf::VideoMode videoMode(newZoom * newWindowWidth, newZoom * newWindowHeight, 16);
renderWindow.Close();
if (fullScreen) {
renderWindow.Create(videoMode, "Dungeon Crawler 2012/08/14", sf::Style::Fullscreen);
}
else {
renderWindow.Create(videoMode, "Dungeon Crawler 2012/08/14");
}
// The game is all drawn to a single sf::Image which is then rendered to a single sf::Sprite
// Set up for this follows
sf::Image newImage(windowWidth, windowHeight, sf::Color(0, 0, 0));
screenImage = newImage;
screenImage.SetSmooth(false);
// set up an indexed image too (note that this isn't scaled up with the zoom, it's at native resolution)
IndexedImage newIndexedScreen(windowWidth, windowHeight);
indexedScreen = newIndexedScreen;
sf::Sprite newSprite;
screenSprite = newSprite;
screenSprite.SetImage(screenImage);
screenSprite.SetX(0.0f);
screenSprite.SetY(0.0f);
screenSprite.Scale(newZoom, newZoom);
}
This function works the first time it is called on program launch. However, there is a problem if I press one of my new hotkeys to change resolution. The function is called and the resolution is switched correctly. The sprite ("screenSprite" above) is visible and scaled correctly, but it becomes white. I wonder if there is something wrong with the way I am initializing things upon switching resolution.
I am using Windows 7, C++, and SFML 1.6.