2011-04-25 88 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渲染。