I am drawing my triangles in a world the triangles in the background but when I go behind it the triangle isn’t in the foreground (like it should be).
I put a video on YouTube showing the problem here (make sure you read the description)
EDIT:
//create instance of camera class
mainCamera = [[Camera alloc]init];
//Tell window to log mouse events
[[self window] setAcceptsMouseMovedEvents:YES];
//Timer for updating frames
NSTimer *timer = [NSTimer scheduledTimerWithTimeInterval:1/30 target:self selector:@selector(redraw) userInfo:nil repeats:YES];
//keep timer running during event tracking
[[NSRunLoop currentRunLoop] addTimer:timer forMode:NSEventTrackingRunLoopMode];
[[NSRunLoop currentRunLoop] addTimer:timer forMode:NSModalPanelRunLoopMode];
glEnable(GL_DEPTH_TEST);
glClearDepth(1.0f);
glShadeModel(GL_SMOOTH);
glEnable(GL_LINE_SMOOTH);
glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
//self in this case is my view. The code below is getting the size of the view.
gluPerspective(45.0f, [self frame].size.width / [self frame].size.height, 1.0f, 1000.0f);
glMatrixMode(GL_MODELVIEW);
//creating triangle objects
Did you create your context with a depth buffer?
Did you activate depth testing with
glEnable(GL_DEPTH_TEST);?Are you using an appropriate
glDepthFuncdepth test?