【问题标题】:Multiple viewport problem多视口问题
【发布时间】:2010-12-23 01:49:14
【问题描述】:

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

在我的右下视口中,我看到了相机视图,我可以切换到全视图。其他三个视口使用固定位置,但右下视口在 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);
}

【问题讨论】:

  • 您没有使用正确的 C++ 语法,也没有发布问题的图片。
  • 您的多个glViewport() 电话是怎么回事?你在viewport() 中有电话,然后在display() 中有更多电话,清除了viewport() 可能设置的任何内容。

标签: c++ opengl


【解决方案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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-01-10
    • 1970-01-01
    • 1970-01-01
    • 2011-08-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多