GLSurfaceView - how to make translucent background

后端 未结 5 1445
日久生厌
日久生厌 2021-01-04 19:08

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

getHolder().setFormat(PixelFormat.TRANSLUCENT);

The I use GLSurfaceView.Rend

5条回答
  •  心在旅途
    2021-01-04 20:02

    You need RGBA 8888 pixel format for translucency:

    private void init( boolean translucent, int depth, int stencil )
    {
        /* By default, GLSurfaceView() creates a RGB_565 opaque surface.
         * If we want a translucent one, we should change the surface's
         * format here, using PixelFormat.TRANSLUCENT for GL Surfaces
         * is interpreted as any 32-bit surface with alpha by SurfaceFlinger.
         */
        this.getHolder().setFormat( PixelFormat.RGB_565 );
        if ( translucent )
        {
            this.getHolder().setFormat( PixelFormat.TRANSLUCENT );
        }
    
        setEGLContextFactory( new ContextFactory() );
    
        /* We need to choose an EGLConfig that matches the format of
         * our surface exactly. This is going to be done in our
         * custom config chooser. See ConfigChooser class definition
         * below.
         */
        setEGLConfigChooser( translucent ?
                             new ConfigChooser( 8, 8, 8, 8, depth, stencil ) :
                             new ConfigChooser( 5, 6, 5, 0, depth, stencil ) );
    
        setRenderer( new Renderer() );
    }
    

提交回复
热议问题