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

Author Topic: Getting supported resolutions.  (Read 3439 times)

0 Members and 1 Guest are viewing this topic.

Richy19

  • Full Member
  • ***
  • Posts: 190
    • View Profile
Getting supported resolutions.
« on: August 22, 2011, 06:19:53 pm »
I just wanted to know if SFML2 had any sort of way to get the supported resolutions?

I have done this in windows (to get the maximum supported resolution) by doing:

Code: [Select]
DEVMODE dmode;
dmode.dmSize = sizeof(DEVMODE);
dmode.dmDriverExtra = 0;

unsigned short maxWidthSupported = 0;
unsigned short maxHeightSupported = 0;

unsigned short imode = 0;

while(EnumDisplaySettings(NULL, imode, &dmode ) != 0)
{
if(dmode.dmPelsWidth > maxWidthSupported) maxWidthSupported = (unsigned short)dmode.dmPelsWidth;
if(dmode.dmPelsHeight > maxHeightSupported) maxHeightSupported = (unsigned short)dmode.dmPelsHeight;

imode++;
}

if(w > maxWidthSupported) w = maxWidthSupported;
if(h > maxHeightSupported) h = maxHeightSupported;

GlobalSettings::WindowWidth = w;
GlobalSettings::WindowHeight = h;


but Ideally I would like to have a cross platform solution.[/code]

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6286
  • Thor Developer
    • View Profile
    • Bromeon
Re: Getting supported resolutions.
« Reply #1 on: August 22, 2011, 06:45:44 pm »
Quote from: "Richy19"
I just wanted to know if SFML2 had any sort of way to get the supported resolutions?
Yes, take a look at the documentation of sf::VideoMode.
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

Richy19

  • Full Member
  • ***
  • Posts: 190
    • View Profile
Getting supported resolutions.
« Reply #2 on: August 22, 2011, 07:58:57 pm »
Ahh thanks, just been playing with it but Im having an issue.
Im using this code:

Code: [Select]
void GlobalSettings::setWidthHeight(unsigned short w, unsigned short h)
{
    sf::VideoMode desktopVM = sf::VideoMode::GetDesktopMode();


        sf::VideoMode vMode = sf::VideoMode(w,h,desktopVM.BitsPerPixel);
        if(vMode.IsValid())
        {
            GlobalSettings::WindowWidth = w;
            GlobalSettings::WindowHeight = h;
             return;
        }
       
        std::vector<sf::VideoMode> modes = sf::VideoMode::GetFullscreenModes();
        for (std::size_t i = 0; i < modes.size(); ++i)
        {
             sf::VideoMode mode = modes[i];

             if(desktopVM.BitsPerPixel == mode.BitsPerPixel)
             {
                if( (mode.Width/mode.Height) == (4/3) )
                {
                    w = mode.Width;
                    h = mode.Height;

                    vMode = sf::VideoMode(w,h,desktopVM.BitsPerPixel);
                        if(vMode.IsValid())
                        {
                            GlobalSettings::WindowWidth = w;
                            GlobalSettings::WindowHeight = h;
                            return;
                        }
                 }
             }
         }


}


Which should check if the given width/height are valid for the resolution and make sure that they are 4:3 aspect ratio, but it isnt working it just gives back the highest resolution (which it should do as im passing something like 1600x1200) but it isnt the highest 4:3.
Its giving back 1280x800.

I think its to do with the  if( (mode.Width/mode.Height) == (4/3) ) but I wasnt sure

omeg

  • Jr. Member
  • **
  • Posts: 55
    • View Profile
    • http://omeg.pl/
Getting supported resolutions.
« Reply #3 on: August 22, 2011, 08:01:44 pm »
if( (mode.Width/mode.Height) == (4/3) )

This is integer division. Cast the numbers to float/double (and remember that floating-point comparisons are not exact).

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6286
  • Thor Developer
    • View Profile
    • Bromeon
Getting supported resolutions.
« Reply #4 on: August 22, 2011, 08:22:09 pm »
Simply reshape the equation to get rid of both problems:
Code: [Select]
if (3 * mode.Width == 4 * mode.Height)
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

Richy19

  • Full Member
  • ***
  • Posts: 190
    • View Profile
Getting supported resolutions.
« Reply #5 on: August 22, 2011, 08:36:15 pm »
Much easier thanks :D