首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在UIViewController中嵌套GLKView

在UIViewController中嵌套GLKView
EN

Stack Overflow用户
提问于 2012-03-18 09:32:23
回答 1查看 8.8K关注 0票数 7

我正在尝试在UIViewController中使用GLKView,我的代码如下所示

CustomViewController.h

代码语言:javascript
复制
#import <UIKit/UIKit.h>
#import <GLKit/GLKit.h>

@interface CustomViewController : UIViewController
{
    NSString * name;
}

@property NSString * name;

CustomViewController.m

代码语言:javascript
复制
#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的绘制/渲染方法?在哪里可以初始化OpenGL?有什么建议吗?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2012-03-18 10:31:59

在您的viewDidLoad中初始化OpenGL,就像您当前正在做的那样。

看看如何将视图控制器注册为GLKView's delegate。只要需要重画,就会调用委托的glkView:(GLKView *)view drawInRect:方法。

This tutorial may help.

票数 9
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/9755288

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档