Download OpenGL Programming on Mac OS X

Transcript
NSLog( @"No valid OpenGL pixel format" \
"matching attributes specified" );
// at this point, we’d want to try different
// sets of pixelformat attributes until we
// got a match, or decided we couldn’t create
// a proper working environment for our
// application
}
}
// init the context for later construction
_context = nil;
return self;
}
- (NSOpenGLContext *) openGLContext
{
if ( _context == nil ) // only if uninitialized
{
// if this is our first time to initialize
_context = [ [ NSOpenGLContext alloc ]
initWithFormat: _pixelformat
shareContext: [ [ SharedContext instance ] context ] ];
if ( _context == nil )
{
NSLog( @"No valid OpenGL context can be" \
"created with that pixelformat" );
/*
we can fail a few ways:
1 - bogus parameters: nil pixelformat, invalid
sharecontext, etc.
2 - share context uses a different Renderer
than the specified pixelformat
recovery techniques:
1 - choose a different pixelformat
2 - proceed without a shared context
*/
}
}
return( _context );
}
As you can see in Example C-7, the only changes we made from our original
custom view example are to use the [ [ SharedContext instance ]
pixelFormat ] accessor to create a pixel format for this view and then, similarly, to use the [ [ SharedContext instance ] context ] accessor
when constructing our context. We should always, of course, confirm that all
pixel formats and contexts are successfully created for our production code
as well. So, add code like this to your existing code and then make one
Additional Topics
307