2011-04-25 90 views
1

我正在研究图形框架的可可包装。在NSWindow中绘图

为了最后得出的东西,我这样做:

- (void)drawRect:(NSRect)rect 
{ 
CGContextRef ctx = (CGContextRef)[[NSGraphicsContext currentContext] graphicsPort]; 
CGContextDrawImage(ctx, NSRectToCGRect(rect), image); 
} 

NSView一个子类中。

现在,我看着像古薮,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]; 

他们为什么所有的问题?我的“简单”方式好吗?

+1

如果它可以工作,那没关系,_enn in meinem Plutarch lese vongroßenMenschen_! – ryyst 2011-05-01 19:28:24

回答

2

我同意ryyst。您正在使用本质上是Quartz 2D API的CGContext。 OpenGL是图形的另一种选择,特别适合复杂的3D渲染。