NSOpenGLView and Depth Testing

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

err, I have not done any OpenGL work in OSX outside of Carbon but it looks like you are ateempting to create a 1-bit depth buffer from what you posted. If that is the case I can practically guarantee that won’t work

I will try that, but it is quite odd, since these lines come directly out of th e teapot example from apple…but I will try it soon…

still doesnt work

fixed it!
in case anyone else needs help: The Buffers need to be enabled in Interface Builder (select the View and the go to the Inspector)

This topic was automatically closed 183 days after the last reply. New replies are no longer allowed.