Cocoa Controls with OpenFrameworks

Hi All!

Need a bit of help getting cocoa controls working with a OpenFrameworks project.

I’ve tried out all 3 cocoa extras I could find and can’t get what I’m looking to do working.

I’ve tried these:
ofxCocoaWindow
ofxCocoaWindowNibless
ofxCocoa

For both ofxCocoaWindow and ofxCocoaWindowNibless I got their example projects running, but I’m not able to add any controls to the window / view.

For ofxCocoa, I couldn’t get their example working. It looks like it requires GLEW which I haven’t been able to get installed correctly.

Ultimately what I’m trying to do is get cocoa controls working so I can use those instead of any ofxUI extras. My sandbox tests were just using an image view and adding it to the glView, or the window contentView like this:

UIImage * image = [UIImage imageNamed:@“test.jpg”];
UIImageView * imgView = [[UIImageView alloc] initWithFrame:NSMakeRect(0,0,64,64)];
//
//[glView addSubview:imgView];
// OR
//[window.contentView addSubview:imgView];
// OR
//[[[NSApp sharedApplication] delegate].glWindow.contentView addSubview:imgView];

Seems like the examples in these cocoa extras don’t actually show an example of what their supposed to be doing? - cocoa controls. Which is what I’m after, but those examples just setup a window and assume anything else would work.

Does anyone have a simple working example? Generally I like to take the emptyExample and just make it work first. Something like that would be awesome.

Thanks for any help!

I missed one line of code that I can’t get edited back in the post…

[imgView setImage:image];

Actually I’m seeing people using cocoa controls without using one of these cocoa extras, is that possible? Anyone have a link or information about it?

Thanks!

I’m contemplating the same problem!
So weird because I used a translator can say
Like you saw an example of three kinds, I can not find it.
I want to control using xib
But concerning xib too hard to find examples or sources
If you find answers me share this article
I hope you find the answer soon
Wing. in Korea

Hey guys,

There are a couple of these floating around, but we have a fork of Memo Atken’s ofxCocoa library that works on of 007 - 0071. Check it out here: https://github.com/labatrockwell/msalibs
( you’ll have to get the whole repository then just grab ofxCocoa from there)

It includes his original example of using xibs to control OF. The GLUT errors you were seeing have to do with how ofSetupOpenGL changed after 006.

Check it out + feel free to follow up if you have questions!

Hey robotconscience,

I tried the ofxCocoa but the example project is missing the openframeworks lib. So it wouldn’t compile for me.

I managed to integrate it into my own app and it compiles, but when it tries to load it says:

2012-08-05 20:13:50.759 emptyExample[28493:107] AppWindow::AppWindow()
2012-08-05 20:13:50.760 emptyExample[28493:107] AppWindow::setupOpenGL()
2012-08-05 20:13:50.761 emptyExample[28493:107] trying Multisampling
2012-08-05 20:13:50.791 emptyExample[28493:107] Multisampling supported
2012-08-05 20:13:50.903 emptyExample[28493:107] AppWindow::initializeWindow()
2012-08-05 20:13:50.904 emptyExample[28493:107] AppWindow::runAppViaInfiniteLoop()
2012-08-05 20:13:50.933 emptyExample[28493:107] Unable to load nib file: WithWindow, exiting

Is there a fully working example with 0071?

Hey Seth,

Firstly, the ofxCocoa example should work if you copy it into your examples/addons directory (sorry, forgot to mention that!).

To integrate ofxCocoa into an existing project, you need to add the nib files (hence your error) to your project.

* If you look in ofxCocoa/nibs you will see two files with the .xib extension. Make sure these are added to your project
* open your .plist file (yourApp/openFrameworks-Info.plist) in XCode.
* Click any property and click the “+” button that appears; this should create a new row.
* Type “Main nib file base name” into the first row of the field
* Type “WithWindow” into the second field
* Try running again!

Feel free to follow up if you have questions! I’m not really the one maintaining this addon (again, just Memo Atken’s library with a few updates), but I’ll help out as best I can.

Hi robotconscience,

I actually did copy it into examples/addons, but at least for me, it didn’t have the OF project inside of the examples.

I also did include the .xib files in my project. I’ll double check again to make sure the target was set though, but I think it was.

I’ll look at it again in a day or two, but I think I actually followed your steps using 0071 from the OF download page.

Thanks for taking the time to reply.