3
\$\begingroup\$

I created an empty iOS project and then added a custom GLView class which is then added to AppDelegate. I have following questions:

1) How do I enable hi-res retina mode on iPhone 4? Currently I am using the following code to check for device. The following code is from the AppDelegate where it first allocates GLView and then sets contentScale.

CGRect screenBounds = [[UIScreen mainScreen] bounds];
self.window = [[[UIWindow alloc] initWithFrame:screenBounds] autorelease];
// Override point for customization after application launch.
_view = [[GLView alloc] initWithFrame:screenBounds];
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
    NSLog(@"iPad detected");
}
else {
    if ([[UIScreen mainScreen] respondsToSelector:@selector(scale)] && [[UIScreen mainScreen] scale] == 2) {
        NSLog(@"iPhone4 detected");
        _view.contentScaleFactor = [[UIScreen mainScreen] scale];
    }
    else {
        NSLog(@"iPhone detected");
    }
}

self.window.backgroundColor = [UIColor whiteColor];
//self.window.rootViewController = [[[UIViewController alloc] initWithNibName:nil bundle:nil] autorelease];
[self.window addSubview:_view];

But even after setting content factor it is drawing pretty poor quality polygons with jagged edges as shown in the image below:

http://farm8.staticflickr.com/7358/8725549609_e2ed1e0e2a_b.jpg

Is there any way to set the resolution to 960x640 instead of the default 480x320 ?

Please note that I can not use "[email protected]" because I am generating images at runtime in the render buffer.

2) Second problem I am having is this warning message:

"Application windows are expected to have a root view controller at the end of application launch"

Thank you for your time.

Edit: Problem solved. Set contentScale before allocating render buffer memory, i.e: inside GLView, not AppDelegate.

\$\endgroup\$
2
  • \$\begingroup\$ How are you setting up your GL renderbuffer and projection matrix? Specifically, does e.g. glGetRenderbufferParameterivOES(GL_RENDERBUFFER_OES, GL_RENDERBUFFER_WIDTH_OES, &backingWidth); get you a backingWidth at the higher resolution? \$\endgroup\$
    – leander
    Commented May 10, 2013 at 20:05
  • \$\begingroup\$ @leander : Well I had to set eaglLayer.contentScale in GLView instead of AppDelegate. That solved the problem. Thanks! \$\endgroup\$
    – fakhir
    Commented May 11, 2013 at 11:21

2 Answers 2

1
\$\begingroup\$

The warning you see is because you didn't add a view controller to your window. If your AppDelegate does the work of loading up the view, a view controller isn't necessary, however Apple recommends using them. It's not a critical warning.

I believe you need to set the content scale on both the backing EAGL layer and the view itself. UIView has the layer property, which you can cast to CAEAGLLayer. So after you set the content scale of your view, do something like this:

CAEAGLLayer *eaglLayer = (CAEAGLLayer *)_view.layer;
eaglLayer.contentsScale = 2.0f;
\$\endgroup\$
3
  • \$\begingroup\$ I added the lines of code as you mentioned, no difference in the output at all! Please download complete xcode project from this link: Xcode Project \$\endgroup\$
    – fakhir
    Commented May 10, 2013 at 23:18
  • \$\begingroup\$ "The file you're looking for has been deleted or moved." \$\endgroup\$
    – jrsa
    Commented May 13, 2013 at 16:25
  • \$\begingroup\$ also, if the answer you provided worked, you should click the check mark so others will know that it's been answered. \$\endgroup\$
    – jrsa
    Commented May 13, 2013 at 20:24
1
\$\begingroup\$

Set contentScale before allocating render buffer memory, i.e: inside GLView, not AppDelegate. I deleted the following code from AppDelegate and placed it into GLView:

    if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
        NSLog(@"iPad detected");
    }
    else {
        if ([[UIScreen mainScreen] respondsToSelector:@selector(scale)] && [[UIScreen mainScreen] scale] == 2) {
            NSLog(@"iPhone4 detected");
            eaglLayer.contentsScale = 2.0f;
        }
        else {
            NSLog(@"iPhone detected");
        }
    }

What happened before was that the GLView was being initialised just before setting new scale factor with AppDelegate.

If Apple is ok with the warning and will not reject the app due to this:

"Application windows are expected to have a root view controller at the end of application launch"

Then problem solved. Thanks a lot !

\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .