android - 在 Android 上的 OpenGL 程序中调用 glViewport 是必要的吗?

标签 android opengl-es

在大多数 Android OpenGL 示例中,我看到人们在 onSurfaceChanged 中调用 glViewport。但是,我只是注意到,如果我将其注释掉,我的程序的行为仍然相同。所以有必要调用它吗?

最佳答案

当您的 gl View 尺寸被修改时,有必要在 onSurfaceChanged 处理程序中调用 glViewport。通常是在设备旋转并且 View 的宽度和高度交换时。

如果 width = height 或 View 不旋转,则不需要调用 glViewport

默认情况下,Activity 将在旋转后重新创建。为避免这种情况,您需要指定您的 Activity 是 handling rotation itself .您需要在 AndroidManifest.xml 中添加这些配置选项:

<activity android:name="Activity"
        android:configChanges="screenSize|orientation">

完成此操作后,您的 Activity 将保留您的 OpenGL 上下文。

关于android - 在 Android 上的 OpenGL 程序中调用 glViewport 是必要的吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15905181/

相关文章:

android - 我无法加载打开的天气 map 图标

android - "Please select Android SDK"- 如何导入项目文件?

android - 使用 OpenGL ES2.0 的纹理渲染质量下降

opengl-es - OpenGL ES 2.x : Bind both `GL_TEXTURE_2D` and `GL_TEXTURE_CUBE_MAP` in the same texture image unit?

android - Firebase Crashlytics 报告 InflateException : ResourceNotFoundException for a Trend TaintArt for 4x6

android-listview - 在底部显示总数的 ListView

android - 在自己的动画中尊重动画师的持续时间比例

android - 将当前时间传递给 OpenGL ES 2.0 着色器以进行纹理动画 : animation stops after certain time

objective-c - 将 NSMutableArray 复制到 float 组中以进行 GLES 渲染

java - 如何在AndEngine Rectangle类中实现glColorPointer