Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 5 of 5

Thread: NSOpenGLView and Depth Testing

  1. #1
    Junior Member Newbie
    Join Date
    Nov 2000
    Posts
    10

    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
    *** Project:
    SteamWeasel. The
    revolution in turn based
    strategy games

  2. #2
    Intern Contributor
    Join Date
    Aug 2000
    Location
    USA
    Posts
    99

    Re: NSOpenGLView and Depth Testing

    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

  3. #3
    Junior Member Newbie
    Join Date
    Nov 2000
    Posts
    10

    Re: NSOpenGLView and Depth Testing

    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..
    *** Project:
    SteamWeasel. The
    revolution in turn based
    strategy games

  4. #4
    Junior Member Newbie
    Join Date
    Nov 2000
    Posts
    10

    Re: NSOpenGLView and Depth Testing

    still doesnt work
    *** Project:
    SteamWeasel. The
    revolution in turn based
    strategy games

  5. #5
    Junior Member Newbie
    Join Date
    Nov 2000
    Posts
    10

    Re: NSOpenGLView and Depth Testing

    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)
    *** Project:
    SteamWeasel. The
    revolution in turn based
    strategy games

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •