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

Author Topic: Storing a list of resolutions as an array?  (Read 5294 times)

0 Members and 1 Guest are viewing this topic.

Flash619

  • Full Member
  • ***
  • Posts: 142
    • View Profile
Storing a list of resolutions as an array?
« on: November 14, 2012, 11:42:32 pm »
Hey everyone. :)

I in my program am needing to have a reference list of resolutions. *actually several lists for wide screen/full screen* But I'm trying to find the best method of storing such a list and was hoping that I could find some help on this subject. I thought maybe if I made a sf::Vector2u array and then stored the values within it. But am unsure on how proper that would be.

So its not really a question regarding broken code as much as it is me just asking for general input on the subject of storing a list of resolutions. It would also be nice if I had the ability to get a resolution by a number "like an array", say for instance. MyResolutionList[5].x

As Always, I'm looking forward to your input. :)

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 10801
    • View Profile
    • development blog
    • Email
Re: Storing a list of resolutions as an array?
« Reply #1 on: November 15, 2012, 12:07:25 am »
You can simply use a std::vector<sf::VideoMode>. If you don't know what a std::vector is then you left out one of the most important part in your literature about learning C++. ;)
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

Flash619

  • Full Member
  • ***
  • Posts: 142
    • View Profile
Re: Storing a list of resolutions as an array?
« Reply #2 on: November 15, 2012, 12:20:33 am »
You can simply use a std::vector<sf::VideoMode>. If you don't know what a std::vector is then you left out one of the most important part in your literature about learning C++. ;)

I somehow always do that. XD

Thanks a ton though! sf::VideoMode would work, any specific reason you chose sf::VideoMode over sf::Vector2u?

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 10801
    • View Profile
    • development blog
    • Email
Re: Storing a list of resolutions as an array?
« Reply #3 on: November 15, 2012, 12:29:20 am »
Thanks a ton though! sf::VideoMode would work, any specific reason you chose sf::VideoMode over sf::Vector2u?
Well sf::VideoMode is what you'll have to apply to your window, once you'd change the resolution, thus you'd could use it directly instead of copying the values of the sf::Vector2u first into a sf::VideoMode. On top of that you can also directly check if the resolution is actually a valid one for the current PC/monitor (if(vec[2].isValid())).
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

Flash619

  • Full Member
  • ***
  • Posts: 142
    • View Profile
Re: Storing a list of resolutions as an array?
« Reply #4 on: November 15, 2012, 01:47:11 am »
Well sf::VideoMode is what you'll have to apply to your window, once you'd change the resolution, thus you'd could use it directly instead of copying the values of the sf::Vector2u first into a sf::VideoMode. On top of that you can also directly check if the resolution is actually a valid one for the current PC/monitor (if(vec[2].isValid())).

Oh wow that actually makes a bunch of sense! Thanks a lot! :D

That isValid could come in VERY handy. I was wondering about that. XD But now I know there is a easy way to check, so thanks for showing me that. :)

Flash619

  • Full Member
  • ***
  • Posts: 142
    • View Profile
Re: Storing a list of resolutions as an array?
« Reply #5 on: November 15, 2012, 02:24:09 am »
What would be a good input for bits per pixel? Or should I just ignore that completely?

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 10801
    • View Profile
    • development blog
    • Email
AW: Storing a list of resolutions as an array?
« Reply #6 on: November 15, 2012, 08:22:53 am »
You can leave it as is, since it will automatically choose 32 which is common value.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

FRex

  • Hero Member
  • *****
  • Posts: 1845
  • Back to C++ gamedev with SFML in May 2023
    • View Profile
    • Email
Re: Storing a list of resolutions as an array?
« Reply #7 on: November 15, 2012, 11:44:52 am »
If you only want to get list of fullscreen modes you can use sf::VideoMode::getFullscreenModes() to get a vector filled with them.
Back to C++ gamedev with SFML in May 2023

Flash619

  • Full Member
  • ***
  • Posts: 142
    • View Profile
Re: Storing a list of resolutions as an array?
« Reply #8 on: November 15, 2012, 03:28:33 pm »
If you only want to get list of fullscreen modes you can use sf::VideoMode::getFullscreenModes() to get a vector filled with them.

Would that include resolutions as well? o.O *probably a dumb question*

Is there a similar function for wide screen modes? *I don't have VS open to check atm* Just checked and I didn't see one. Oh well, I'm just going to make a huge list of resolutions for now so that only the resolutions compatible with the sizes of the sprites are available *after all I have a manual override if I need a specific resolution* Then I'll just sort it all out later.
« Last Edit: November 15, 2012, 03:31:53 pm by Flash619 »

Flash619

  • Full Member
  • ***
  • Posts: 142
    • View Profile
Re: Storing a list of resolutions as an array?
« Reply #9 on: November 15, 2012, 04:31:39 pm »
Just wanted to say I have everything working flawlessly.

Thank you for your help. :)

Flash619

  • Full Member
  • ***
  • Posts: 142
    • View Profile
Re: Storing a list of resolutions as an array?
« Reply #10 on: November 15, 2012, 04:54:14 pm »
Hate to talk again and have to re post...... but.

isValid() is telling me that all of my video modes in my vector are invalid...

void EngineWindow::PrimeResolutionList()
{
        //Store initial resolutions.
        sf::VideoMode SVGA;
        SVGA.width=800;
        SVGA.height=600;
        SVGA.bitsPerPixel=4;
       
        sf::VideoMode XGAP1;
        XGAP1.width=1152;
        XGAP1.height=864;
        XGAP1.bitsPerPixel=16;
       
    sf::VideoMode XGAP2;
        XGAP2.width=1152;
        XGAP2.height=900;
        XGAP2.bitsPerPixel=16;
       
    sf::VideoMode HD;
        HD.width=1360;
        HD.height=768;
        HD.bitsPerPixel=24;

        sf::VideoMode HD2;
        HD2.width=1366;
        HD2.height=768;
        HD2.bitsPerPixel=24;
       
    sf::VideoMode WXGA;
        WXGA.width=1280;
        WXGA.height=800;
        WXGA.bitsPerPixel=24;

        sf::VideoMode HDP;
        HDP.width=1600;
        HDP.height=900;
        HDP.bitsPerPixel=24;

        sf::VideoMode SXGA;
        SXGA.width=1280;
        SXGA.height=1024;
        SXGA.bitsPerPixel=24;

        sf::VideoMode SXGAP;
        WXGA.width=1400;
        WXGA.height=1050;
    WXGA.bitsPerPixel=24;

        sf::VideoMode WSXGA;
        WSXGA.width=1440;
        WSXGA.height=900;
        WSXGA.bitsPerPixel=24;

        sf::VideoMode UXGA;
        WXGA.width=1600;
        WXGA.height=1200;
        WXGA.bitsPerPixel=24;

        sf::VideoMode WSXGAP;
        WXGA.width=1680;
        WXGA.height=1050;
        WXGA.bitsPerPixel=24;

        sf::VideoMode FULLHD;
        FULLHD.width=1920;
        FULLHD.height=1080;
        FULLHD.bitsPerPixel=24;

        sf::VideoMode WUXGA;
        WXGA.width=1920;
        WXGA.height=1200;
        WXGA.bitsPerPixel=24;

        //Add to the vector.
        reslist.push_back(SVGA);
        reslist.push_back(XGAP1);
        reslist.push_back(XGAP2);
        reslist.push_back(HD);
        reslist.push_back(HD2);
        reslist.push_back(WXGA);
        reslist.push_back(HDP);
        reslist.push_back(SXGA);
        reslist.push_back(SXGAP);
        reslist.push_back(WSXGA);
        reslist.push_back(UXGA);
        reslist.push_back(WSXGAP);
        reslist.push_back(FULLHD);
        reslist.push_back(WUXGA);

        //Iterate through the vector removing incompatable resolutions.
        std::vector<sf::VideoMode>::iterator it;
        for(it=reslist.begin(); it != reslist.end(); it++)
        {
                if(!(*it).isValid())
                {
                        it = reslist.erase(it);
                }
        }
}
 

Any ideas? o.O
Just a side note, I added in the bpp because otherwise if I try to use a VideoMode without a bpp defined, it claims its incompatible. *that is if it actually makes it past that final loop*

I mean. My current resolution is 1920 x 1080, so I don't see why its calling FULLHD invalid... Or a lot of the other ones for that matter.
« Last Edit: November 15, 2012, 04:59:59 pm by Flash619 »

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Re: Storing a list of resolutions as an array?
« Reply #11 on: November 15, 2012, 05:09:39 pm »
bpp should be 32 (what are you trying to do with other bpps??), or omitted since it's the default.
Laurent Gomila - SFML developer

Flash619

  • Full Member
  • ***
  • Posts: 142
    • View Profile
Re: Storing a list of resolutions as an array?
« Reply #12 on: November 15, 2012, 05:17:29 pm »
bpp should be 32 (what are you trying to do with other bpps??), or omitted since it's the default.

Oh, I was just copying them from a video chart I had found on Wikipedia. ^^;; I'll set them all to 32.

But say, if I make a quickie video mode like....
sf::VideoMode MyMode;
MyMode.Width=800;
MyMode.Height=600;

create(MyMode,"MyWindow",sf::Style::Fullscreen);
 

Will create an error since the bpp was not defined. However
sf::VideoMode MyMode;
MyMode.Width=800;
MyMode.Height=600;
MyMode.BitsPerPixel=32;

create(MyMode,"MyWindow",sf::Style::Fullscreen);
 

Will work perfectly. So thats why I have the bpp for each video mode. :)

Still unsure as to why they are all invalid...

Oh well, I'll just use
reslist = sf::VideoMode::getFullscreenModes();
 

Instead of making my own list, after all, its likely to save me time and be more efficient. ^^;
« Last Edit: November 15, 2012, 05:33:05 pm by Flash619 »

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Re: Storing a list of resolutions as an array?
« Reply #13 on: November 15, 2012, 07:10:28 pm »
Yes, sorry. Bpp is 32 only if you use the constructor that takes the width and height. By the way, your code would be a lot shorter if you used this constructor.
Laurent Gomila - SFML developer

cire

  • Full Member
  • ***
  • Posts: 138
    • View Profile
Re: Storing a list of resolutions as an array?
« Reply #14 on: November 15, 2012, 08:18:36 pm »

isValid() is telling me that all of my video modes in my vector are invalid...

        //Iterate through the vector removing incompatable resolutions.
        std::vector<sf::VideoMode>::iterator it;
        for(it=reslist.begin(); it != reslist.end(); it++)
        {
                if(!(*it).isValid())
                {
                        it = reslist.erase(it);
                }
        }
 

If all of your video modes were invalid, this loop would only be capable of removing half of them.  An element is skipped for every one removed, with the exception of the last element if it happens to be removed -- undefined behavior is invoked in that case.


 

anything