data between 2 Instantiations

Moderator
Posts: 916
Joined: 2002.10
Post: #1
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?
Quote this message in a reply
Moderator
Posts: 508
Joined: 2002.09
Post: #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..."
Quote this message in a reply
Sage
Posts: 1,403
Joined: 2005.07
Post: #3
You can do it a bit like this:

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.

Sir, e^iπ + 1 = 0, hence God exists; reply!
Quote this message in a reply
Moderator
Posts: 508
Joined: 2002.09
Post: #4
My solution is far more simple Rasp

"When you dream, there are no rules..."
Quote this message in a reply
Sage
Posts: 1,403
Joined: 2005.07
Post: #5
...but it doesn't do the same thing.

Sir, e^iπ + 1 = 0, hence God exists; reply!
Quote this message in a reply
Moderator
Posts: 916
Joined: 2002.10
Post: #6
unknown Wrote:You can do it a bit like this:

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.
this does for the most part what I think I want it to do...

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 Smile

PS. "delegate" doesn't exist., what exactly should be there
Quote this message in a reply
Moderator
Posts: 1,140
Joined: 2005.07
Post: #7
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.
Quote this message in a reply
Post Reply