Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix iOS orientation #1477

Closed
julapy opened this issue Aug 10, 2012 · 14 comments
Closed

fix iOS orientation #1477

julapy opened this issue Aug 10, 2012 · 14 comments

Comments

@julapy
Copy link
Member

julapy commented Aug 10, 2012

currently when setting orientation on ios,
the glView remains in portrait mode but everything drawn in the glView is flipped or rotated depending on the specified orientation.

a more elegant method would be to rotate and resize the glView directly to a orientation.
and as far as OF is concerned, its always in OF_ORIENTATION_DEFAULT mode but the glView is adjusted.
this way you never have to flip or rotate any coordinates.... which will cut out a lot of orientation bugs which currently exist.

@ghost ghost assigned julapy Aug 10, 2012
@roymacdonald
Copy link
Member

I just came across this issue.
I remember that I was fixed or at least I fixed it in the 0062 era.
I'll check what's going on.

@erinnovations
Copy link

I founded this bug at this moment. We develop a game and we use landscape orientations only. When the orientation change we flip the game's board and draw it in the good way but the native iOS things (volume and brightness change, popups, notifications) was upside down.

I used this workaround and the problem is solved. Maybe you can implement something like this:
http://code.compartmental.net/2012/01/13/auto-rotation-in-ios-with-openframeworks/

@julapy
Copy link
Member Author

julapy commented Aug 21, 2012

hey @erinnovations, thanks for posting your solution.
will definitely be taking it into consideration when implementing this feature.

@bilderbuchi
Copy link
Member

I'm pushing this back to 0073.

@erinnovations
Copy link

The given solution is not working good for iPad3's retina display. There is an unknown situation why glView not appearing in the right position.

My updated workaround (maybe helps you in the final solution):

    // ORIENTATION HACK

    // remove the glview from the UIWindow, which is where openFrameworks puts it
    [ofxiPhoneGetGLView() removeFromSuperview];

    // create a plain old UIView that is the same size as the app
    // just use OF sizes as our reference, everything should work out
    CGRect mainFrame = CGRectMake(0, 0, CurrentConfig::CC_GAME_WIDTH, CurrentConfig::CC_GAME_HEIGHT);
    mMainView = [[UIView alloc] initWithFrame:mainFrame];

    // grab the glView and rotate/position it so it looks correct
    UIView* glView = ofxiPhoneGetGLView();

    CGAffineTransform landscapeTransform = CGAffineTransformMakeRotation(M_PI_2);
    glView.transform = CGAffineTransformTranslate(landscapeTransform, -128, -128); //A transform hack. I don't understand why -128,-128, but this works.

    // glView goes on our main view to prevent wonky resizing
    [mMainView addSubview:glView];

    // root controller has main view as its view
    mRootViewController = [[LandscapeViewController alloc] init];
    mRootViewController.view = mMainView;

    // and finally we set the root view controller
    // which will make mMainView the window's primary view
    // all other views are then added as subviews of mMainView
    // NOT as subviews of the UIWindow or the EAGLView
    ofxiPhoneGetUIWindow().rootViewController = mRootViewController;

@julapy
Copy link
Member Author

julapy commented Sep 4, 2012

ive got glView orientation working correctly now...
the glView is being rotated and resized to match the new orientation.
this means there will be less flipping of the glView coordinates and hopefully less confusion and bugs later on.

to move forward with this change,
ofAppiPhoneWindow::setOrientation now becomes a bit redundant.
but it can not be deleted because ofAppiPhoneWindow::setOrientation and ofAppiPhoneWindow::getOrientation is used throughout the entire framework.

so im thinking a couple extra methods need to be created,
ofAppiPhoneWindow::setAppOrientation
ofAppiPhoneWindow::getAppOrientation
(open to naming suggestions)

and adding a message to ofAppiPhoneWindow::setOrientation to use the above methods instead.

also thinking of moving ofAppiPhoneWindow::rotateXY somewhere else as its no longer being used inside ofAppiPhoneWindow but its a really handy method for iOS and maybe if used by other platforms, it can be standardised in a common class. possibly also used for android...? where would be a good place for it to live?

@julapy
Copy link
Member Author

julapy commented Sep 5, 2012

had another think and decided against adding new orientation methods to ofAppiPhoneWindow... probably would confuse things.

instead, when now calling ofAppiPhoneWindow::setOrientation a message is displayed in the console to use ofxiPhoneSetOrientation instead.

ofxiPhoneSetOrientation and ofxiPhoneGetOrientation now call methods on ofxiPhoneViewController to make orientation changes.

think this approach will have minimal effect on legacy apps and its easy to make the adjustment to get orientation working again.

@cerupcat
Copy link
Contributor

We seem to be having an orientation issue here: http://forum.openframeworks.cc/index.php/topic,11484.msg50874.html#msg50874

I'm not sure if it's an iOS 6 issue. For our project we have it so the openGL should never rotate, but we should be able to have a iOS native GUI that can rotate to all orientations. This previously worked until the update.

@julapy
Copy link
Member Author

julapy commented Dec 13, 2012

hey @cerupcat, there have been changes in iOS6 that deal with orientation differently.
i have not investigated properly but i can tell you that in xcode - "Supported Interface Orientation" did not do much in the past but in iOS6 it seems to dictate the orientation for the entire app, ignoring all other orientations you set within your app. try changing "Supported Interface Orientation" and see if that does anything...

iOS orientation is still an outstanding issue in OF and when it gets resolved, it should also work on iOS6.

@cerupcat
Copy link
Contributor

Yeah, I noticed that setting the orientation in the plist will cause the whole thing to rotate to those orientations. Therefore, the only option seems to be setting it in code so that it can be controlled.

If you don't give an orientation, it'll rotate the whole window including the openGL view and it'll cut off the openGL view since it's not resized. So right now it seems the only supported orientations are portrait or landscape, but not both. I'll try to look into it a bit more, but may have to revert to a previous OF for now.

@chrisoshea
Copy link

.@cerupcat did you get this fixed on yours? can anyone confirm if this works?
http://forum.openframeworks.cc/index.php/topic,11484.msg50906.html#msg50906

Thanks

@roikr
Copy link
Contributor

roikr commented May 19, 2013

Hi,
I didn't find a simple way to recreate the EAGLView, so basically there is no way to create landscape opengl layer.
my solution which does not support rotations (only fixed orientation) is:

  1. modify addons/ofxiPhone/src/core/ofxiPhoneAppDelegate.mm:

-(void) applicationDidFinishLaunching:(UIApplication *)application {
...
if ([appDelegateClassName isEqualToString:@"ofxiPhoneAppDelegate"]) { // app delegate is not being extended.
CGRect frame = [[UIScreen mainScreen] bounds];

    switch (iPhoneGetOFWindow()->getOrientation()) {
        case OF_ORIENTATION_DEFAULT:
        case OF_ORIENTATION_180:

            break;
        case OF_ORIENTATION_90_RIGHT:
        case OF_ORIENTATION_90_LEFT:
            frame.size.width = [[UIScreen mainScreen] bounds].size.height;
            frame.size.height = [[UIScreen mainScreen] bounds].size.width;
            break;

        default:
            break;
    }
    self.glViewController = [[[ofxiPhoneViewController alloc] initWithFrame:frame
                                                                        app:(ofxiPhoneApp *)ofGetAppPtr()] autorelease];
    self.window.rootViewController = self.glViewController;
}

..

  1. setup orientation in main.mm
    iPhoneGetOFWindow()->setOrientation(OF_ORIENTATION_90_RIGHT);
    to force creation of EAGL view from with your desired orientation
  2. rollback to OF_ORIENTATION_PORTRAIT in testApp::setup()
    iPhoneSetOrientation(OFXIPHONE_ORIENTATION_PORTRAIT);
    to draw and get touch events in of standard orientation.

in this solution you don't have to rotateXY or transform touches.
but as I mentioned, you can't change orientations after setup.

Roee

@roymacdonald
Copy link
Member

this should be closed because of this #931

@bilderbuchi
Copy link
Member

Closed by #931 thanks roy!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

7 participants