我正在嘗試製作賽車遊戲,並且在屏幕上顯示多個視口時遇到問題。我希望在屏幕的右下角放置一個小型「迷你地圖」(這實際上是與主攝像機場景不同的視圖),但爲什麼,第二個視口不會出現,我所能看到的只是主相機的視圖。OpenGL上的多個視口
這裏如下我的代碼是:
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;
}
你在繪製第二個視口?我沒有看到任何實際繪製任何代碼的代碼。 – Tim
去這裏,有一個可下載的ViewPort例子。 http://zavie.free.fr/opengl/index.html.en#viewports – trumpetlicks
我沒有畫第二個視口,我只是改變相機的位置,所以它可以從上往上看地圖將看起來像一個小地圖(這就是我使用lookAt函數)。 – Imperian