Rudiger
Rudiger

Reputation: 6769

Displaying CAEAGLLayer in a UIView or CALayer

Rather new to trying to get OpenGL ES working on the iPhone, but I've created a working demo from an OpenGL template and wanted to add it to another App which is a standard UIViewController App. After searching around it seems that I can't addSubview a CAEAGLLayer to a CALayer aka UIView. How would I go about doing this? Or am I completely wrong in what I'm doing.

Cheers for any help

Upvotes: 1

Views: 3953

Answers (3)

Rudiger
Rudiger

Reputation: 6769

What I actually had to do was change in the EAGLView -initWithCoder to -initWithFrame and make the appropriate changes to the method to handle the frame. Once I did that and initialised the view with initWithFrame it worked.

Upvotes: 1

redshift5
redshift5

Reputation: 2006

Simply use a UIView and add:

+ (Class)layerClass {
    return [CAEAGLLayer class];
}

That UIView is now a CAEAGLLayer, so you can add that view as a subview of another UIView like normal.

Upvotes: 6

charlie hwang
charlie hwang

Reputation: 472

I believe you are looking for CALayer's insertSublayer methods or the addSublayer method.

Upvotes: 0

Related Questions