多视口问题

时间:2010-12-23 01:49:15

标签: c++ opengl

我正在设置所以我可以在一个或四个视口之间切换但是我遇到了一些麻烦。

在我的右下方视口中,我有相机视图,我可以切换到全视图的相机。其他三个视口正在使用固定位置,但右下方视口在y刻度上压缩,x刻度上的图片的一半缺失。

void display(int what)
{
    if(what==5){glViewport(0, 0, w, h);
    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();
    ca.lookAt();}

    if(what==1){glViewport(0, 0, w/2, h/2);
    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();
    gluLookAt(75,15,-5,0,5,-5,0,1,0);}

    if(what==2){glViewport(w/2, h/2, w, h);
    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();
    gluLookAt(0,110,0,20,0,20,1,0,0);}

    if(what==3){glViewport(w/2, 0, w, h/2);
    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    gluPerspective(45.0f, float(320) / float(240), 0.1f, 100.0f); 
    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();
    ca.lookAt();}

    if(what==4){glViewport(0, h/2, w/2, h);
    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();
    gluLookAt(185,75,25,0,28,0,0,1,0);}


    //glMatrixMode(GL_MODELVIEW);
    //glLoadIdentity();
    ////gluLookAt(cos(shared.time) * shared.distance, 10, sin(shared.time) * shared.distance, 0, 0, 0, 0, 1, 0);   // Roterar kameran kring origo genom att skapa en ny vymatris varje bildruta
    ////ca.orbitYaw(0.05);
    //ca.lookAt();

    glClearColor(0, 0, 0, 1);
    glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
    drawScene();
    drawCamera();
    glutSwapBuffers();
}

void viewport(){
glEnable(GL_SCISSOR_TEST);

    if(!divided_view_port)
    {
    glViewport(0, 0, w, h);
    glScissor(0,0,640,480);
    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    gluPerspective(45.0f, w / h, 0.1f, 100.0f);
    display(5);
    }

else
{
    ////////////////////// bottom left - working
    glViewport(0, 0, w/2, h/2);
    glScissor(0,0,w/2,h/2);
    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    gluPerspective(45.0f, w / h, 0.1f, 300.0f);
    display(1);
    //////////////////////


    ////////////////////// top right - working
    glViewport(w/2, h/2, w, h);
    glScissor(w/2,h/2,w,h);
    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    gluPerspective(45.0f, w / h, 0.1f, 300.0f);
    display(2);
    //////////////////////

    ////////////////////// bottom right -working
    glViewport(w/2, 0, w, h/2);
    glScissor(w/2,0,w,h/2);
    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    gluPerspective(45.0f, w / h, 0.1f, 300.0f);
    display(3);
    ////////////////////////

    ////////////////////////// top left
    glViewport(0, h/2, w/2, h);
    glScissor(0,h/2,w/2,h);
    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    gluPerspective(45.0f, w / h, 0.1f, 300.0f);
    display(4);
    ///////////////////////////
}

glDisable(GL_SCISSOR_TEST);
glMatrixMode(GL_MODELVIEW);
}

1 个答案:

答案 0 :(得分:1)

glViewport()获取偏移量和尺寸

您的代码似乎正在传递左下角和右上角坐标。

试试这些:

glViewport(   0,  0, w/2, h/2);  // lower-left
glViewport(w/2,   0, w/2, h/2);  // lower-right
glViewport(w/2, h/2, w/2, h/2);  // upper-right
glViewport(  0, h/2, w/2, h/2);  // upper-left