Tuesday 4 January 2011

iPhone 4 and the retarded, I mean retina display

So, I have a shiny new iPhone 4 with all it's hi-res lovelyness. I also have an iPad with it's equally lovely hi-res screen. Imagine my surprise when I asked the SDK for the screen res of the iPhone 4 and was very disappointed to be told it's the same as the iPhone 3G. But hang on a second I hear you say, it is most definitely a hi-res screen but the OS says it's not. A little leg work later and I have an answer, and it's one of the biggest bodges to date.

iPhone 4 and the retina display cannot be accessed directly. Instead you treat it as an iPhone 3 and the OS draws text and windows etc. in hi-res. The only issue here is if you are displaying images (or graphics via OpenGL) in which case you generate a hi-res imagine and add @2x to the end of the filename. When you request your normal file (picture.png) for example, if you are on an iPhone 4 the system will instead load picture@2x.png (if it exists) instead. This makes sense so that everything is backward compatible. However there is no alternative. You cannot tell it you are writing an iPhone 4 compatible app and get the correct dimensions etc, you just have to live with the strange x2 issues. This means when drawing things to the screen with pixel positions you should specify half pixels to address the in-between pixels. Of course if you're doing an OpenGL game you're most likely already using floats for your positions and therefore everything will just automatically be hi-res for you.

OK, now I've ranted about it this does make some sense. But I still thought there'd be a direct mode. There is for iPad so why not for iPhone 4? Maybe it'll come in time with an OS release.

Oh, and Merry Christmas and a happy new year etc.