Retina Display
Now that the baby is a bit more independent, I’m finally getting a chance to do some iPhone programming. One of the first things I wanted to tackle was adding Retina Display support for the iPhone 4.
It turned out to be pretty straightforward (once I figured out where to do set the contentScale). First, you have to determine what device you’re running. I started by creating a type to store that information:
typedef enum {
DisplayTypeIPhone,
DisplayTypeIPhoneRetina,
DisplayTypeIPad,
} DisplayType;
DisplayType displayType;
Then I set it in applicationDidFinishLaunching like so:
displayType = DisplayTypeIPhone;
// check for iPad
float systemVersion = [[UIDevice currentDevice].systemVersion floatValue];
if (systemVersion >= 3.2)
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
displayType = DisplayTypeIPad;
// check for Retina Display
if (systemVersion >= 4.0)
if ([UIScreen mainScreen].scale == 2.0)
displayType = DisplayTypeIPhoneRetina;
The final piece of the puzzle was to set contentScaleFactor to 2 for my OpenGL view. The trick is that you have to do it after the context gets created and before the view gets setup. This took me all day to figure out. But hopefully someone else will see this and be spared some of that pain. In my case, I put it in initGLES:
if (displayType == DisplayTypeIPad) {
// eventually do resolution dependent stuff here
} else if (displayType == DisplayTypeIPhoneRetina) {
self.contentScaleFactor = 2.0;
} else {
}