Hello OpenGl ES专家,
你有没有在UIView上添加GLKView?
我在这里尝试的是使用ios 6中的标准OpenGl ES模板。我正在使用GLKViewController,因为一切都已设置好。然后我试图将GLKViewController.view作为子视图添加到另一个UIViewController中的视图 - 但问题是没有在GLKViewController上调用update(),因此没有动画。尽管渲染了第一帧。
你对如何做到这一点有任何想法 - 或者我是否需要在同一个GLKViewController中使用UIView和GLKView?
提前致谢。
- (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;
}
答案 0 :(得分:0)
如果根视图不是GLKView,我认为你不应该使用GLKViewController。您可能想要丢弃GLKViewController并只使用GLKView - 您不希望进入嵌套viewControllers这样的事情。所以你只需将TopViewController作为常规的UIViewController子类,在TopViewController的设置代码中的某处,你就可以初始化所有的OpenGL内容并添加一个GLKView作为topViewController.view的子视图。
此外,你绝对不希望在应用程序中执行所有这些操作:didFinishLauncingWithOptions!它看起来应该在TopViewController的viewDidLoad方法中。您真的希望尽可能地远离App Delegate,[[TopViewController alloc] init]
和self.viewController = topViewController;
之间的所有内容都应该在TopViewController子类中发生。