Programmatically change resolution OS X

2020-06-06 20:26发布

问题:

My question is simple. I am developing a game and, as the title states, I want to be able to programmatically change the display resolution / refresh rate on OS X. I've been searching for this for hours and couldn't find anything. I already know how to create a full screen window.

I would also want to get the list of supported resolutions and refresh rates

回答1:

From Apple's OpenGL Programming Guide for Mac OS X: Drawing to the Full Screen:

Avoid changing the display resolution from that chosen by the user. If your application needs to render data at a lower resolution for performance reasons, you can explicitly create a back buffer at the desired resolution and allow OpenGL to scale those results to the display. See “Controlling the Back Buffer Size.”

That said, if you really want to do this, you can use Quartz Display Services. See "Changing Display Modes". You should really capture the display, as described elsewhere in that guide, before changing the display configuration or else other applications will have their windows moved and resized and your users will be annoyed. (For example, their desktop icons may get rearranged.)