7

UIViewController で GLKView を使用しようとしています。コードは次のようになります。

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 の draw/render メソッドを定義するにはどうすればよいですか? どこでOpenGLを初期化できますか? 助言がありますか?

4

1 に答える 1

9

viewDidLoad現在行っているのと同じように、でOpenGL を初期化します。

View Controller をGLKView の delegateとして登録する方法を見てください。デリゲートのglkView:(GLKView *)view drawInRect:メソッドは、再描画が必要になるたびに呼び出されます。

このチュートリアルが役立つ場合があります。

于 2012-03-18T02:31:59.327 に答える