NSOpenGLView does not update view
NSOpenGLView does not update view
- Subject: NSOpenGLView does not update view
- From: Dirkjan Krijnders <email@hidden>
- Date: Wed, 8 Oct 2008 15:24:34 +0200
Hi,
I have a problem rendering a scene to a NSOpenGLView. Here is a
outline of the setup: I have a carbon program (MATLAB) that allows for
plugins called mexfiles, these are just .dylib's with a plain C-entry
point. I setup a singleton controller object and feed the controller
new data via the entry points. The controller sets up a visualizer
thread to display the incoming data. This display thread is setup as
below. The problem is that when I resize the window the view gets
updated, however when I the timer fires I can see my drawRect:
function being called, but onscreen window is not updated. I found
other people with similar problems and I seems they solve it by
[window display] but this doesn't work here. Any ideas?
Thanks in advance
Dirkjan
Visualizer thread setup:
-(id)init
{
self = [super init];
pool = [[NSAutoreleasePool alloc] init];
NSApplicationLoad();
visWindow = [[NSWindow alloc] initWithContentRect:NSMakeRect(100,
100, 600, 400) styleMask:(NSTitledWindowMask|NSResizableWindowMask)
backing:NSBackingStoreRetained defer:NO];
[visWindow setTitle:@"Auditory cognition group Groningen"];
openglview = [[ACGMatrixView alloc] init];
[[visWindow contentView] setAutoresizesSubviews:YES];
[openglview setFrame:[[visWindow contentView] bounds]];
[openglview setAutoresizingMask:(NSViewWidthSizable |
NSViewHeightSizable)];
[[visWindow contentView] setAutoresizingMask:(NSViewWidthSizable |
NSViewHeightSizable)];
[openglview setWindow:visWindow];
[[visWindow contentView] addSubview:openglview];
windowManager = [[GLWindowOwner alloc] initWithWindow:visWindow];
[windowManager window]; // Make sure the window is loaded;
[visWindow makeKeyAndOrderFront:nil];
return self;
};
I setup the window in code so I don't need a nib to copy as well. The
thread is then started by:
-(void)backgroundThreadStarted {
NSAutoreleasePool* thePool = [[NSAutoreleasePool alloc] init];
// create a scheduled timer
[[NSRunLoop mainRunLoop] addTimer:[NSTimer
scheduledTimerWithTimeInterval:1.0 target:openglview
selector:@selector(updateView:) userInfo:nil repeats:YES]
forMode:NSRunLoopCommonModes];
m_isBackgroundThreadToTerminate = NO;
// create the runloop
double resolution = 300.0;
BOOL isRunning;
do {
// run the loop!
NSDate* theNextDate = [NSDate
dateWithTimeIntervalSinceNow:resolution];
isRunning = [[NSRunLoop currentRunLoop] runMode:NSDefaultRunLoopMode
beforeDate:theNextDate];
// occasionally re-create the autorelease pool whilst program is
running
NSLog(@"runloop cycle");
[thePool release];
thePool = [[NSAutoreleasePool alloc] init];
} while(isRunning==YES && m_isBackgroundThreadToTerminate==NO);
[thePool release];
}
The timer calls this function:
- (void)updateView:(NSTimer*)theTimer
{
[self setNeedsDisplay:YES];
[window display];
[window update];
};
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden