2013-05-27 235 views
0

当我创建一个新的GLUT/openGL程序时,窗口大小使得屏幕顶部+1和底部-1在x方向上,我想坐标匹配的像素大小窗口。我想这样做,因为当我重塑我的窗户时,项目被扭曲了。我正在寻找的是我应该阅读的函数的名称。OpenGL窗口大小渲染问题

+0

上调整大小,你需要调整由纵横比获得新的窗口大小和高度,这里是另一个帖子的一个很好的例子http://stackoverflow.com/questions/3267243/in-opengl-how-can-i-adjust-for-the-window-being-res- – Sherlock

回答

0

此功能是我的项目的一部分,它可以防止失真。

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

从我的项目

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)

希望它可以帮助