如何在Qt应用程序中替换"gluOrtho2d"



我正在努力使我七年前写的一个程序起死回生。它都是用Qt编写的,并使用一些OpenGL在应用程序显示的图像上绘制一些帧线。问题是使用了"gluOrtho2D",但不再找到。我在想怎样才能绕过这个问题。下面是代码:

void MSContext::ResizePaint(int width, int height)
{
    // setup viewport, projection etc.:
    glViewport(0, 0, (GLint)width, (GLint)height);
    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    gluOrtho2D(0.0, (GLdouble) width, 0.0, (GLdouble) height);
    glMatrixMode(GL_MODELVIEW); 
    glClearColor(0.5, 0.5, 0.5, 1.0);
    glShadeModel(GL_FLAT);
    glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
    CreatePrintCropMarks();
}
void MSContext::CreatePrintCropMarks()
{
    GLuint print45CropId = openGLListMgr()->print45CropId();
    glNewList( print45CropId, GL_COMPILE);
    {
        qreal lineSize = 4.0;
        // Shrink down the canvas by 4 pixels so that the crop will show up
        const QRectF& viewPort = primaryCanvas()->imageView()->viewRectangle();
        QRectF shrunkingCanvas = viewPort.adjusted(lineSize, lineSize, -lineSize, -lineSize);
        QRectF print45Crop = GetCropRect(shrunkingCanvas, 5, 4);
        QRectF print57Crop = GetCropRect(print45Crop, 7, 5);
        glLineWidth(lineSize / 2);
        glLineStipple(1,0xFF00);
        DrawBox(print57Crop);
        glLineWidth(lineSize);
        glLineStipple(1,0xFFFF);
        DrawBox(print45Crop);
    }
    glEndList();
}

在我的脑海里,我想知道为什么我从来没有听说过这个函数…事实证明,在(老派的)OpenGL中有一个很好的替代方案。来自SGI GLU实现:

void GLAPIENTRY                                                   
gluOrtho2D(GLdouble left, GLdouble right, GLdouble bottom, GLdouble top)
{
    glOrtho(left, right, bottom, top, -1, 1); 
}

所以你可以写:

glOrtho(0.0, (GLdouble) width, 0.0, (GLdouble) height, -1, 1);

相关内容

  • 没有找到相关文章

最新更新