【问题标题】:OpenGL window sizing rendering issueOpenGL窗口大小渲染问题
【发布时间】:2013-05-27 16:37:31
【问题描述】:

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

【问题讨论】:

标签: c++ opengl glut


【解决方案1】:

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

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

【讨论】:

    【解决方案2】:

    来自我的项目

    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)

    希望对你有帮助

    【讨论】:

      猜你喜欢
      • 2013-05-25
      • 1970-01-01
      • 2017-01-08
      • 2013-06-06
      • 2014-12-17
      • 1970-01-01
      • 1970-01-01
      • 2013-09-26
      • 1970-01-01
      相关资源
      最近更新 更多