[英]OpenGL window sizing rendering issue
当我创建一个新的GLUT / openGL程序时,窗口大小将使屏幕的顶部在x方向上+1,而底部-1在x方向上,我希望坐标与窗口的像素大小匹配。 我想这样做是因为当我调整窗口形状时,该项目会变形。 我要寻找的只是应该阅读的函数的名称。
此功能是我的项目的一部分,它可以防止变形。
GLvoid myWidget::resizeGL(GLint width, GLint height) {
glViewport(0, 0, width, height);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(45.0, //The camera angle
(double)width / height,//The width-to-height ratio
1.0, //The near z clipping coordinate
100.0); //The far z clipping coordinate
glMatrixMode(GL_MODELVIEW);
}
从我的项目
void GLWidget::resizeGL(int width, int height)
{
if (height==0) // Prevent A Divide By Zero By
{
height=1; // Making Height Equal One
}
w_screen=width; // GLWidget members (u don't need these)
h_screen=height; //
float ratio=width/height;
glViewport(0,0,width,height); // Reset The Current Viewport
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(fov,ratio,0.1f,200.0f);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
}
在我的情况下,fov是公共成员(初始化为45)
希望能帮助到你
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.