I’m doing a program about lights in OpenGL. I built the interface using Interface Builder, but I’m now completely at a loss as to how make my ANSI C code interact with Interface Builder objects. I mean: my C codes creates a scene that can be rotated, etc. How do I make my scene appear in IB? How do I make my IB sliders use my C event handling function?
How do I make my scene appear in IB?
You need to have a NSView instance which can do OpenGL calls.
I think there is one in the IB palette…
How do I make my IB sliders use my C event handling function?
You need to define actions in a Objective-C controller class.
Then an action can call your C code.
There is lots of example on Apple developpeer section… See ‘Sample Code’ on ‘3D graphics’ and ‘Cocoa’
There is a good OpenGL in Cocoa demo on Apple’s site. Strangely enough they don’t use the OpenGL view from the palette, instead the subclass NSOpenGLView and put a custom view into the window using IB and then tell it that the custom view is of type “whatever your subclass is”.
I’m not sure why they did this, however, I ran into problems using the palette as well, so I followed the same technique and it works just fine.
If you want to manipulate with sliders, add a couple of IBAction’s to your subclass and then load the .h file into IB so that you can use the cool hold-control-and-drag-between-items method to hook stuff up.
You can then have your IBActions send getFloat messages to <sender> and that will get the value for you and you can call your C code with the updated values and then [self setNeedsDisplay: true].
Hope this helps,
This topic was automatically closed 183 days after the last reply. New replies are no longer allowed.