2012-03-18 12 views
7

Próbuję użyć GLKView w UIViewController, mój kod wygląda następującozagnieżdżanie GLKView do 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 

Jak można zdefiniować metoda rysowania/renderowania GLKView? i gdzie mogę zainicjować OpenGL? Jakieś sugestie?

Odpowiedz

9

Zainicjuj OpenGL w swoim viewDidLoad, tak jak obecnie.

Zobacz rejestrację kontrolera widoku jako GLKView's delegate. Metoda delegata o numerze glkView:(GLKView *)view drawInRect: będzie wywoływana za każdym razem, gdy wymagane będzie odświeżenie.

This tutorial may help.

+0

będę spojrzeć na samouczku też muszę sprawdzić, jak działają delegatów – JohnnyAce

+0

Można również zajrzeć do korzystania [GLKViewController] (http://developer.apple.com/library /ios/#DOCUMENTATION/GLkit/Reference/GLKViewController_ClassRef/Reference/Reference.html) zamiast UIViewController. Implementuje pętlę renderowania, dzięki czemu można okresowo aktualizować GLKView kilka razy na sekundę. –

Powiązane problemy