Android GLSurfaceView transparent background without setZOrderonTop

匿名 (未验证) 提交于 2019-12-03 01:08:02

问题:

Sorry for my English.

My work is based on https://github.com/harism/android_page_curl/

After many hours of research, I have found a few solutions, but not for all the issues what I have in my application. I've some trouble with a GLSurfaceView. I've got a background with a relativeLayout, a GLSurfaceView, and an overlay on top.

When I init my view :

setEGLConfigChooser(8,8,8,8,16,0); setRenderer(renderer); getHolder().setFormat(PixelFormat.TRANSLUCENT); setRenderMode(GLSurfaceView.RENDERMODE_WHEN_DIRTY); setZOrderMediaOverlay(true); 

In my renderer:

public void onSurfaceCreated(GL10 gl, EGLConfig config) {     gl.glClearColor(0f, 0f, 0f, 0f);     gl.glShadeModel(GL10.GL_SMOOTH);     gl.glHint(GL10.GL_PERSPECTIVE_CORRECTION_HINT, GL10.GL_NICEST);     gl.glHint(GL10.GL_LINE_SMOOTH_HINT, GL10.GL_NICEST);     gl.glHint(GL10.GL_POLYGON_SMOOTH_HINT, GL10.GL_NICEST);     gl.glEnable(GL10.GL_LINE_SMOOTH);     gl.glDisable(GL10.GL_DEPTH_TEST);     gl.glDisable(GL10.GL_CULL_FACE); }  public synchronized void onDrawFrame(GL10 gl) {     gl.glClearColor(0f,0f,0f,0f);     gl.glClear(GL10.GL_COLOR_BUFFER_BIT);     gl.glLoadIdentity(); } 

After multiple research, I am currently blocked with this result:
with setZOrderOnTop, i've got background, but the overlay is under the view.
with setZOrderMediaOverlay, i've got the overlay, but the background is black.

Someone can help me?

回答1:

This worked for me:

final GLSurfaceView glView = (GLSurfaceView) findViewById(R.id.glView);  glView.setZOrderOnTop(true); glView.setEGLConfigChooser(8, 8, 8, 8, 16, 0); glView.getHolder().setFormat(PixelFormat.RGBA_8888); glView.setRenderer(new MyRenderer()); glView.setRenderMode(GLSurfaceView.RENDERMODE_WHEN_DIRTY); 

Found here: http://andrewhague.wordpress.com/2011/05/24/how-to-set-a-transparent-glsurfaceview/



回答2:

I would like to accomplish the same thing with a view on top of a GLSurfaceView and I have not found a solution without limitations. First, glView.setZOrderOnTop(true) gives the correct transparent background but the view is alway on top no matter what the sequence of ordering views. Second, without ZOrderOnTop the view hierarchy is maintained but the GLSurface background is black or the color that is set with glClearColor(red, green, blue, alpha) in the renderer. Unfortunately, the alpha argument has no effect when using this method unless

android:windowIsTranslucent="true" 

and the problem with this is that you may not want to punch a hole into the OS view. There should be a way to accomplish this easily for a more animated UI using openGL. I have searched this site and others without finding a solution.



回答3:

I'm working the same problem. I found that you have to make the calls for

setZOrderOnTop(true); getHolder().setFormat(PixelFormat.RGBA_8888); 

before the call to

setRenderer(...); 

Good luck!



标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!