Strokes
Strokes

Reputation: 217

Set background drawable of openGL animation

I'm looking to set a static image from my drawable resource folder as a background for my OpenGL animation. As the animation sits on a GLSurfaceView I tried setting the GLSurfaceView's background to the drawable resource but this doesn't work.

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

Any ideas how I would go about setting a background image for my OpenGL animation. I have onSurfaceCreated, onDrawFrame, onSurfaceChanged methods for my GLSurfaceView class so maybe somewhere in there?

Upvotes: 0

Views: 1071

Answers (1)

keaukraine
keaukraine

Reputation: 5364

This won't work. You will need to make it this way:

  1. Place another view with needed background beneath GLSurfaceView
  2. Use transparent clear color in rendeder.

This way you will see your background.

You can see example of this in Android API Demos, take a look at TranslucentGLSurfaceViewActivity. To see it, launch API Demos application and select Graphics->OpenGL ES->Translucent GLSurfaceView.

However, I will strongly suggest to draw background not this way but with OpenGL means - load texture and draw it.

Upvotes: 1

Related Questions