I recently made my app FunkyBooth with retina support using OF.http://itunes.apple.com/us/app/funkybooth/id424731057#
I had to hack into the guts of OF quite a bit. With the following method, your touch events and screen coordinates are all reporting the full size(e.g. 480x320 and 960x640). I created code with normalized coordinates from 0.0 to 1.0, and drew everything appropriately. For instance, draw(0.5, 0.5) would scale to 240, 160 on a regular display and 480, 320 on the retina.
Also, I use two sets of images and a draw function that was scale aware, loading the correct image. Using string values, I would just load the proper path into each, depending on the resolution. I tried to always use the high res version and just draw them smaller, but older phones don’t like to handle that many pixels.
First in EAGLView.mm:
touchScaleFactor=1;
if(retinaEnabled)
{
if ([[UIScreen mainScreen] respondsToSelector:@selector(scale)]) {
if ([[UIScreen mainScreen] scale] > 1)
{
[self setContentScaleFactor:[[UIScreen mainScreen] scale]];
touchScaleFactor=[[UIScreen mainScreen] scale];
}
}
}
Then in ofxiPhoneAppDelegate.mm:
int w = 320, h = 480;
float ver = [[[UIDevice currentDevice] systemVersion] floatValue];
// Can't detect screen res in pre 3.2 devices, but they are all 320x480 anyway.
if (ver >= 3.2) {
UIScreen* mainscr = [UIScreen mainScreen];
w = mainscr.currentMode.size.width;
h = mainscr.currentMode.size.height;
}
if (w == 640){
iPhoneGetOFWindow()->enableRetinaSupport();
NSLog(@"Retina Detected.");
}
And finally in ofAppiPhoneWindow.mm:
// return cached size, read if nessecary
ofPoint ofAppiPhoneWindow::getWindowSize() {
if(windowSize.x == NOT_INITIALIZED) {
CGSize s = [[[UIApplication sharedApplication] keyWindow] bounds].size;
windowSize.set(s.width, s.height, 0);
if(retinaEnabled)
if ([[UIScreen mainScreen] respondsToSelector:@selector(scale)])
windowSize*=[[UIScreen mainScreen] scale];
}
return windowSize;
}
// return cached size, read if nessecary
ofPoint ofAppiPhoneWindow::getScreenSize() {
if(screenSize.x == NOT_INITIALIZED) {
CGSize s = [[UIScreen mainScreen] bounds].size;
screenSize.set(s.width, s.height, 0);
}
return screenSize;
}
int ofAppiPhoneWindow::getWidth(){
if( orientation == OFXIPHONE_ORIENTATION_PORTRAIT || orientation == OFXIPHONE_ORIENTATION_UPSIDEDOWN ){
return (int)getWindowSize().x;
}
return (int)getWindowSize().y;
}
int ofAppiPhoneWindow::getHeight(){
if( orientation == OFXIPHONE_ORIENTATION_PORTRAIT || orientation == OFXIPHONE_ORIENTATION_UPSIDEDOWN ){
return (int)getWindowSize().y;
}
return (int)getWindowSize().x;
}
I think that’s the majority of the changes, but let me know if I missed anything. One of these days I really have to learn how to use git. Of course there is probably a better way to do this, but it worked for me.
Cheers,
a.stellato