Android手机转动时的OpenGL

发布于 2024-09-18 20:02:21 字数 162 浏览 10 评论 0原文

翻转/倾斜手机时它叫什么(我应该谷歌什么术语),以便在运行 Android 时旋转视图

当我执行此操作时,我的 (OpenGL) 应用程序崩溃了,当发生这种情况时,在处理 OpenGL 时是否应该执行一些特定步骤?

还有什么我可能想考虑的吗?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

素染倾城色 2024-09-25 20:02:21

如果您没有为处理自己的旋转的活动设置 AndroidManifest.xml 的属性,您的活动将重新启动,GL 上下文将被重新创建,并且至少,您使用的任何表面和缓冲区都将无效。

在我的gles 1.1应用程序中,我的AndroidManifest.xml中有以下内容,它指定我的应用程序活动希望通过键盘和方向配置更改继续存在,并且应用程序支持任何方向,但不希望它改变 -因为我不想处理重新加载纹理或重做游戏布局(还)

<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>

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>
爱给你人给你 2024-09-25 20:02:21

该问题就像屏幕方向发生变化时发生的配置更改一样。请参阅配置更改。您可能想告诉 Android 您将自己处理方向更改,通过 configChanges 属性。

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.

寒冷纷飞旳雪 2024-09-25 20:02:21

您可以尝试搜索“屏幕旋转 android”或“屏幕旋转 android OpenGL”,因为您正在尝试执行 3D。当屏幕旋转时,当前表面将被破坏,并根据新的屏幕尺寸创建一个新表面。

我建议查看一些示例代码,只是为了了解处理屏幕旋转的正确方法,在 Android 中查找“ApiDemos.apk”(顺便说一下,它是开源的),特别是那些使用 GL 的人,它们都处理屏幕旋转。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文