我在 (0,0) 处有一辆汽车,并设置了一些障碍,但现在我主要关心的是从 glPerspective 切换到 glOrtho,反之亦然。当我从透视切换到正交时,我得到的只是黑屏。
void myinit(){
glClearColor(0.0,0.0,0.0,0.0);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(60,ww/wh,1,100);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
gluLookAt(-5,5,3,backcarx,topcarx,0,0,0,1);
}
void menu(int id){
/*menu selects if you want to view it in ortho or perspective*/
if(id == 1){
glClear(GL_DEPTH_BUFFER_BIT);
glViewport(0,0,ww,wh);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(-2,100,-2,100,-1,1);
glMatrixMode(GL_MODELVIEW);
glutPostRedisplay();
}
if(id == 2){
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(60,ww/wh,1,100);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
viewx = backcarx - 10;
viewy = backcary - 10;
gluLookAt(viewx,viewy,viewz,backcarx,topcarx,0,0,0,1);
}
}
我已经尝试使用清除深度缓冲区,但仍然无法正常工作。