设置openGL动画的背景drawable

时间:2012-12-04 11:22:31

标签: android-layout opengl-es

我希望从我的drawable资源文件夹中设置一个静态图像作为我的OpenGL动画的背景。当动画位于GLSurfaceView时,我尝试将GLSurfaceView的背景设置为可绘制资源,但这不起作用。

<android.opengl.GLSurfaceView
                android:id="@+id/graphics_glsurfaceview1"
                android:layout_width="fill_parent"
                android:layout_height="500dp"
                android:background="@drawable/background" />

我想如何为我的OpenGL动画设置背景图像。我的onSurfaceCreated课程有onDrawFrameonSurfaceChangedGLSurfaceView方法,所以可能在某处?

1 个答案:

答案 0 :(得分:1)

这不会奏效。你需要这样做:

  1. GLSurfaceView
  2. 下放置另一个需要背景的视图
  3. 在渲染器中使用透明的清晰颜色。
  4. 这样你就会看到你的背景。

    您可以在Android API演示中查看此示例,请查看TranslucentGLSurfaceViewActivity。要查看它,请启动API演示应用程序并选择 Graphics-&gt; OpenGL ES-&gt; Translucent GLSurfaceView

    但是,我强烈建议不要以这种方式绘制背景,但使用OpenGL意味着 - 加载纹理并绘制它。