dekay
11-17-2000, 07: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_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
@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_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