SFML community forums
Help => Window => Topic started by: Richy19 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:
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]
-
I just wanted to know if SFML2 had any sort of way to get the supported resolutions?
Yes, take a look at the documentation (http://www.sfml-dev.org/documentation/2.0/classsf_1_1VideoMode.php) of sf::VideoMode.
-
Ahh thanks, just been playing with it but Im having an issue.
Im using this code:
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
-
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).
-
Simply reshape the equation to get rid of both problems:
if (3 * mode.Width == 4 * mode.Height)
-
Much easier thanks :D