multiple NSOpenGLViews
Hi
I'm trying to set up at least 2 (maybe more later) NSOpenGLViews that share the same resources. At this stage I'm struggling to even have 2 views without bothering with the sharing bit. There have been various problems, but currently my large view seems to have the same viewport as the the small one, though they have separate contexts. sometimes one or the other doesnt update for a while, some times one or the other is filled with garbage, and sometimes the small one shows the content of the large one.
By sometimes, I mean dependent on whether I've just started it up, resized one of the windows, switched to full screen and back etc. etc.
Any ideas what might be going wrong? Or links that might be useful when trying to do something like this?
Cheers,
David
I'm trying to set up at least 2 (maybe more later) NSOpenGLViews that share the same resources. At this stage I'm struggling to even have 2 views without bothering with the sharing bit. There have been various problems, but currently my large view seems to have the same viewport as the the small one, though they have separate contexts. sometimes one or the other doesnt update for a while, some times one or the other is filled with garbage, and sometimes the small one shows the content of the large one.
By sometimes, I mean dependent on whether I've just started it up, resized one of the windows, switched to full screen and back etc. etc.
Any ideas what might be going wrong? Or links that might be useful when trying to do something like this?
Cheers,
David
Chopper, iSight Screensavers, DuckDuckDuck: http://majicjungle.com
NSOpenGLViews can't share resources. You have to create the NSOpenGLContext yourself for that.
NSOpenGLView only guarantees that your context is current during -drawRect: and -reshape. Any GL calls you make outside those scopes are a bug.
NSOpenGLView only guarantees that your context is current during -drawRect: and -reshape. Any GL calls you make outside those scopes are a bug.
For a bit more context (no pun intended) This is for an editor for my game. My main game window currently uses a subclass of NSOpenGLView, and it's drawRect method is not overridden. Instead I have my own method that I call myself via a timer, or as often as possible. This has worked fine up until now.
Now I've tried using basically the same method with this new view which will contain a top down map. Forget the sharing contexts thing at this stage, first I just want to have 2 views that don't screw each other up.
So now that you might no a little more about where I'm at, are you saying I should override drawRect instead of calling my own method? If I called drawRect myself, would the contexts still be managed for me? Or perhaps I need to do some clever makeCurrentContext calling that currently isn't happening? I believe I am both using NSOpenGLView, and creating my own NSOpenGLContexts. From what you said it sounds like what I'm doing is impossible.... now you have me confused
David
Now I've tried using basically the same method with this new view which will contain a top down map. Forget the sharing contexts thing at this stage, first I just want to have 2 views that don't screw each other up.
So now that you might no a little more about where I'm at, are you saying I should override drawRect instead of calling my own method? If I called drawRect myself, would the contexts still be managed for me? Or perhaps I need to do some clever makeCurrentContext calling that currently isn't happening? I believe I am both using NSOpenGLView, and creating my own NSOpenGLContexts. From what you said it sounds like what I'm doing is impossible.... now you have me confused

David
Chopper, iSight Screensavers, DuckDuckDuck: http://majicjungle.com
If you submit GL commands outside of drawRect, then you need to ensure that you make the proper context current. Otherwise, you don't know what you're drawing into.
from within your method your timer calls try:
[myOGLView lockFocus];
// draw stuff here
[[myOGLView openGLContext] flushBuffer];
[myOGLView unlockFocus];}
or if you subclass drawRect: why not:
[myOGLView setNeedsDisplay:YES]; // redraw next pass of event loop
or:
[myOGLView display]; // redraw now!
[myOGLView lockFocus];
// draw stuff here
[[myOGLView openGLContext] flushBuffer];
[myOGLView unlockFocus];}
or if you subclass drawRect: why not:
[myOGLView setNeedsDisplay:YES]; // redraw next pass of event loop
or:
[myOGLView display]; // redraw now!
thankyou very much codemattic
I replaced my drawFrame methods with the overridden drawRect methods, and replaced all direct calls to the method with display: and setNeedsDisplay:, and it works like a charm.
I found that calling openGL intializing functions from the initWithFrame method didn't work, so I moved the calls to the reshape function and it works OK now.
I'm sure I was making the right context current before doing stuff earlier, but perhaps NSOpenGLView doesnt take kindly to that sort of thing...
Thanks again
David
I replaced my drawFrame methods with the overridden drawRect methods, and replaced all direct calls to the method with display: and setNeedsDisplay:, and it works like a charm.
I found that calling openGL intializing functions from the initWithFrame method didn't work, so I moved the calls to the reshape function and it works OK now.
I'm sure I was making the right context current before doing stuff earlier, but perhaps NSOpenGLView doesnt take kindly to that sort of thing...
Thanks again
David
Chopper, iSight Screensavers, DuckDuckDuck: http://majicjungle.com
oh yeh, and an unexpected side effect to doing it this way, is I got really smooth window resizing, where it was all flashy and munted before.
Chopper, iSight Screensavers, DuckDuckDuck: http://majicjungle.com

