0
我有簡單的studyng項目代表一些太空星系統。我有一顆恆星和幾顆行星,星星周圍有衛星旋轉。我正在使用深度緩衝區,但行星總是在星星的前方,即使星球應該被星星遮住。什麼是問題原因?OpenGL顏色深度緩衝區
void drawPlanet(float orbitRadius, float planetRadius, float daysInYear, float hoursInDay){
static float year = 0;
static float days = 0;
static float hours = 0;
glPushMatrix();
glRotatef(year, 0, 1, 0);
glTranslatef(orbitRadius, 0 ,0);
glRotatef(days, 1, 2, 0);
glutWireSphere(planetRadius, 20, 16);
drawLuna(0.3, 0.1, 30, 15);
glPopMatrix();
hours++;
days = hours/hoursInDay;
year=days/daysInYear;
}
void display(void){
glClear(GL_COLOR_BUFFER_BIT);
glLoadIdentity();
gluLookAt(0,0,5, 0, 0, 0, 0 ,1, 0);
glColor3f(1.0, 0.647059, 0.00);
glutSolidSphere(0.5, 20, 16);
glColor3b(197, 96, 63);
drawPlanet(2, 0.2, 50, 12);
drawPlanet(1, 0.15, 30, 15);
glFlush();
}
int main(int argc, char** argv)
{
....
glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB | GLUT_DEPTH);
glEnable(GL_DEPTH_TEST);
....
}