7
我想在UIViewController中使用GLKView,我的代码看起来像这样嵌套GLKView到的UIViewController
CustomViewController.h
#import <UIKit/UIKit.h>
#import <GLKit/GLKit.h>
@interface CustomViewController : UIViewController
{
NSString * name;
}
@property NSString * name;
CustomViewController.m
#import "CustomViewController.h"
@interface CustomViewController()
@end
@implementation CustomViewController
@synthesize name;
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.
EAGLContext * context = [[EAGLContext alloc] initWithAPI:kEAGLRenderingAPIOpenGLES2];
CGRect mainScreen = [[UIScreen mainScreen] bounds];
GLKView * viewGL = [[GLKView alloc] initWithFrame:CGRectMake(mainScreen.size.width/2, mainScreen.size.height/2, 50, 50)];
viewGL.context = context;
[self.view addSubview:viewGL];
}
- (void)viewDidUnload
{
[super viewDidUnload];
// Release any retained subviews of the main view.
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
@end
我如何定义GLKView的绘制/渲染方法?我在哪里可以启动OpenGL?有什么建议么?
我要在教程一看,也是我需要检查的代表是如何工作的 – JohnnyAce 2012-03-18 04:51:22
你也可能想看看使用[GLKViewController](http://developer.apple.com/library /ios/#DOCUMENTATION/GLkit/Reference/GLKViewController_ClassRef/Reference/Reference.html)而不是UIViewController。它实现了一个渲染循环,所以你可以定期更新你的GLKView几次。 – 2012-03-19 03:02:05