建立OpenGL視圖(必要的投影,攝像機角度等)用於繪製2D遊戲所需的最低樣板代碼是多少?什麼是OpenGL 2D視圖的最小樣板代碼?
例如,做石英2D中的自定義視圖繪圖(和,比方說,加載一個背景圖像)所需的最小如下:
#import <Cocoa/Cocoa.h>
@interface MyView : NSView {
}
@end
= = =
#import "MyView.h"
@implementation MyView
- (id)initWithFrame:(NSRect)frame {
self = [super initWithFrame:frame];
return self;
}
- (void)drawRect:(NSRect)rect {
CGContextRef myContext = [[NSGraphicsContext currentContext] graphicsPort];
CGRect frame = CGRectMake(bounds.origin.x, bounds.origin.y, bounds.size.width, bounds.size.height);
CFBundleRef mainBundle = CFBundleGetMainBundle();
CFURLRef url = CFBundleCopyResourceURL(mainBundle, CFSTR("background"), CFSTR("png"), NULL);
CGDataProviderRef provider = CGDataProviderCreateWithURL (url);
CGImageRef image = CGImageCreateWithPNGDataProvider (provider, NULL, true, kCGRenderingIntentDefault);
CGDataProviderRelease (provider);
CGContextDrawImage (myContext, frame, image);
CGImageRelease (image);
//rest of drawing code here...
}
@end
樣板代碼中的任何內容與iPhone上的Open GS ES不同,而不是在Mac上使用Open GL?
哦,請不要推薦遊戲庫,cocos2D等人。我只想要一個基於OpenGL的答案。 – Hejazzman 2009-05-23 00:40:51