博客:金属星球

1、创建一个继承于GLKViewController类的新类,比如HelloGLKitViewController

2、编辑文件HelloGLKitViewController.m,增加以下内容


@interface HelloGLKitViewController (){float _curRed;
BOOL _increasing;

}@property(strong, nonatomic) EAGLContext *context;

@end

@implementation HelloGLKitViewController
@synthesize context = _context;


并增加
 

  1.  
  2. -(void)viewDidLoad
  3. {[super viewDidLoad];
  4.  
  5. self.context =[[EAGLContext alloc] initWithAPI:kEAGLRenderingAPIOpenGLES2];
  6.  
  7. if(!self.context){
  8. NSLog(@quot;Failed to create ES contextquot;);
  9. }
  10.  
  11. GLKView *view =(GLKView *)self.view;
  12. view.context = self.context;
  13. }
  14.  
  15. -(void)viewDidUnload
  16. {[super viewDidUnload];
  17.  
  18. if([EAGLContext currentContext]== self.context){[EAGLContext setCurrentContext:nil];
  19. }
  20. self.context =nil;
  21. }#pragma mark - GLKViewDelegate
  22.  
  23. -(void)glkView:(GLKView *)view drawInRect:(CGRect)rect {
  24.  
  25. glClearColor(_curRed, 0.0, 0.0, 1.0);
  26. glClear(GL_COLOR_BUFFER_BIT);
  27.  
  28. }
  29.  
  30. #pragma mark - GLKViewControllerDelegate
  31.  
  32. -(void)update {if(_increasing){
  33. _curRed +=1.0* self.timeSinceLastUpdate;
  34. }else{
  35. _curRed -=1.0* self.timeSinceLastUpdate;
  36. }if(_curRed gt;=1.0){
  37. _curRed =1.0;
  38. _increasing =NO;
  39. }if(_curRed lt;=0.0){
  40. _curRed =0.0;
  41. _increasing =YES;
  42. }}
  43.  
  44. // 暂停功能
  45. -(void)touchesBegan:(NSSet*)touches withEvent:(UIEvent *)event {
  46. self.paused =!self.paused;
  47. }
  48.  

复制代码

3、在AppDelegate.m文件中删除 didFinishLaunchingWithOptions 函数中的内容,只留下 return YES;

4、然后创建一个新的Storyboard文件,命名为:MainStoryboard.storyboard打开这个文件,拖拽一个 View Controller 到空白处,选择这个控件在 Identity Inspector 中修改 class 为我们之前创建好的HelloGLKitViewController再点击控件内部的空白处,同样的方法设置 class 为 GLKView 。

5、下一步需要将这个故事板设定为启动项打开 HelloGLKit-Info.plist 文件,右键添加一行,下拉列表中选择 Main storyboard file base name 在后面的格子中填上故事板的文件名 MainStoryboard.
锐亚教育

锐亚教育,游戏开发论坛|游戏制作人|游戏策划|游戏开发|独立游戏|游戏产业|游戏研发|游戏运营| unity|unity3d|unity3d官网|unity3d 教程|金融帝国3|8k8k8k|mcafee8.5i|游戏蛮牛|蛮牛 unity|蛮牛