gpt4 book ai didi

c++ - 多视口(viewport)问题

转载 作者:太空宇宙 更新时间:2023-11-04 12:21:54 26 4
gpt4 key购买 nike

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

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

最佳答案

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

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

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com