I am working on bring back to life a program I wrote seven years ago. It is all written in Qt and uses some OpenGL to draw some frame lines on an image that the application is displaying. The problem is that 'gluOrtho2D' is used but is no longer found. I am wondering how I can get around the problem. Here is the code:
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();
}
At the back of my head, I was wondering why I'd never heard of this function... turns out there is a fine alternative in (old-school) OpenGL. From the SGI GLU implementation:
void GLAPIENTRY
gluOrtho2D(GLdouble left, GLdouble right, GLdouble bottom, GLdouble top)
{
glOrtho(left, right, bottom, top, -1, 1);
}
So you can write:
glOrtho(0.0, (GLdouble) width, 0.0, (GLdouble) height, -1, 1);