Search code examples
androidandroid-layoutopengl-esglsurfaceview

GlSurface view with XML layout


I see some questions could be duplicate but i need to ask this because i have other concern about my other code related to the layout that i didn't find in other question.

i have my activity bind with surface view

public void onCreate(Bundle savedInstanceState ) {
    super.onCreate(savedInstanceState);

    requestWindowFeature(Window.FEATURE_NO_TITLE);
    getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
    WindowManager.LayoutParams.FLAG_FULLSCREEN);

    glView = new GLSurfaceView(this);
    glView.setRenderer(this);       
    layout = new RelativeLayout(this);
    layout.addView(glView);
    setContentView(layout);
    glGraphics = new GLGraphics(glView);
    fileIO = new AndroidFileIO(getAssets());
    audio = new AndroidAudio(this);
    input = new AndroidInput(this, glView, 1,1);
    PowerManager powerManager = (PowerManager) getSystemService(Context.POWER_SERVICE);
    wakeLock = powerManager.newWakeLock(PowerManager.FULL_WAKE_LOCK, "GLGame");

}

this class actually i took from Mario Zechner's Book, so the OnDrawFrame will be responsible for the looping of update and present state which i like it very much and don't want to recreate it, so i want to use it. the only problem is the book only show how to use the canvas, all the game images will be drawn in the canvas which i don't want to use. i want to use XML layout. set all my images, buttons , etc from there..

I try to setContentView my layout but it will make the onDrawFrame() Stopped , so i can't get my update and present screen code running.

the latest, i tried :

(somewhere when i want to open match screen)

    myView = getLayoutInflater().inflate(R.layout.match, layout, false);    
    RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,ViewGroup.LayoutParams.MATCH_PARENT);
    params.leftMargin=0;
    params.topMargin=0;
    layout.addView(myView, params); 

the onDrawFrame is good, still running but now my layout only displayed 1/4 from top screen, 3/4 below all black. what caused that ?

How to achieve what i want here, the point is i want glview is still there but only to keep the code (onDrawFrame) Running ,while i want to display full XML layout.. and oh, i also tried to glView.setVisibility(View.GONE) , i got my layout displayed but unfortunately, the onDrawFrame code not running..

Edit: tried this recently. but still got 3/4 black screen...
(on Create)

    glView = new GLSurfaceView(this);
    glView.setRenderer(this);           
    layout = new RelativeLayout(this);
    fL = new FrameLayout(this);
    fL.addView(glView);
    layout.addView(fL);
    setContentView(layout);

(somewhere when i want to open match screen)

    myView = getLayoutInflater().inflate(R.layout.match, layout, false);
    layout.addView(myView); 

UPDATED: After tracing and searching for hours, now i know the black screen is caused by cleared screen. now the problem narrowed to the "how to make my match view on top of the glsurfaceview?"


Solution

  • depends on your code, but some have it worked with this code :

    glView.setZOrderOnTop(true);
    glView.setEGLConfigChooser(8, 8, 8, 8, 16, 0);
    glView.getHolder().setFormat(PixelFormat.RGBA_8888);
    

    try it and see if you can see your layout on top of the glview now.