29,028
社区成员
发帖
与我相关
我的任务
分享
- (id) initWithFrame: (CGRect) frame
{
NSLog(@"fram e %f",frame.origin.x);
if (self = [super initWithFrame:frame])
{
CAEAGLLayer* eaglLayer = (CAEAGLLayer*) self.layer;
eaglLayer.opaque = YES;
EAGLRenderingAPI api = kEAGLRenderingAPIOpenGLES2;
m_context = [[EAGLContext alloc] initWithAPI:api];
if (!m_context) {
api = kEAGLRenderingAPIOpenGLES1;
m_context = [[EAGLContext alloc] initWithAPI:api];
}
if (!m_context || ![EAGLContext setCurrentContext:m_context]) {
[self release];
return nil;
}
m_resourceManager = Darwin::CreateResourceManager();
m_applicationEngine = ParametricViewer::CreateApplicationEngine(m_renderingEngine);
[m_context
renderbufferStorage:GL_RENDERBUFFER
fromDrawable: eaglLayer];
int width = CGRectGetWidth(frame);
int height = CGRectGetHeight(frame);
NSLog(@"gl w - h %d\t%d", width , height );
m_applicationEngine->Initialize(width-50, height-50);
[self drawView: nil];
CADisplayLink* displayLink;
displayLink = [CADisplayLink displayLinkWithTarget:self
selector:@selector(drawView:)];
[displayLink addToRunLoop:[NSRunLoop currentRunLoop]
forMode:NSDefaultRunLoopMode];
}
return self;
}
- (void) drawView: (CADisplayLink*) displayLink
{
if (displayLink != nil) {
float elapsedSeconds = displayLink.timestamp - m_timestamp;
m_timestamp = displayLink.timestamp;
m_applicationEngine->UpdateAnimation(elapsedSeconds);
}
m_applicationEngine->Render();
[m_context presentRenderbuffer:GL_RENDERBUFFER];
}
http://
-(void) viewWillAppear:(BOOL)animated
{
if(new_display)
{
// [m_view release];
CGRect screenBounds = [[UIScreen mainScreen] bounds];
screenBounds.origin.y = 100 ;
screenBounds.size.height -= 200 ;
m_view = [[GLView alloc] initWithFrame: screenBounds];
[self.view addSubview:m_view];
new_display = false ;
}
}
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view from its nib.
CGRect screenBounds = [[UIScreen mainScreen] bounds];
screenBounds.origin.y = 100 ;
screenBounds.size.height -= 200 ;
if(g_crc)
t_crc = *g_crc;
viewport_h =320 ,viewport_w =368;
m_view = [[GLView alloc] initWithFrame: screenBounds];
[self.view addSubview:m_view];
}