Why when I render a scene with a revolving camera objects that you'd expect to appear behind others don't do that? OPENGL Objective-c

StackOverflow https://stackoverflow.com/questions/2664936

문제

I am rendering a scene in which I have two spheres. I am revolving a camera around one of them. What happens is counter-intuitive. When the camera goes around the sphere the other gets in front of it when you'd expect it to be behind. So it appears as though the spheres aren't revolving around each other and the one the should go around is always upfront. Please help.

Here is the code that renders the scene:

glLoadIdentity();

[self positionCamera];

glutSolidSphere(2, 12,12);

glPushMatrix();
glTranslatef(5, 0, 0);
glutSolidSphere(0.5, 12,12);
glPopMatrix();

glFlush();  

This block is part of a class that gets called on using.

[NSTimer scheduledTimerWithTimeInterval:DEFAULT_ANIMATION_INTERVAL 
                                 target:self 
                               selector:@selector(drawRect) 
                               userInfo:nil 
                                repeats:YES];

And

-(void)positionCamera{}

Contains math do camera revolution and gluLookAt()

도움이 되었습니까?

해결책

Basically what you're doing now is a back-to-front rendering, where the last primitive drawn will always appear be drawn over the others.

What you want to do is enable the depth test, where the depth of each fragment will be compared before being drawn on screen. glEnable(DEPTH_TEST) should help.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top