Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

glkView drawInRect not called

I am learning OpenGLES and I am trying to put a GLKViewer inside an UIViewController.

I know I can come around the main issues by using GLViewController, but I am trying to learn how to do it this way.

I found this question, Nesting GLKView into UIViewController and Nested GLKView and GLKViewController but I must be missing something even though I think I am doing all the right steps because when I run my project, I am not getting to the drawInRect print line.

In the storyboard I am pointing the ViewController as the delegate of the glkview component.

I tried to keep the code as simple as possible and any help will be apreciated:

MyController.h

#import <Foundation/Foundation.h>
#import <GLKit/GLKit.h>

@interface MyGLController : UIViewController <GLKViewDelegate>
{
    GLuint vertexBufferID;

}

@property (weak, nonatomic) IBOutlet GLKView *glview;

@property (strong, nonatomic) GLKBaseEffect *baseEffect;

@end

MyGLController.m

#import "MyGLController.h"

@implementation MyGLController

//@synthesize baseEffect;

-(void) viewDidLoad{
    [super viewDidLoad];

    self.glview.context = [[EAGLContext alloc] initWithAPI:
     kEAGLRenderingAPIOpenGLES2];

     [EAGLContext setCurrentContext:self.glview.context];
    printf("View Loaded");
}


- (void)glkView:(GLKView *)view drawInRect:(CGRect)rect
{
    printf("DrawInRect");
}

@end

* Update *

As far as I can tell the glkview is hooked up properly as suggested per and added the josh-knapp and called setNeedsDisplay.

In case there's something I am missing, I have uploaded a copy of the project here: https://github.com/jcrogel/OpenGLDebug.git

I am a total noob in this so I apologize for any silly oversight :)

like image 765
Juan Carlos Moreno Avatar asked Nov 12 '12 16:11

Juan Carlos Moreno


3 Answers

You didn't say you hooked up the glview property of MyGLController in the storyboard, so verify that.

Next, you're setting up the glview context after it loads. Without a GLKViewController, there is nothing telling the glview it needs to be drawn. Make sure you call [self.glview setNeedsDisplay] somewhere after the context is set up.

like image 159
Josh Knapp Avatar answered Oct 19 '22 23:10

Josh Knapp


I had a similar problem.

By default, xcode sets the enable setNeedsDisplay checkbox to NO in GLKView property list.
Once I changed it, it worked.

like image 41
ashabtay Avatar answered Oct 19 '22 21:10

ashabtay


I see this question was already answered. But I had the same problem, with a different solution. I figured I'd post the info here on the off chance others might be able to benefit from it.

Problem Description

While using GLKView and GLKViewController, the render loop function (drawInRect) is called once, but not called again.

Possible Cause

Some methods to CViewController have been implemented incorrectly, without calling their supers. The following code illustrates three such functions. The examples below have the three functions implemented correctly, calling their supers.

-(void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:NO];
}

-(void)viewDidAppear:(BOOL)animated {
    [super viewDidAppear:NO];
}
-(void)viewWillDisappear:(BOOL)animated {
    [super viewWillDisappear:NO];
}
like image 23
MikeyE Avatar answered Oct 19 '22 23:10

MikeyE