x


Different resolutions on iPhone 4 and 4S

Is there a way to have a different Unity resolutions on iPhone 4 and 4S? Given that the 4 isn't really powerful enough to run some of my game at retina resolution.

I think that I've read that it is not possible to change the resolution after the game initializes, so perhaps I need to modify the XCode project - any pointers or advice would be willingly received.

more ▼

asked Jun 21 '12 at 05:27 PM

whydoidoit gravatar image

whydoidoit
33.1k 12 23 100

(comments are locked)
10|3000 characters needed characters left

1 answer: sort voted first

You need to modify AppController.mm and check for an iPhone 4S in the CreateSurface code, changing the returned resolution if you discover that it is an iPhone4 or less:

bool CreateSurface(EAGLView *view, EAGLSurfaceDesc* surface)
{
    CAEAGLLayer* eaglLayer = (CAEAGLLayer*)surface->eaglLayer;
    assert(eaglLayer == [view layer]);

    CGSize newSize = [eaglLayer bounds].size;
    newSize.width  = roundf(newSize.width);
    newSize.height = roundf(newSize.height);

#ifdef __IPHONE_4_0
    int resolution = UnityGetTargetResolution();

    // Start modification //

    if([[machineName() substringWithRange:NSMakeRange(0, 6)] isEqualToString:@"iPhone"] && [[machineName() substringWithRange:NSMakeRange(6,1)] compare:@"4"] == NSOrderedAscending)
    {
        resolution = kTargetResolutionStandard;
    }

    //  End modification  //


    if (    (resolution == kTargetResolutionNative || resolution == kTargetResolutionHD)
         && [view respondsToSelector:@selector(setContentScaleFactor:)]
         && [[UIScreen mainScreen] respondsToSelector:@selector(scale)]
       )
    {
            CGFloat scaleFactor = [UIScreen mainScreen].scale;
            [view setContentScaleFactor:scaleFactor];
            newSize.width = roundf(newSize.width * scaleFactor);
            newSize.height = roundf(newSize.height * scaleFactor);
            UnitySetInputScaleFactor(scaleFactor);
    }
#endif

    surface->w = newSize.width;
    surface->h = newSize.height;

    UNITY_DBG_LOG ("CreateWindowSurface: FBO\n");
    CreateSurfaceGLES(surface);
    GLES_CHK( glBindRenderbufferOES(GL_RENDERBUFFER_OES, surface->renderbuffer) );

    QCARUnityPlayer::getInstance().QCARNotifyCreated((int)surface->w, (int)surface->h);
    return true;
}

Then add this code to the top of the file:

#import <sys/utsname.h>

NSString*
machineName()
{
    struct utsname systemInfo;
    uname(&systemInfo);

    return [NSString stringWithCString:systemInfo.machine
                              encoding:NSUTF8StringEncoding];
}
more ▼

answered Jun 22 '12 at 08:46 PM

whydoidoit gravatar image

whydoidoit
33.1k 12 23 100

Though I'd prefer a better way of detecting an iPhone 4s

Jun 22 '12 at 08:47 PM whydoidoit

QCARUnityPlayer::getInstance().QCARNotifyCreated((int)surface->w, (int)surface->h); return true;

<< this returns an error

Dec 20 '12 at 11:26 PM StoneFish

Please don't post comments or new questions as answers. This is a known fault with the latest stuff where I believe Vuforia has changed to using targetW and targetH.

Dec 20 '12 at 11:29 PM whydoidoit

Please note to anyone reading you SHOULD NOT take this function as is - please use the section marked //Start Modification up to //End Modification only - at any time in the future many other things in this function could change.

Obviously U4 solves this problem by having it's own setting.

Dec 20 '12 at 11:31 PM whydoidoit

I'm using 0.5 for most things to be honest. Looks fine to me :)

Feb 06 at 11:14 PM whydoidoit
(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x381
x3
x2

asked: Jun 21 '12 at 05:27 PM

Seen: 2994 times

Last Updated: Feb 06 at 11:14 PM