ofxCocoa - how do you draw interface elements over the openframeworks GLView?

Hi,
does anyone know how (if possible) to add Cocoa UI elements over the main OpenFrameworks GLView in a Mac Os X window?
I would like to create a UI for my project but if I position elements in the XIB over the GLView canvas they are not rendered when the app is launched.

Hi, these aren’t mine, but you could checkout/reverse engineer … It seems you can create the GL context via Cocoa and plug OF in via listeners.

ofxCocoaWindow https://github.com/julapy/ofxCocoaWindow along with some deets and vid here http://www.creativeapplications.net/news/interface-builder-of-openframeworks-news/

Also https://github.com/ofZach/ofxNativeGui

And other Cocoa alternatives can be found on ofxAddons http://www.ofxaddons.com/categories/1-gui

I hope these help.

The most direct way to go about it would be to change ofApp.cpp to ofApp.mm and call ofGetCocoaWindow() in your ofApp. It’ll return an NSWindow that you can do whatever you want with.

You should still be able to use IB, but you’ll need to instantiate the xib yourself and then add the resulting root view as a subview of the NSWindow’s contentView.

If you want a gui window, I usually make a window with all the gui elements in interface builder and then add that over the OF window. The elements aren’t in the same window, but serves the purpose of a gui pretty well. Then you just need to hook up the gui values to your OF app.

NSWindow* nswin =  (NSWindow*)((ofAppGLFWWindow*)ofGetWindowPtr())->getCocoaWindow();
 soundMenuController = [[SoundMenuViewController alloc] initWithNibName:@"SoundMenuView" bundle:nil];
    
    if( soundMenuController != nil ) {
        if( nswin != nil ) {
            // set to the bottom of the window //
            NSPoint pos;
            pos.x = 20;
            pos.y = ofGetHeight() - 20;
            
            pos.x += ofGetWindowPositionX();
            pos.y += ofGetWindowPositionY();
            
            pos.y = ofGetScreenHeight() - pos.y;
            
            [[soundMenuController.view window] setFrameOrigin:pos];
            
            [ [soundMenuController.view window] orderOut:nil ]; // to hide it
        }
    }

To avoid all of the obj-c conflicts, try changing the Compile Source As to Objective-C++ in the Build Settings of your project.

Thank you everyone, I know it’s been a long time :slight_smile: I had to switch to another platform so I didn’t need this anymore but I’ll check everything out.