Is it possible to make an OpenGL ES layer transparent?

前端 未结 1 1490
青春惊慌失措
青春惊慌失措 2020-12-09 22:19

Is it possible to make the background of an OpenGL ES layer transparent so you can see what is behind the OpenGL ES content?

相关标签:
1条回答
  • 2020-12-09 23:08

    You have to do two things:

    1. When you initialize your CAEAGLLayer, set the opaque property to NO (or FALSE).

      You may also need to make sure your drawableProperties uses a color format that supports transparency (kEAGLColorFormatRGBA8 does, but kEAGLColorFormatRGB565 does not).

      eaglLayer.opaque = NO;

      eaglLayer.drawableProperties = [NSDictionary dictionaryWithObjectsAndKeys: [NSNumber numberWithBool:NO], kEAGLDrawablePropertyRetainedBacking, kEAGLColorFormatRGBA8, kEAGLDrawablePropertyColorFormat, nil];

      If you are using XCode's OpenGL project template, this will be in [EAGLView's initWithCoder].

    2. Draw the background in a transparent color and alpha.

      glClearColor(0.0f, 0.0f, 0.0f, 0.0f);

      If you are using XCode's OpenGL project template, this will be in the "render" methods: [ES1Renderer render] and [ES2Renderer render].
    0 讨论(0)
提交回复
热议问题