c++ - OpenGL 上的多个视口(viewport)

标签 c++ opengl viewport

我正在尝试制作一款赛车游戏,但在屏幕上显示多个视口(viewport)时遇到了问题。我想在屏幕的右下角放一个小的“迷你 map ”(这实际上是与主相机场景不同的 View )但不知何故,第二个视口(viewport)没有出现,我只能看到主摄像头的 View 。

下面是我的代码:

    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;
    }

最佳答案

I don't draw in the second viewport, I just change the position of the camera, so it can look to the map from upwards and it will look like a minimap (that's what I use the lookAt function for).

我认为您对 opengl 的工作原理有一些严重的误解。只是改变 gluLookAt 不会做任何事情。如果您想从不同的角度查看场景,则必须在更改视口(viewport)后重新绘制整个场景。如果你想显示一个小 map ,那么你应该正常绘制整个场景,将视口(viewport)设置为小 map ,设置俯视相机,然后再次绘制整个场景。

关于c++ - OpenGL 上的多个视口(viewport),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11161699/

相关文章:

c++ - 尝试将纹理映射到 GLSL 中的三角形时发生访问冲突

html - 使网站适合窗口的视口(viewport),所有手机

html - 如何让 bootstrap 网站失去 786px 宽度内的所有响应功能?

java - 如何向 JScrollPane 视口(viewport)添加渐变?

c++ - 方向梯度直方图

c++ - 通过另一个 vector 推力访问 vector 元素

c++ - 生成控制台窗口而不锁定应用程序

C++ 带括号的取消引用(带迭代器)

qt - 用于渲染 2D 文本的 paintGL() 中着色器和 QPainter 之间的冲突

c++ - glPushMatrix() 和 glPopMatrix() 如何保持场景不变?