2012-03-18 14 views
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 की ड्रा/रेंडर विधि? और मैं ओपनजीएल कहां लगा सकता हूं? कोई सुझाव?

उत्तर

9

अपने viewDidLoad में ओपनजीएल आरंभ करें, जैसा कि आप वर्तमान में कर रहे हैं।

GLKView's delegate के रूप में अपना व्यू कंट्रोलर पंजीकृत करने पर एक नज़र डालें। प्रतिनिधि के glkView:(GLKView *)view drawInRect: विधि को तब भी लागू किया जाएगा जब कोई रेड्रा आवश्यक हो।

This tutorial may help.

+0

मैं ट्यूटोरियल पर उसकी समीक्षा करेंगे, यह भी मैं कैसे प्रतिनिधियों काम – JohnnyAce

+0

तुम भी (http://developer.apple.com/library [GLKViewController] का उपयोग को देखने के लिए चाहते हो सकता है जांच करने की आवश्यकता UIViewController के बजाय /ios/#DOCUMENTATION/GLkit/Reference/GLKViewController_ClassRef/Reference/Reference.html)। यह एक प्रतिपादन पाश लागू करता है, ताकि आप समय-समय पर अपने GLKView को कई बार अपडेट कर सकें। –