我正在尝试制作赛车游戏,但在屏幕上显示多个视口时遇到问题。我希望在屏幕的右下角放一个小的“迷你地图”(这实际上是与主相机场景不同的视图)但是不知何故,第二个视口没有出现,我所能看到的只是主摄像头的视图。
下面是我的代码:
void mainRender() {
updateState();
setViewport(0, windowWidth, 0, windowHeight);
setWindow();
renderScene();
setViewport(0, windowWidth, 0, windowHeight/2);
renderScene();
gluLookAt(0,88,0,
1 ,0 ,0,
0.0,1.0,0.0);
Sleep(30);
}
void setWindow() {
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(45.0f,(GLfloat)windowWidth/(GLfloat)windowHeight,0.1f, 100.0f);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
gluLookAt(posX,posY + 0.025 * std::abs(sin(headPosAux*PI/180)),posZ,
posX + sin(roty*PI/180),posY + 0.025 * std::abs(sin(headPosAux*PI/180)) + cos(rotx*PI/180),posZ -cos(roty*PI/180),
0.0,1.0,0.0);
}
void setViewport(GLint left, GLint right, GLint bottom, GLint top){
glViewport(left, bottom, right - left, top - bottom);
}
int main(int argc, char **argv) {
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_SINGLE | GLUT_RGBA | GLUT_DEPTH);
glutInitWindowSize(windowWidth,windowHeight);
glutInitWindowPosition(windowXPos,windowYPos);
/**
Store main window id so that glui can send it redisplay events
*/
mainWindowId = glutCreateWindow("TF");
glutDisplayFunc(mainRender);
glutReshapeFunc(onWindowReshape);
/**
Register keyboard events handlers
*/
glutKeyboardFunc(onKeyDown);
glutKeyboardUpFunc(onKeyUp);
mainInit();
glutMainLoop();
return 0;
}