I cannot get the depth test to work…it seems to work with GLUT, but not NSopenGLView…any ideas?
@implementation MyOpenGLView
// — initWithFrame: —
-
(id)initWithFrame NSRect)frameRect
{
NSOpenGLPixelFormatAttribute attrs[] = {
NSOpenGLPFADepthSize, 1, // NSOpenGLPFADepthSize
NSOpenGLPFAAccelerated, 0};
NSOpenGLPixelFormat *pixFmt;pixFmt = [[NSOpenGLPixelFormat alloc] initWithAttributes:attrs];
self = [super initWithFrame:frameRect pixelFormat ixFmt];
return self;
}
// — drawRect: —
-
(void)drawRect NSRect)aRect
{
glEnable(GL_AUTO_NORMAL);
glEnable(GL_NORMALIZE);glEnable(GL_DEPTH_TEST); // bs: enabled depth testing
glDepthFunc (GL_LESS);glClearColor( 0.0, 1.0, 0.0, 0.0 );// R, G, B, alpha
glClear(GL_COLOR_BUFFER_BIT |
GL_DEPTH_BUFFER_BIT);// Clear the view
glViewport( 0,0,NSWidth([self bounds]),NSHeight([self bounds]) );// Set a coordinate system, and a point of view
glMatrixMode( GL_PROJECTION );
glLoadIdentity();gluPerspective( 45, NSWidth([self bounds])/NSHeight([self bounds]), 1, 40 );// fov, aspect ratio, near clipping plane, far clipping plane
glMatrixMode( GL_MODELVIEW );
glLoadIdentity();
gluLookAt( 0,0,[myController getCameraZoom], 0,0,0, 0,1,0 );// Rotate depending on the status of the sliders
glRotatef( [myController getRotationX], 1,0,0 );
glRotatef( [myController getRotationZ], 0,0,1 );// Draw
[[[myController getDocument] getBoard] drawBoard];// Flush gl code
glFinish();
}
@end