Download OpenGL Programming on Mac OS X

Transcript
2 -proceed without a shared context
*/
}
}
return( _context );
}
- (void) lockFocus
{
NSLog( @"myView::lockFocus" );
// ensure we are ready to draw
[ super lockFocus ];
// get our context
NSOpenGLContext *cxt = [ self openGLContext ];
// ensure we are pointing to ourself as the Drawable
if ( [ cxt view ] != self )
{
[ cxt setView: self ];
}
// make us the current OpenGL context
[ cxt makeCurrentContext ];
}
- (void) prepareOpenGL
{
NSLog( @"myView::prepareOpenGL" );
glMatrixMode( GL_PROJECTION );
glLoadIdentity();
glOrtho(-1,1,-1,1,-1,100);
}
- (void) drawRect: (NSRect) rect
{
// adjust viewing parameters
glViewport( 0, 0,
(GLsizei) rect.size.width, (GLsizei) rect.size.height );
glClearColor( 0, .5, .8, 0 );
glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
glMatrixMode( GL_MODELVIEW );
glLoadIdentity();
glTranslatef( 0, 0, -1 );
GLfloat green[ 4 ] = { 0, 1, 0, 0 };
glMaterialfv( GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, green );
glutSolidTeapot( .5 );
298
Appendix C: The Cocoa API for OpenGL Configuration in Leopard