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#msg16913
Here 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.
I read in another thread that 1.6 is more stable than 2.0, but I'd be willing to switch if that's no longer the case.
windowWidth and windowHeight are globals and their values are the same, but I might as well change that so as to make the example more self contained. Here:
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/04/03", sf::Style::Fullscreen);
}
else {
renderWindow.Create(videoMode, "Dungeon Crawler 2012/04/16");
}
sf::Image newImage(newWindowWidth, newWindowHeight, 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(newWindowWidth, newWindowHeight);
indexedScreen = newIndexedScreen;
// Set up an sf::Sprite for displaying things on the screen. This will be our draw canvas.
sf::Sprite newSprite;
screenSprite = newSprite;
screenSprite.SetImage(screenImage);
screenSprite.SetX(0.0f);
screenSprite.SetY(0.0f);
screenSprite.Scale(newZoom, newZoom);
}