View Full Version : NSOpenGLView and Depth Testing

11-17-2000, 08:12 AM
I cannot get the depth test to work...it seems to work with GLUT, but not NSopenGLView...any ideas?

@implementation MyOpenGLView

// --- initWithFrame: ---
- (id)initWithFrame http://www.opengl.org/discussion_boards/ubb/frown.gifNSRect)frameRect
NSOpenGLPixelFormatAttribute attrs[] = {
NSOpenGLPFADepthSize, 1, // NSOpenGLPFADepthSize
NSOpenGLPFAAccelerated, 0};
NSOpenGLPixelFormat *pixFmt;

pixFmt = [[NSOpenGLPixelFormat alloc] initWithAttributes:attrs];
self = [super initWithFrame:frameRect pixelFormat http://www.opengl.org/discussion_boards/ubb/tongue.gifixFmt];
return self;

// --- drawRect: ---
- (void)drawRect http://www.opengl.org/discussion_boards/ubb/frown.gifNSRect)aRect

glEnable(GL_DEPTH_TEST); // bs: enabled depth testing
glDepthFunc (GL_LESS);

glClearColor( 0.0, 1.0, 0.0, 0.0 );// R, G, B, alpha

// Clear the view
glViewport( 0,0,NSWidth([self bounds]),NSHeight([self bounds]) );

// Set a coordinate system, and a point of view
glMatrixMode( GL_PROJECTION );

gluPerspective( 45, NSWidth([self bounds])/NSHeight([self bounds]), 1, 40 );// fov, aspect ratio, near clipping plane, far clipping plane

glMatrixMode( GL_MODELVIEW );
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

DJ Tricky S
11-17-2000, 05:40 PM
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 http://www.opengl.org/discussion_boards/ubb/smile.gif

11-18-2000, 01:33 AM
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.. http://www.opengl.org/discussion_boards/ubb/smile.gif

11-18-2000, 02:34 AM
still doesnt work http://www.opengl.org/discussion_boards/ubb/frown.gif

11-18-2000, 04:20 AM
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)