Reputation: 863
...frustration. I want my game to be run only in landscape mode. I have added the appropriate key/value to the Info.plist file that forces the device orientation to be correct at launch.
I'm now trying to rotate the OpenGL coordinate space to match that of the device. I'm trying to use the code I found here, but it's not working. My test case draws a square at the center, and with all of that code included, I see nothing drawn; if I comment out the 2nd part (only setting the GL_PROJECTION matrix mode), the coordinate system does appear to be correct. But I'd like it rotated as well. I'm a little puzzled on how to do this, as well as setting up the view nib correctly as well. Tips, please?
Also, in the future, I'm going to be swapping out the EAGLView with another UIView subclass; is doing this going to require anything different?
Thanks! randy
Upvotes: 2
Views: 1689
Reputation: 634
You have the plist set correctly. Now make sure ALL your view controllers have the following:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation
{
return (toInterfaceOrientation==UIInterfaceOrientationLandscapeRight) ? YES : NO;
}
A child view without it can muck things up.
Also if you have a UINavigationController or similar you NEED to subclass it and implement shouldAutorotateToInterfaceOrientation because its dead stupid on its own and will default to portrait and ruin things.
Then for viewdidload
- (void)viewDidLoad {
[super viewDidLoad];
CGRect rect = [[UIScreen mainScreen] bounds];
rect.size.height = 320;
rect.size.width = 480;
rect.origin.x = 0;
rect.origin.y = 0;
glView = [[EAGLView alloc] initWithFrame:rect pixelFormat:GL_RGB565_OES depthFormat:GL_DEPTH_COMPONENT16_OES preserveBackbuffer:NO];
[self.view addSubview: glView];
[glView addSubview: minimapView];
//etc...
}
Upvotes: 2