data between 2 Instantiations
m'k, so I have an NSOpenGLView create in iBuilder and I also have my Controller class, also instantiated via iBuilder.
How would I go about passing data between these 2?
How would I go about passing data between these 2?
Add an outlet to the view in your controller. Then control click on the controller (make sure you've instatiated it in IB so that you get a blue cube) and drag a connection to the view. In the inspector window, select the outlet of you just created and click connect.
"When you dream, there are no rules..."
You can do it a bit like this:
Hope that's what you were looking for.
Code:
@implementation MyOpenGLView
- (void)drawGL
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glLoadIdentity();
if(delegate) {
[delegate performSelector:gfxCallback];
}
}
- (void)setDelegate:(id)_delegate graphicsCallback:(SEL)_gfxCallback
{
delegate = _delegate;
gfxCallback = _gfxCallback;
}
@endCode:
@implementation Controller
- (void)awakeFromNib
{
[myOpenGLViewOutlet setDelegate:self graphicsCallback:@selector(glCallback)];
[myOpenGLViewOutlet setNeedsDisplay:YES];
}
- (void)glCallback
{
// Here you can perform any OpenGL commands and they are executed and drawn in the myOpenGLViewOutlet's context
}
@endHope that's what you were looking for.
Sir, e^iπ + 1 = 0, hence God exists; reply!
My solution is far more simple
"When you dream, there are no rules..."
...but it doesn't do the same thing.
Sir, e^iπ + 1 = 0, hence God exists; reply!
unknown Wrote:You can do it a bit like this:this does for the most part what I think I want it to do...
Code:
@implementation MyOpenGLView
- (void)drawGL
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glLoadIdentity();
if(delegate) {
[delegate performSelector:gfxCallback];
}
}
- (void)setDelegate:(id)_delegate graphicsCallback:(SEL)_gfxCallback
{
delegate = _delegate;
gfxCallback = _gfxCallback;
}
@end
Code:
@implementation Controller
- (void)awakeFromNib
{
[myOpenGLViewOutlet setDelegate:self graphicsCallback:@selector(glCallback)];
[myOpenGLViewOutlet setNeedsDisplay:YES];
}
- (void)glCallback
{
// Here you can perform any OpenGL commands and they are executed and drawn in the myOpenGLViewOutlet's context
}
@end
Hope that's what you were looking for.
though I don't really want to draw any of the opengl commands in my controller class. it's already bloated enough. BUT I SUPPOSE IT WILL WORK

PS. "delegate" doesn't exist., what exactly should be there
You would have to declare a variable. (in this case, id delegate) Personally, if all you want to do is pass information, I would just have functions and make sure that the controller has the instance of the OpenGL view, as per Taxxodium's suggestion. No need for actual code other than the IBOutlet, and a control-click is all you need. You can even just have the controller pass itself to the view through a function so it knows what to do, and not bother with trying to pass selectors back and forth, since you would just know what functions you want to call anyway.

