openframeworks / openframeworks/openFrameworks

ofGetOrientation() Can't get hardware orientation on startup

Open
#5,612 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

iOS prelim-analysis
Dominant language
C++
Stars
10.4k
Forks
2.6k
Avg merge
1d 21h
Merged PRs (30d)
9

Description

Hi, I'm trying to detect the device orientation when the app is launched.

But it seems like the app always changes its orientation to OF_ORIENTATION_DEFAULT on startup regardless of its current hardware orientation.

For example, if I start an app in a landscape mode, it always changes to a default portrait mode.

Here's my example code,

in main.mm

int main() {
    
    //  here are the most commonly used iOS window settings.
    //------------------------------------------------------
    ofiOSWindowSettings settings;
    settings.enableRetina = true; // enables retina resolution if the device supports it.
    settings.enableDepth = true; // enables depth buffer for 3d drawing.
    settings.enableAntiAliasing = true; // enables anti-aliasing which smooths out graphics on the screen.
    settings.numOfAntiAliasingSamples = 4; // number of samples used for anti-aliasing.
    settings.enableHardwareOrientation = true; // enables native view orientation.
    settings.enableHardwareOrientationAnimation = false; // enables native orientation changes to be animated.
    settings.glesVersion = OFXIOS_RENDERER_ES1; // type of renderer to use, ES1, ES2, etc.
    
    ofCreateWindow(settings);
    
	return ofRunApp(new ofApp);
}

in ofApp.mm

//--------------------------------------------------------------
void ofApp::setup(){	

    switch (ofGetOrientation()) {
            
        case OF_ORIENTATION_DEFAULT:
            cout << "OF_ORIENTATION_DEFAULT" << endl;
            break;
        case OF_ORIENTATION_180:
            cout << "OF_ORIENTATION_180" << endl;
            break;
        case OF_ORIENTATION_90_LEFT:
            cout << "OF_ORIENTATION_90_LEFT" << endl;
            break;
        case OF_ORIENTATION_90_RIGHT:
            cout << "OF_ORIENTATION_90_RIGHT" << endl;
            break;
        case OF_ORIENTATION_UNKNOWN:
            cout << "OF_ORIENTATION_UNKNOWN" << endl;
            break;
        default:
            break;
    }
}

And it always prints OF_ORIENTATION_DEFAULT regardless of the device orientation.
I think this is a bug since this worked properly on of_v0.9.0_ios version. ( I had to change some codes though as there were some bugs https://forum.openframeworks.cc/t/fixed-orientation-issues-on-ios8/20275)

If anyone has a solution to this, please let me know.
I tested this on both of_v0.9.8_ios and the latest nightly build.

Thanks!

forum post : https://forum.openframeworks.cc/t/ios-cant-get-hardware-orientation-on-startup/26817

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the report using the settings in main.mm and the ofApp::setup() call to ofGetOrientation() in ofApp.mm. Trace the iOS orientation initialization path and verify that startup reports the device's hardware orientation instead of OF_ORIENTATION_DEFAULT when hardware orientation is enabled; confirm the behavior on the versions mentioned.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp, ios
Domain
mobile-dev
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.