Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Changing screen resolutions  (Read 14027 times)

0 Members and 3 Guests are viewing this topic.

Raptor88

  • Full Member
  • ***
  • Posts: 111
    • View Profile
    • Email
Changing screen resolutions
« on: June 22, 2012, 12:26:24 am »
Just trying different things to get familiar with SFML.  I'm trying to change screen resolutions but the original screen resolution keeps overriding the new screen resolution.   Here's my code:
#include <SFML/Graphics.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::Style::Resize | sf::Style::Close );
                                        }
                                        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;
}

When I press the F12 key, I see the 640x480 window for a split second and then the 800x600 window returns.  When I press F11, the screen blacks out and then I see the console window and stuff get large but the fullscreen never happens and the 800x600 window returns.

After a lot of Googling and searching the SFML forum, I "think" my problem may have to do with the first sf::RenderWindow statement setting a constructor and then that constructor overriding any subsequent attempt to re-size the window.

Could you tell me how to re-size the SFML window?

Running SFML 2.0 on VC++ 2010 in dynamic debug mode.

Raptor
« Last Edit: June 22, 2012, 12:29:39 am by Raptor88 »

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11032
    • View Profile
    • development blog
    • Email
Re: Changing screen resolutions
« Reply #1 on: June 22, 2012, 12:31:02 am »
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.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

Raptor88

  • Full Member
  • ***
  • Posts: 111
    • View Profile
    • Email
Re: Changing screen resolutions
« Reply #2 on: June 22, 2012, 01:37:45 am »
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
« Last Edit: June 22, 2012, 01:46:01 am by Raptor88 »

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11032
    • View Profile
    • development blog
    • Email
Re: Changing screen resolutions
« Reply #3 on: June 22, 2012, 01:45:07 am »
Been searching for a webpage like that for SFML 2.0 for a long time and couldn't find it.
Yeah it's directly on the website front page, i.e. Documetation... ;)

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");
;D

I guess you go better back to a C++ book, so you'll understand that changing the name of a variable, doesn't influence the functionality and doesn't in no way call the function create(...).
You need to have some basis on C++ before you can work with SFML. ;)

Also you don't need to include Window.hpp since that already gets included with Graphics.hpp. But again it shows that you have actually no much knowledge on what you're doing (no offense!). ;)

#include <SFML/Graphics.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) {
                                                Window.create(sf::VideoMode(800, 600, 32), "Fullscreen", sf::Style::Fullscreen);
                                        } else if (Event.key.code == sf::Keyboard::F12) {
                                                Window.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;
}
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

Raptor88

  • Full Member
  • ***
  • Posts: 111
    • View Profile
    • Email
Re: Changing screen resolutions
« Reply #4 on: June 22, 2012, 02:00:32 am »
Yeah it's directly on the website front page, i.e. Documetation... ;)

Oh, now I see the "tabs" on the documentation page.  I was just viewing the "Main Page" before.

Quote
I guess you go better back to a C++ book, so you'll understand that changing the name of a variable, doesn't influence the functionality and doesn't in no way call the function create(...).
You need to have some basis on C++ before you can work with SFML. ;)

Also you don't need to include Window.hpp since that already gets included with Graphics.hpp. But again it shows that you have actually no much knowledge on what you're doing (no offense!). ;)
...sample code not shown to save bandwidth...

Thanks for that sample code.  It works just fine.  You're totally right on all counts.  I have so much to learn about C++ after coming from C many years ago.

Thanks again!
Raptor