erkanyildiz erkanyildiz - 9 months ago 67
Objective-C Question

Displaying an EAGLView with transparent background on a UIImageView

In my app, I have an EAGLView which is displaying some OpenGL 3D model, and a UIImageView which is displaying an image.

What I want is to display EAGLView above that UIImageView. No matter what I do, it keeps displaying UIImageView above EAGLView.

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

Any solution would be appreciated.


Here is the solution I found:

In EAGLView.m initialization

self.opaque = NO;
self.backgroundColor = [UIColor clearColor];

CAEAGLLayer *eaglLayer = (CAEAGLLayer *)self.layer;
eaglLayer.opaque = NO;

CGColorSpaceRef rgb = CGColorSpaceCreateDeviceRGB();
const CGFloat myColor[] = {0.0, 0.0, 0.0, 0.0};
eaglLayer.backgroundColor = CGColorCreate(rgb, myColor);