2011-12-28 24 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

相关问题