Marcus Johansson
Marcus Johansson

Reputation: 2667

OpenGL when turning Android Phone

What is it called ( what term should i google) when flipping/tilting the phone, so that the view rotates when running android?

My (OpenGL) application crashes when I do this, are there some certain steps you should do when handling OpenGL when this occures?

Is there something else I might want to think about?

Upvotes: 5

Views: 2979

Answers (4)

forksandhope
forksandhope

Reputation: 501

if you don't set the AndroidManifest.xml 's attributes for activities that handle their own rotations, your activity will be restarted, the GL context will be recreated, and at least, any surfaces and buffers that you were using will be invalid.

in my gles 1.1 application, I have the following in my AndroidManifest.xml, which specifies that my application activity wants to live on through keyboard and orientation configuration changes, and that the application supports any orientation, but doesn't want it to change -because I don't want to deal with reloading textures or redoing the game layout (yet)

<application android:label="@string/app_name" 
             android:icon="@drawable/icon" 
             android:theme="@android:style/Theme.NoTitleBar.Fullscreen"
             android:debuggable="true">
    <activity android:name="MainActivity"
              android:configChanges="keyboard|keyboardHidden|orientation"
              android:screenOrientation="nosensor"
              android:label="@string/app_name">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
</application>

Upvotes: 5

csanta
csanta

Reputation: 512

You could try searching for "Screen rotation android" or "Screen rotation android OpenGL" since you're trying to do 3D. When the screen rotates the current surface gets destroyed and a new one gets created already accounting for the new screen dimensions.

I'd recommend looking into some sample code just to see the correct way to handle screen rotation, look for "ApiDemos.apk" in Android (it's open sourced by the way), specifically the ones who use GL", all of them handle screen rotation.

Upvotes: 0

Cheryl Simon
Cheryl Simon

Reputation: 46844

The problem is like the configuration change that occurs when the screen orientation change occurs. See Configuration Changes. You might want to tell Android that you will handle the orientation change yourself, via the configChanges attribute.

Upvotes: 3

Related Questions