2012-03-18 28 views
7

UIViewController içinde GLKView kullanmaya çalışıyorum içine, benim kod buYuvalama 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 

nasıl tanımlayabilirsiniz benziyor GLKView çizim/render yöntemi? ve OpenGL'yi nereden başlatabilirim? Baska öneri?

cevap

9

Şu anda yaptığınız gibi, viewDidLoad ürününüze OpenGL'yi sıfırlayın.

Görünüm denetleyicinizi GLKView's delegate olarak kaydetmeye göz atın. Yeniden çizme gerektiğinde delegenin glkView:(GLKView *)view drawInRect: yöntemi çağrılır.

This tutorial may help.

+0

Ben de delegeler Ayrıca http://developer.apple.com/library ([GLKViewController] kullanarak bakmak isteyebilirsiniz – JohnnyAce

+0

nasıl çalıştığını kontrol etmeniz gerekir, öğretici bir göz atacağız UIViewController yerine /ios/#DOCUMENTATION/GLkit/Reference/GLKViewController_ClassRef/Reference/Reference.html). Bir oluşturma döngüsü uygular, böylece GLKView'ınızı belirli aralıklarla saniyede birkaç kez güncelleyebilirsiniz. –