如何更换' gluOrtho2d'在Qt应用程序中

时间:2016-09-26 16:39:36

标签: c++ qt opengl opengl-2.0

我正在努力恢复我七年前写的一个项目。它全部用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();
}

1 个答案:

答案 0 :(得分:2)

在我的脑后,我想知道为什么我从来没有听说过这个功能......原来在(老派)OpenGL中有一个很好的选择。来自SGI GLU implementation

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