GLSurfaceView - 如何使半透明的背景 [英] GLSurfaceView - how to make translucent background

查看:686
本文介绍了GLSurfaceView - 如何使半透明的背景的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试使用GLSurfaceView来呈现,并通过我定格的文档:

  getHolder()和setFormat(PixelFormat.TRANSLUCENT)。
 

在我使用GLSurfaceView.Renderer,其中提请在onDrawFrame:

  GLES20.glClearColor(0,0,1,.5f);
GLES20.glClear(GLES20.GL_DEPTH_BUFFER_BIT | GLES20.GL_COLOR_BUFFER_BIT);
 

然而,在GLSurfaceView的GL渲染不透亮,而且是完全蓝色。如果我忽略glClear通话,那么它的全黑。

我如何GL渲染有透明的背景,所以它混合了拉背后看法?

修改:这是我的GLSurfaceView:

 类GLView扩展GLSurfaceView {
   MyRendererř;
   公共GLView(上下文CTX){
      超(CTX);
      setEGLContextClientVersion(2);

      。getHolder()和setFormat(PixelFormat.TRANSLUCENT);

      setEGLConfigChooser(8,​​8,8,8,16,0);
      R =新MyRenderer(的getContext());
      setRenderer(r)的;
   }
}
 

解决方案

确定,经过一番研究,我可以回答这个问题我自己。

我终于来到了被透明使用SurfaceView.setZOrderOnTop(真)绘制。但后来我失去了可能性,把我的GLSurfaceView之上的其他意见。

我结束了两个可能的结果:

上头

在左侧低于所有其他视图,它不能与透明度绘制标准GL表面,因为GL表面绘制之前的应用程序的窗口面,且GLSurfaceView只是拳洞在它的位置,以便GL表面看透。

在右侧是绘制setZOrderOnTop(真)透明GL表面,因而其表面被绘制在应用程序窗口顶部。现在,它是透明的,但会绘制在置于其上的视图层次其他视图顶部。

因此​​看来,应用程序有一个窗口面为其视图层次,并SurfaceView有自己的表面为GL,其可以是应用程序窗口的顶部或下面。不幸的是,透明的GL视图不能正确地使用内部在它上面的其他视图视图层次有序。

I try to render using GLSurfaceView, and by docs I set format:

getHolder().setFormat(PixelFormat.TRANSLUCENT);

The I use GLSurfaceView.Renderer, which draws in onDrawFrame:

GLES20.glClearColor(0, 0, 1, .5f);
GLES20.glClear(GLES20.GL_DEPTH_BUFFER_BIT | GLES20.GL_COLOR_BUFFER_BIT);

However, the GL rendering in GLSurfaceView is not translucent, and is fully blue. If I omit glClear call, then it's fully black.

How do I make GL rendering to have transparent background, so that it is blended with views drawn behind it?

EDIT: here is my GLSurfaceView:

class GLView extends GLSurfaceView{
   MyRenderer r;
   public GLView(Context ctx){
      super(ctx);
      setEGLContextClientVersion(2);

      getHolder().setFormat(PixelFormat.TRANSLUCENT);

      setEGLConfigChooser(8, 8, 8, 8, 16, 0);
      r = new MyRenderer(getContext());
      setRenderer(r);
   }
}

解决方案

OK, after some research I can answer this myself.

I finally made it to be drawn with transparency using SurfaceView.setZOrderOnTop(true). But then I lost possibility to place other views on top of my GLSurfaceView.

I ended with two possible results:

On left is standard GL surface below all other views, which can't be drawn with transparency, because GL surface is drawn before application's window surface, and GLSurfaceView just punches hole in its location so that GL surface is seen through.

On right is transparent GL surface drawn with setZOrderOnTop(true), thus its surface is drawn on top of application window. Now it's transparent, but is drawn on top of other views placed on it in view hierarchy.

So it seems that application has one window with surface for its view hierarchy, and SurfaceView has own surface for GL, which may be on top or below of app window. Unfortunately, transparent GL view can't be ordered correctly inside view hierarchy with other views on top of it.

这篇关于GLSurfaceView - 如何使半透明的背景的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆