簡體   English   中英

(void)drawRect:(CGRect)rect iOS 5.1 OpenGL ES 2.0中的錯誤

[英]Errors in (void)drawRect:(CGRect)rect iOS 5.1 OpenGL ES 2.0

我正在嘗試通過opengl es 2.0模板在屏幕上繪制圖像。 它在MyGLKView的(void)drawRect:(CGRect)rect中顯示以下錯誤。 有什么解決辦法嗎? 謝謝!!

CGContextSaveGState:無效上下文0x0
CGContextSetBlendMode:無效的上下文0x0
CGContextSetAlpha:無效的上下文0x0
CGContextTranslateCTM:無效上下文0x0
CGContextScaleCTM:無效上下文0x0
CGContextDrawImage:無效上下文0x0
CGContextRestoreGState:無效的上下文0x0

MyGLKView.m

#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

GLKView的指定初始值GLKViewGLKView -initWithFrame:context: GLKView 您應該實現而不是-initWithFrame:並在super上調用它。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM