Download OpenGL Programming on Mac OS X

Transcript
Figure 8-2 Subclassing NSOpenGLView in Interface Builder
Open the Resources folder, and double-click on the MainMenu.nib icon. This
will open the nib file for this project in Interface Builder. Now switch to Interface
Builder.
In the MainMenu.nib window, click on the Classes tab, and navigate through
the three-pane system until you finally click on NSOpenGLView. The panes
should look like Figure 8-2 when selected.
Next click on the Classes menu and Subclass NSOpenGLView item to create a new derived class based on the NSOpenGLView type. A new text entry
field will appear, suggesting the name MyOpenGLView. Accept the default
name by pressing the Enter key or choose something more interesting and type
away. Your results should look similar to Figure 8-3.
So what did we just do? We told Interface Builder that we wanted to subclass NSOpenGLView for our own purposes. NSOpenGLView is derived from
the NSView class. It provides the integration between OpenGL and Cocoa. By
subclassing it, we become able to customize many aspects of its behavior, including pixel format selection and context sharing. But we’re getting ahead of
ourselves. First we’ve got to get MyOpenGLView into a form where we can write
some code.
We’ll now use Interface Builder to instantiate a default object when the nib file
is loaded, create some sample code, and arrange our view in the window.
First, let’s create an instance of our class. Return to the MainMenu.nib window, where you should still have MyOpenGLView selected. If not, navigate
through the hierarchy to re-select it. With MyOpenGLView selected, click on the
Classes menu and Instantiate MyOpenGLView item. This will create an
NSOpenGLView
123