Android GLSurfaceView with drawable background

10,332

Solution 1

GLSurfaceView cannot really have a background. The way a surface view works is by cutting a hole through your Activity's window and showing another surface behind. Setting setZOrderOnTop(true) moves the surface above the Activity's window.

Solution 2

false! You can do it. Just an example to show how it works.

glRenderer  = new OpenGLRenderer(context);
view = new GLSurfaceView(context);
view.setEGLConfigChooser(8, 8, 8, 8, 16, 0);
view.setRenderer(glRenderer);
view.getHolder().setFormat(PixelFormat.RGBA_8888);
view.getHolder().setFormat(PixelFormat.TRANSLUCENT);
view.setRenderMode(GLSurfaceView.RENDERMODE_CONTINUOUSLY);

Then use framelayout to put a view under glsurfaceview!

Solution 3

Try setZOrderMediaOverlay(true); which should put the gl layer above the background but below the window.

Solution 4

Well, since GLSurfaceView is just another view, why not use a FrameLayout to place the GLSurfaceView on top of the ImageView (or whatever you're using to display the drawable.)

Share:
10,332
Jlam
Author by

Jlam

iOS engineer, system architect, ex Apple-er, did a bunch of startups. An engineer and an artist. Passionately curious all day, everyday.

Updated on June 04, 2022

Comments

  • Jlam
    Jlam almost 2 years

    I have a GLSurfaceView with a drawable as background, however only the background is visible when rendered without surfaceView.setZOrderOnTop(true)

    I need to avoid using setZOrderOnTop(true) because there are static TextView's being used on top of the GLSurfaceView.

    Any suggestions for getting this to work?

  • Jlam
    Jlam over 13 years
    Tired it but it wasn't working because of the following conditions: 1. The gl layer has a constant background image. 2. there are additional elements on top of the gl layer such as buttons etc. It wasn't possible to set the static image as a background on the gl layer because the actual 3d content would not render unless I setZOrderOnTop(true) on the gl layer. But if I do that then the additional elements would end up under the gl layer.
  • Jlam
    Jlam over 13 years
    Thank you that was very helpful! Is there a way that you could recommend for achieving what I needed: static background image -> 3d content -> additional views buttons on top or is the only way to just render the static background as texture on a polygon?
  • Jlam
    Jlam over 13 years
    I ended up just rendering the background on a polygon behind everything else.. thanks for the tip!
  • Aleks N.
    Aleks N. over 12 years
    Thanks. It made my GLSurfaceView descendant transparent. But actually REDERMODE_CONTINUOUSLY is the default value and for me adding the last line crashes the app.
  • Justin Buser
    Justin Buser about 12 years
    That's because you have to setRenderMode before view.setRenderer
  • mayank_droid
    mayank_droid over 10 years
    what to put in FrameLayout to keep the other views above GLsurfaceView?