Updated to SDK4, CADisplayLink layer now sized wrong on iPad
I updated to SDK4, and now when I run my universal app on the iPad, all the OpenGL rendering happens in an iPhone sized window in the corner of the iPad.
I re-downloaded the GLES2Sample app that I modeled my code after, and it has the exact same behavior when run in the ipad simulator.
the init method for the gl view from the sample starts like this:
if you look at eaglLayer.bounds.size at this point, it seems to be 480x320 at all times. before i updated to SDK4, it was 480x320 when i run the app on the iPhone and 1024x768 when I run the app on the iPad.
Anyone have any idea how I get the "self.layer" resized properly?
I re-downloaded the GLES2Sample app that I modeled my code after, and it has the exact same behavior when run in the ipad simulator.
the init method for the gl view from the sample starts like this:
Code:
- (id) initWithCoder:(NSCoder*)coder
{
if ((self = [super initWithCoder:coder]))
{
// Get the layer
CAEAGLLayer *eaglLayer = (CAEAGLLayer *)self.layer;if you look at eaglLayer.bounds.size at this point, it seems to be 480x320 at all times. before i updated to SDK4, it was 480x320 when i run the app on the iPhone and 1024x768 when I run the app on the iPad.
Anyone have any idea how I get the "self.layer" resized properly?
As often happens, as soon as I had asked the question I knew the answer. It turns out that the automagically generated "MainWindow-iPad.xib" which is used by the sample app, and my cousin of the sample app, have the size of the EAGLView set to 480x320. Opening up I.B. and setting the size of the EAGLView to be the size of an iPad fixed the sample app, and my app as well.
Curious about why or how it ever worked without this.
[ EDITED LATER ]
Actually, that ended up NOT working in all cases of launching my app (sometimes I mess with the view hierarchy before starting the animation on the glview). For some reason I don't understand, no matter what size the view is in the NIB, it can get resized and/or repositioned oddly. Im heading in to work this morning planning to do something very like what MercuryBen says below.
Curious about why or how it ever worked without this.
[ EDITED LATER ]
Actually, that ended up NOT working in all cases of launching my app (sometimes I mess with the view hierarchy before starting the animation on the glview). For some reason I don't understand, no matter what size the view is in the NIB, it can get resized and/or repositioned oddly. Im heading in to work this morning planning to do something very like what MercuryBen says below.
I had the same problem today. I ended up having to reset the dimensions manually. I put this in applicationDidFinishLaunching:
Then you have to make sure the frame buffer is resized as well, so put this at the beginning of your EAGLView createFrameBuffer method.
I don't know if you really need to set both the frame and bounds, but figured it couldn't hurt. These changes seemed to fix the problem for me.
-Ben
Code:
#if (__IPHONE_OS_VERSION_MAX_ALLOWED >= 30200)
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
{
[self.window setFrame:CGRectMake(0, 0, 768, 1024)];
[self.window setBounds:CGRectMake(0, 0, 768, 1024)];
}
#endifThen you have to make sure the frame buffer is resized as well, so put this at the beginning of your EAGLView createFrameBuffer method.
Code:
#if (__IPHONE_OS_VERSION_MAX_ALLOWED >= 30200)
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
{
[self setFrame:CGRectMake(0, 0, 768, 1024)];
[self setBounds:CGRectMake(0, 0, 768, 1024)];
[self.layer setFrame:CGRectMake(0, 0, 768, 1024)];
[self.layer setBounds:CGRectMake(0, 0, 768, 1024)];
}
#endifI don't know if you really need to set both the frame and bounds, but figured it couldn't hurt. These changes seemed to fix the problem for me.
-Ben
Although I am hounded by the idea that somehow if I made my nib files "right" I wouldn't be having this problem, I have given up on that, and, like ben, just resize the gl view just before I setRootView: the view controller (which I select at run time depending on which device is being used).
Code:
CGRect fullScreen = [UIScreen mainScreen].bounds;
glView.bounds = fullScreen;
glView.frame = fullScreen;
[myViewController setRootView: glView];
This seems to work for me. My view expands to fit whatever it is put in.
THANK YOU FOR THIS POST!!!
Adding the code fixed my display issues. I am converting my app from iPhone to iPad, followed the Apple docs, resizing and editing nibs, all yielding no results, Apple needs to add this info to their tutorial, as many game developers could care less about nibs,objective-c etc as they only use it as a means to end to get their game on the platform. Dealing with these issues all day is a test of my insanity.
ok i need to vent, please bare with me lol. Let me start from the beginning, on leopard, xcode 3.1, successful iphone app done and happy, hm lets do an ipad version, search google and apple for tutorials on how to do this, come up with garbage, only tutorial which looks good is apples, first step click the "upgrade current target for ipad" menu option. hm it doesn't exist, i must need the new sdk, ok so lets go download it, 2GB downloaded and 40 minutes later. "you fool, you need SNOW leopard to install this SDK". apple.com/buymorestuff hm no download version of snow leopard exists, off to best buy, all of out single user licenses! but they have 25 copies of the family pack, oh well $20 more no big deal right. installing snow leopard, 1 hour later, install all OS updates, 30 minutes later, install 4.0 SDK, 20 minutes later, ok now im ready to start the ipad version lol! i hate dealing with compiler and os issues, it seems like such a waste of time. OMG and i forgot about the provisioning and code signing problems lol, another 2 hours wasted.
Adding the code fixed my display issues. I am converting my app from iPhone to iPad, followed the Apple docs, resizing and editing nibs, all yielding no results, Apple needs to add this info to their tutorial, as many game developers could care less about nibs,objective-c etc as they only use it as a means to end to get their game on the platform. Dealing with these issues all day is a test of my insanity.
ok i need to vent, please bare with me lol. Let me start from the beginning, on leopard, xcode 3.1, successful iphone app done and happy, hm lets do an ipad version, search google and apple for tutorials on how to do this, come up with garbage, only tutorial which looks good is apples, first step click the "upgrade current target for ipad" menu option. hm it doesn't exist, i must need the new sdk, ok so lets go download it, 2GB downloaded and 40 minutes later. "you fool, you need SNOW leopard to install this SDK". apple.com/buymorestuff hm no download version of snow leopard exists, off to best buy, all of out single user licenses! but they have 25 copies of the family pack, oh well $20 more no big deal right. installing snow leopard, 1 hour later, install all OS updates, 30 minutes later, install 4.0 SDK, 20 minutes later, ok now im ready to start the ipad version lol! i hate dealing with compiler and os issues, it seems like such a waste of time. OMG and i forgot about the provisioning and code signing problems lol, another 2 hours wasted.
@Rasterman: you don't say exactly which post 'did it' for you. I'm presuming the code example rather than the .nib file fix?
Yup - the changeover is a major, massive pain. I lost about a week to it due to various errors - mostly caused by XCode 3.2.3's 'install-over-old-xcode' procedure being fundamentally flawed. After nuking the entire developer directory using the console (read the instructions in the XCode directory) I reinstalled to find things working... and slow.
Snow Leopard: slow.
iOS: slow.
My app, which was running at a lovely 50fps now runs considerably slower, pushing my optimisation stage to the fore. Not good. Hopefully now Shark will now work again, having stopped working for some black magic reason on 3.2.2.
Yup - the changeover is a major, massive pain. I lost about a week to it due to various errors - mostly caused by XCode 3.2.3's 'install-over-old-xcode' procedure being fundamentally flawed. After nuking the entire developer directory using the console (read the instructions in the XCode directory) I reinstalled to find things working... and slow.
Snow Leopard: slow.
iOS: slow.
My app, which was running at a lovely 50fps now runs considerably slower, pushing my optimisation stage to the fore. Not good. Hopefully now Shark will now work again, having stopped working for some black magic reason on 3.2.2.
Possibly Related Threads...
| Thread: | Author | Replies: | Views: | Last Post | |
| NSTimer fine, CADisplayLink having some issues | monteboyd | 5 | 7,509 |
Aug 31, 2010 07:05 PM Last Post: Skorche |
|
| OpenAL, i am doing it wrong or is it broken on iPad simulator? | AdrianM | 3 | 3,367 |
Apr 23, 2010 11:18 AM Last Post: Rasterman |
|
| Simulator Graphical Glitch *Updated* | Amorpheous | 10 | 4,194 |
Nov 16, 2009 07:43 PM Last Post: AnotherJake |
|
| Wrong x,y coordinates with Texture2D class | Minishlink | 2 | 2,789 |
Feb 12, 2009 11:37 AM Last Post: Minishlink |
|
| What's wrong with Core Graphics and UI? | Lazarwulf | 1 | 2,865 |
Nov 12, 2008 12:33 PM Last Post: longjumper |
|

