我正在尝试通过 opengl es 2.0 模板在屏幕上绘制图像。它在 MyGLKView 的 (void)drawRect:(CGRect)rect 中显示以下错误。有什么想法可以解决这个问题吗?谢谢!!
CGContextSaveGState:无效上下文 0x0
CGContextSetBlendMode:无效上下文 0x0
CGContextSetAlpha:无效上下文 0x0
CGContextTranslateCTM:无效上下文 0x0
CGContextScaleCTM:无效上下文 0x0
CGContextDrawImage:无效上下文 0x0
CGContextRestoreGState:无效上下文 0x0
我的GLKView.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
视图控制器.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