简体   繁体   中英

ios OpenGl ES / GLKit - UIView as super and GLKView as sub view

Hello OpenGl ES expert,

Have you ever added a GLKView on top of a UIView?

What I am trying out here is to use the standard OpenGl ES template from ios 6. I am using the GLKViewController, as everything is setup. Then I am trying to add the GLKViewController.view as a sub view to the view in another UIViewController - but the problem is that update() is not called on GLKViewController, and therefore no animation. The first frame is rendered though.

Do you have any idea on how to do this - or do I need to have bout UIView and GLKView in the same GLKViewController?

Thanks in advance.

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
    // Override point for customization after application launch.

    UIViewController* topViewController = [[TopViewController alloc] init];

    UIImageView* uiImageView = [[UIImageView alloc] initWithFrame:self.window.frame];
    NSString *imgFrontFilepath = [[NSBundle mainBundle] pathForResource:@"front" ofType:@"png"];
    UIImage* frontImg = [[UIImage alloc] initWithContentsOfFile:imgFrontFilepath];
    [uiImageView setImage:frontImg];
    [topViewController setView:uiImageView];

    GLKViewController* glkViewController = [[[ViewController alloc] initWithNibName:@"ViewController" bundle:nil] autorelease];
    // glkViewController.paused = NO;

    [[topViewController view] addSubview:[glkViewController view]];

    self.viewController = topViewController; //[[[ViewController alloc] initWithNibName:@"ViewController" bundle:nil] autorelease];
    self.window.rootViewController = topViewController; //self.viewController;
    [self.window makeKeyAndVisible];
    return YES;
}

I don't think you should be using GLKViewController if the root view is not a GLKView. You probably want to discard the GLKViewController and just use a GLKView -- you don't want to get into nesting viewControllers for something like this. So you'd just have TopViewController as a regular UIViewController subclass, and somewhere in the setup code for TopViewController, you'd initialize all your OpenGL stuff and add a GLKView as a subview of topViewController.view.

Also, you definitely don't want to be doing all that stuff in application:didFinishLauncingWithOptions! It looks like it should be in TopViewController's viewDidLoad method. You really want to stay out of the App Delegate as much as possible, and everything between [[TopViewController alloc] init] and self.viewController = topViewController; should happen inside the TopViewController subclass.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM