开发者

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?


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>


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.


Some good reading: http://android-developers.blogspot.com/2010/09/one-screen-turn-deserves-another.html


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜