2012-06-03 2 views
1

opengl es 2.0 템플릿을 통해 화면에 이미지를 그려야합니다. 그것은 MyGLKView에서 (void) drawRect : (CGRect) rect에 다음 오류를 표시합니다. 이 문제를 해결할 수있는 아이디어가 있습니까? 고맙습니다!!(void) drawRect 오류 : (CGRect) rect iOS 5.1 OpenGL ES 2.0

CGContextSaveGState : 유효하지 않은 컨텍스트 0x0으로
CGContextSetBlendMode : 유효하지 않은 컨텍스트 0x0으로
CGContextSetAlpha : 유효하지 않은 컨텍스트 0x0으로
CGContextTranslateCTM : 유효하지 않은 컨텍스트 0x0으로
CGContextScaleCTM : 유효하지 않은 컨텍스트 0x0으로
CGContextDrawImage : 잘못된 컨텍스트 0x0으로
CGContextRestoreGState : 잘못된 컨텍스트 0x0

MyGLKView.m

,515,
#import "MyGLKView.h" 
@implementation MyGLKView 

@synthesize pUIImage; 

//- (id)initWithFrame:(CGRect)frame 
- (id)initWithFrame:(CGRect)frame context:(EAGLContext *)context 
{ 
    //if (self = [super initWithFrame:frame]) 
    if (self = [super initWithFrame:frame context:context]) 
    { 
     // Initialization code 
     pUIImage = [UIImage imageNamed:@"star-green.png"]; 
    } 
    return self; 
} 


// Only override drawRect: if you perform custom drawing. 
// An empty implementation adversely affects performance during animation. 
- (void)drawRect:(CGRect)rect 
{ 
    // Drawing code 
    [pUIImage drawAtPoint:CGPointMake(0, 0)]; 
} 

@end 

ViewController.m는

#import "ViewController.h" 
#import "MyGLKView.h" 

@implementation ViewController 

@synthesize pContext; 

- (void)viewDidLoad 
{ 
    [super viewDidLoad]; 
    pContext = [[EAGLContext alloc] initWithAPI:kEAGLRenderingAPIOpenGLES2]; 

    if (!pContext) 
    { 
     NSLog(@"Failed to create ES context"); 
    } 

    //MyGLKView *pMyGLKView = [[MyGLKView alloc] init]; 
    //pMyGLKView.context = pContext; 
    //self.view = pMyGLKView; 
    self.view = [[MyGLKView alloc] initWithFrame:[[UIScreen mainScreen] bounds] context:pContext]; 
} 

- (void)viewDidUnload 
{  
    [super viewDidUnload]; 

} 

- (void)didReceiveMemoryWarning 
{ 
    [super didReceiveMemoryWarning]; 
    // Release any cached data, images, etc. that aren't in use. 
} 

- (void)update 
{ 

} 

@end 

답변

0

GLKView위한 지정된 이니셜 -initWithFrame:context:이다. -initWithFrame:이 아니라이를 구현해야하며 super에서 호출해야합니다.

+0

변경되었습니다. 하지만 여전히 같은 문제가 있습니다. 편집 된 포스트 – WooD

+1

보기'-drawRect :'메소드는 Core Graphics 컨텍스트를 예상하는 "일반"드로잉을하고 있습니다. 'GLKView'는'EAGLContext'를 그립니다. 따라서 OpenGL ES 드로잉 작업을 수행해야합니다. –

+0

OpenGL ES 드로잉 작업을 통해 이미지를 그릴 수 있습니까? 그렇다면 어떻게 보여줄 수 있습니까? 이 링크 (http://stackoverflow.com/questions/4820372/explain-how-opengl-es-background-images-work)가 내 이미지를 그리는 올바른 방향인가? 나는 거대한 양의 인터넷 검색을하고 있으며 하루 동안 노력하고있다. 나는 아직도 그릴 수 없다. 고맙습니다! – WooD