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
410 views
in Technique[技术] by (71.8m points)

iphone - Displaying an EAGLView with transparent background on a UIImageView

I have an EAGLView displaying an OpenGL 3D model, and a UIImageView displaying an image.



What I want is to display EAGLView above that UIImageView with transparent background.

Is there any way to display this 3D model with transparent background, on top of the UIImageView.

Any solution would be appreciated.

See Question&Answers more detail:os

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

1 Reply

0 votes
by (71.8m points)

For reference, most of the accepted answer is unnecessary. The only key part is this (in the UIViewController - no need to edit or subclass EAGLView / GLKView):

self.view.opaque = NO; // NB: Apple DELETES THIS VALUE FROM NIB
self.view.backgroundColor = [UIColor clearColor]; // Optional: you can do this in NIB instead

You can set the background Color in the NIB - but you CANNOT set the opacity (Apple seems to overwrite this var for GL views at initWithCoder :( )

Plus, of course, in your OpenGL code you need to clear to alpha=0.0. So, wherever your glClear / glClearColor calls are already, replace the clearColor with:

glClearColor( 0, 0, 0, 0.0);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

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

...