我正在为一个图形框架做一个可可包装器。
为了最终画出这个东西,我这样做:
- (void)drawRect:(NSRect)rect
{
CGContextRef ctx = (CGContextRef)[[NSGraphicsContext currentContext] graphicsPort];
CGContextDrawImage(ctx, NSRectToCGRect(rect), image);
}在NSView的子类中。
现在我研究了其他框架,如Gosu,Irrlicht等,我发现它们总是在做复杂的NSOpenGL工作,比如:
// Settings, depending on fullscreen or not
NSOpenGLPixelFormatAttribute windowedAttrs[] =
{
NSOpenGLPFADoubleBuffer,
NSOpenGLPFAScreenMask,
(NSOpenGLPixelFormatAttribute)CGDisplayIDToOpenGLDisplayMask(CGMainDisplayID()),
NSOpenGLPFADepthSize,
(NSOpenGLPixelFormatAttribute)16,
(NSOpenGLPixelFormatAttribute)0
};
NSOpenGLPixelFormatAttribute fullscreenAttrs[] =
{
NSOpenGLPFADoubleBuffer,
NSOpenGLPFAScreenMask,
(NSOpenGLPixelFormatAttribute)CGDisplayIDToOpenGLDisplayMask(CGMainDisplayID()),
NSOpenGLPFAFullScreen,
NSOpenGLPFADepthSize,
(NSOpenGLPixelFormatAttribute)16,
(NSOpenGLPixelFormatAttribute)0
};
NSOpenGLPixelFormatAttribute* attrs = fullscreen ? fullscreenAttrs : windowedAttrs;
// Create pixel format and OpenGL context
ObjRef<NSOpenGLPixelFormat> fmt(
[[NSOpenGLPixelFormat alloc] initWithAttributes:attrs]);
::context = [[NSOpenGLContext alloc] initWithFormat: fmt.obj() shareContext:nil];他们为什么要这么做?我的“简单”方式可以吗?
发布于 2011-05-10 07:26:49
我同意ryyst的观点。您正在使用CGContext,它本质上是Quartz 2DAPI。OpenGL是图形的另一种选择,特别适用于复杂的3D渲染。
https://stackoverflow.com/questions/5776656
复制相似问题