Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
531 views
in Technique[技术] by (71.8m points)

iphone - Is it possible to make an OpenGL ES layer transparent?

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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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].

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...