method of getting valid fullscreen resolutions on OS X in Objective-C or C++?
Asked Answered
A

2

3

I'm making a game and I'd like to get a list of valid fullscreen resolutions for the launcher. I can't find any way of doing this for Mac OS X;

Like in the system preferences Displays pane.

enter image description here

Is it possible?

Agminate answered 21/9, 2013 at 7:48 Comment(0)
F
5

If you mean get the Display screen resolutions.

This may be what you are after.

NSScreen* thescreen;
id theScreens = [NSScreen screens];

for (thescreen in theScreens) {
  NSLog(@"%@x%@",  [NSNumber numberWithFloat:[thescreen frame].size.width],   [NSNumber numberWithFloat:[thescreen frame].size.height]);
}

This example will give you the set resolutions of all displays

Have a look at apples NSScreen

If this is not quite what you are after can you expand your question.

Cheers


  • UPDATE. in regard to comment from OP on wanting all possible display resolutions.

This maybe what you are after and you will have to play with it to see if it is indeed returning the correct info. I was getting multiple results hence the filter. But if you play with it you should be able to thin it down.

The test project was using ARC and it forced the __bridges.. But again I am sure you will have time to code it all better.

My reference was Quartz Display Services Reference

NSArray* theref  =  (__bridge NSArray *)(CGDisplayCopyAllDisplayModes ( CGMainDisplayID(), nil ));

NSMutableArray * rezes = [[NSMutableArray  alloc]init];

for (id aMode  in theref) {
  CGDisplayModeRef  thisMode = (__bridge CGDisplayModeRef)(aMode);
  size_t theWidth = CGDisplayModeGetWidth( thisMode );
  size_t theHeight = CGDisplayModeGetHeight( thisMode );
  NSString *theRez = [NSString stringWithFormat:@"%zux%zu",theWidth,theHeight];

  if (![rezes containsObject:theRez]) {
    [rezes addObject:theRez];
  }
}

NSLog(@" display deatails = %@", rezes);

--> display deatails = ( 2560x1440, 1280x720, 640x480, 800x600, 1024x768, 1280x1024, 1344x756, 1600x900, 1680x1050, 1920x1080, 1600x1200, 1920x1200 )

Footgear answered 21/9, 2013 at 19:28 Comment(6)
I meant a list of any valid screen resolutions supported at the OS level - like, when I go into the system preferences, I can see that my display supports several fullscreen resolutions. I want to get thoseAgminate
yes, this updated version is exactly what I needed. thank you so much!! :)Agminate
@Mark how to sort the screen resolutions ?Stump
@Stump what do you mean?. if you mean by list order then there will likely be a sort command in Objective -C or what ever language you are using..Footgear
@Footgear ok and have tried to pass kCGDisplayShowDuplicateLowResolutionModes instead of nil in CGDisplayCopyAllDisplayModes ? It said to get all possible resolutions but i am getting same as if i pass nil.Stump
@Stump looks like you are already talking to the person who put an up an example using this 'reserved for future use' option, so best you keep with them on that.. https://mcmap.net/q/1329049/-how-to-get-all-possible-screen-resolutions-in-cocoaFootgear
C
1

In C++ http://specialmeaning.blogspot.com/2016/07/yes-apple-i-did-it.html

#include <iostream>
#include <CoreGraphics/CoreGraphics.h>

int main(int argc, const char * argv[]) {
    // insert code here...
    auto mainDisplayId = CGMainDisplayID();

    std::cout << "Current resolution was "
    << CGDisplayPixelsWide(mainDisplayId) << 'x'
    << CGDisplayPixelsHigh(mainDisplayId) << std::endl
    << "Supported resolution modes:";

    auto modes = CGDisplayCopyAllDisplayModes(mainDisplayId, nullptr);
    auto count = CFArrayGetCount(modes);
    CGDisplayModeRef mode;
    for(auto c=count;c--;){
        mode = (CGDisplayModeRef)CFArrayGetValueAtIndex(modes, c);
        auto w = CGDisplayModeGetWidth(mode);
        auto h = CGDisplayModeGetHeight(mode);
        std::cout << std::endl << w << 'x' << h;
    }
    CGDisplaySetDisplayMode(mainDisplayId, mode, nullptr);
    std::cout << " is the selected top one." << std::endl;
    std::cin.get();
    return 0;

}
Carcinogen answered 5/6, 2017 at 0:25 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.