Is it possible to make the background of an OpenGL ES layer transparent so you can see what is behind the OpenGL ES content?
是否可以使OpenGL ES层的背景透明,以便您可以看到OpenGL ES内容背后的内容?
1 个解决方案
#1
11
You have to do two things:
你必须做两件事:
- 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].
- 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].
初始化CAEAGLLayer时,将opaque属性设置为NO(或FALSE)。您可能还需要确保drawableProperties使用支持透明度的颜色格式(kEAGLColorFormatRGBA8可以,但kEAGLColorFormatRGB565不支持)。 eaglLayer.opaque = NO; eaglLayer.drawableProperties = [NSDictionary dictionaryWithObjectsAndKeys:[NSNumber numberWithBool:NO],kEAGLDrawablePropertyRetainedBacking,kEAGLColorFormatRGBA8,kEAGLDrawablePropertyColorFormat,nil];如果您正在使用XCode的OpenGL项目模板,那么这将在[EAGLView的initWithCoder]中。
以透明颜色和alpha绘制背景。 glClearColor(0.0f,0.0f,0.0f,0.0f);如果您正在使用XCode的OpenGL项目模板,那么这将是“渲染”方法:[ES1Renderer渲染]和[ES2Renderer渲染]。
#1
11
You have to do two things:
你必须做两件事:
- 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].
- 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].
初始化CAEAGLLayer时,将opaque属性设置为NO(或FALSE)。您可能还需要确保drawableProperties使用支持透明度的颜色格式(kEAGLColorFormatRGBA8可以,但kEAGLColorFormatRGB565不支持)。 eaglLayer.opaque = NO; eaglLayer.drawableProperties = [NSDictionary dictionaryWithObjectsAndKeys:[NSNumber numberWithBool:NO],kEAGLDrawablePropertyRetainedBacking,kEAGLColorFormatRGBA8,kEAGLDrawablePropertyColorFormat,nil];如果您正在使用XCode的OpenGL项目模板,那么这将在[EAGLView的initWithCoder]中。
以透明颜色和alpha绘制背景。 glClearColor(0.0f,0.0f,0.0f,0.0f);如果您正在使用XCode的OpenGL项目模板,那么这将是“渲染”方法:[ES1Renderer渲染]和[ES2Renderer渲染]。