我目前正在尝试以编程方式创建一个简单的可可NSWindow,而不是使用接口构建器(我有这样做的理由)。这是一个快速测试:
int main(int argc, char** argv){
NSWindow *mainwin;
CocoaGLView *mainview;
NSRect scr_frame;
unsigned int style_mask;
NSAutoreleasePool *pool =[[NSAutoreleasePool alloc] init];
[NSApplication sharedApplication];
scr_frame= NSMakeRect(100, 100, 400, 400);
style_mask=NSClosableWindowMask|NSMiniaturizableWindowMask|
NSResizableWindowMask|NSTitledWindowMask;
scr_frame=[NSWindow contentRectForFrameRect:scr_frame
styleMask:style_mask];
mainwin=[[NSWindow alloc]
initWithContentRect:scr_frame
styleMask:style_mask
backing:NSBackingStoreBuffered
defer:NO];
[mainwin makeKeyAndOrderFront:nil];
[mainwin setTitle:@"Visible screen window"];
mainview=[[CocoaGLView alloc] initWithFrame:scr_frame];
[mainwin setContentView:mainview];
[mainview display];
[mainwin setReleasedWhenClosed:YES];
[pool drain];
[NSApp run];
return 0;
}CocoaGLView由NSOpenGLView派生而来,如下所示:
@interface CocoaGLView : NSOpenGLView {
//some stuff
}
- (id) initWithFrame: (NSRect) frameRect;
- (void)setFrameSize:(NSSize) aSize;
- (void)drawRect:(NSRect) aRect;
@end它通常是有效的。我能看到窗户。我甚至可以看到我在CocoaGLViews drawRect函数中绘制的openGL内容,但不幸的是该函数只被调用一次,我错过了什么?
发布于 2010-06-09 00:12:33
为什么你希望它被多次调用呢?当操作系统认为视图的内容不再有效时,会要求绘制视图。如果您希望定期绘制OpenGL视图,则需要设置一个计时器,将setNeedsDisplay:消息发送到您的视图。
https://stackoverflow.com/questions/2997046
复制相似问题