Everytime you press F11 or F12 you create a completly new window. But since that's the only operation within that if-scope the window get immediatly destroyed again.
sf::RenderWindow provides the function create(...) to change the size of the existing window.
Look in the documentation.
Hey eXpl0it3r,
Thanks for that link! Been searching for a webpage like that for SFML 2.0 for a long time and couldn't find it.
I added the #include <SFML/Window.hpp> and changed:
sf::RenderWindow Window(sf::VideoMode(640, 480, 32), "640 x 480 Screen");
to
sf::RenderWindow create(sf::VideoMode(640, 480, 32), "640 x 480 Screen");
but I still get the momentary 640x480 display and the 800x600 display returns again. Could you tell me what I need to do next?
My revised code is:
#include <SFML/Graphics.hpp>
#include <SFML/Window.hpp>
int main()
{
sf::RenderWindow Window(sf::VideoMode(800, 600, 32), "SFML Sample Application");
sf::Text text("Hello SFML");
while (Window.isOpen())
{
sf::Event Event;
while(Window.pollEvent(Event))
{
switch (Event.type)
{
case sf::Event::Closed:
Window.close();
break;
case sf::Event::KeyPressed:
if (Event.key.code == sf::Keyboard::Escape) {
Window.close();
} else if (Event.key.code == sf::Keyboard::F11) {
sf::RenderWindow Window(sf::VideoMode(800, 600, 32), "Fullscreen", sf::Style::Fullscreen);
} else if (Event.key.code == sf::Keyboard::F12) {
//sf::RenderWindow Window(sf::VideoMode(640, 480, 32), "640 x 480 Screen");
sf::RenderWindow create(sf::VideoMode(640, 480, 32), "640 x 480 Screen");
}
break;
default:
break;
}
}
Window.clear(sf::Color(0, 255, 255) ); // Sets screen color to safflower blue.
Window.draw(text); // Displays text on line 12.
Window.display();
}
return 0;
}
Also tried:
sf::Window create(sf::VideoMode(640, 480, 32), "640 x 480 Screen");
in place of the
sf::RenderWindow Window(sf::VideoMode(640, 480, 32), "640 x 480 Screen");
but same momentary 640x480 window.
Am a rank beginner so please excuse my ignorance,
Raptor