2011-12-28 81 views

回答

2

當然,您可以通過編程創建所有UI元素。您只需創建一個窗口NSOpenGLView內容,例如:

NSWindow *w = [[NSWindow alloc] initWithContentRect:NSMakeRect(100,100,400,300) 
              styleMask:NSTitledWindowMask|NSClosableWindowMask|NSMiniaturizableWindowMask|NSResizableWindowMask 
              backing:NSBackingStoreBuffered 
               defer:YES]; 
NSRect frame = [w contentRectForFrameRect:[w frame]]; 
// this is optional - request accelerated context 
unsigned int attrs[] = { NSOpenGLPFAAccelerated, 0 }; 
NSOpenGLPixelFormat *pixelFormat = [[NSOpenGLPixelFormat alloc] initWithAttributes:(NSOpenGLPixelFormatAttribute*)attrs]; 
NSOpenGLView *view = [[NSOpenGLView alloc] initWithFrame:frame pixelFormat:pixelFormat]; 
[pixelFormat release]; 
// manage properties of the window as you please ... 
[w setOpaque:YES]; 
[w setContentView:view]; 
[w makeFirstResponder:view]; 
[w setContentMinSize:NSMakeSize(150.0, 100.0)]; 
[w makeKeyAndOrderFront: self]; 

在實踐中,你可能會繼承NSOpenGLView和使用你的類,而不是...

+0

這真的很難找到一個最新的指南,但這工作很好,謝謝西蒙! – Tradition 2011-12-29 04:31:52

相關問題