2011-04-25 8 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

정상적으로 작동한다면, 괜찮습니다. 즉, Plutarch lese von großen Menschen_! – ryyst

답변

2

나는 ryyst에 동의합니다. 본질적으로 Quartz 2D API 인 CGContext를 사용하고 있습니다. OpenGL은 복잡한 3D 렌더링에 특히 좋은 그래픽 옵션입니다.