0

Property 'layer' not found on object of type 'ViewController * where ViewController is of type GLKView and also I am importing following files in my opengl project

QuartzCore/QuartzCore.h

OpenGLES/ES2/gl.h

OpenGLES/ES2/glext.h

Code for ViewController.h

@interface ViewController : GLKViewController

{

    CAEAGLLayer* eaglLayer;

}

@end

ViewController.m

@interface ViewController ()

@property (nonatomic, strong) EAGLContext *context;
@property (nonatomic, strong) GLKBaseEffect *baseEffect;

@end 

@implementation ViewController

- (void)viewDidLoad
{
 [super viewDidLoad];
 // Do any additional setup after loading the view, typically from a nib.
 self.context = [[EAGLContext alloc] initWithAPI: kEAGLRenderingAPIOpenGLES2];
 GLKView *view = (GLKView *) self.view;
 view.context = self.context;
[EAGLContext setCurrentContext:self.context];

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

- (void)createLayer
{
 eaglLayer = (CAEAGLLayer *) self.layer;
 eaglLayer.opaque = YES;
}

Please tell what am I doing wrong?

Error lineAdded GLKView in controller

genpfault
  • 51,148
  • 11
  • 85
  • 139
  • I think you are mixing up views with view controllers. How do you know ViewController is a GLKView? – Justin Moser Oct 16 '14 at 06:16
  • because I am already setting it to GLKView. Please see edit I am attaching image related to it –  Oct 16 '14 at 06:18
  • I'd have to see more code to be sure but I think you are currently working inside of the @implementation for a GLKViewController which is not a view. If this is true then you should be able to access the layer by doing self.view.layer – Justin Moser Oct 16 '14 at 06:21
  • Added file code in edit –  Oct 16 '14 at 06:28
  • 1
    Thanks! I was confused because you have the +layerClass method in there but you mentioned "ViewController". This is how you access your layer: GLKViewController->GLKView->CALayer. In your code, "self" is actually a GLKViewController. So again to access the layer in code it would be: self.view.layer – Justin Moser Oct 16 '14 at 06:36

1 Answers1

0

You need to refer to the view, not to the controller.

_eaglLayer = (CAEAGLLayer*) self.view.layer;

should work.

SaeX
  • 17,240
  • 16
  • 77
  • 97