Try this
void GLWidget::resizeGL(int width, int height)
{
glViewport(0, 0, width, height);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluOrtho2D(0.0, width, 0.0, height);
}
void GLWidget::resizeGL(int width, int height)
{
glViewport(0, 0, width, height);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluOrtho2D(0.0, width, 0.0, height);
}
To copy to clipboard, switch view to plain text mode
void GLWidget::paintGL()
{
................
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glTranslatef(width() / 2.0f, height() / 2.0f, 0.0f);
glScalef(scaleFactor, scaleFactor, 0.0f);
glTranslatef(-imageWidth / 2.0f, -imageHeight / 2.0f, 0.0f);
glBegin(GL_QUADS);
glTexCoord2f(0.0f, 0.0f); glVertex2f(0.0f, 0.0f);
glTexCoord2f(1.0f, 0.0f); glVertex2f(imageWidth, 0.0f);
glTexCoord2f(1.0f, 1.0f); glVertex2f(imageWidth, imageHeight);
glTexCoord2f(0.0f, 1.0f); glVertex2f(0.0f, imageHeight);
glEnd();
}
void GLWidget::paintGL()
{
................
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glTranslatef(width() / 2.0f, height() / 2.0f, 0.0f);
glScalef(scaleFactor, scaleFactor, 0.0f);
glTranslatef(-imageWidth / 2.0f, -imageHeight / 2.0f, 0.0f);
glBegin(GL_QUADS);
glTexCoord2f(0.0f, 0.0f); glVertex2f(0.0f, 0.0f);
glTexCoord2f(1.0f, 0.0f); glVertex2f(imageWidth, 0.0f);
glTexCoord2f(1.0f, 1.0f); glVertex2f(imageWidth, imageHeight);
glTexCoord2f(0.0f, 1.0f); glVertex2f(0.0f, imageHeight);
glEnd();
}
To copy to clipboard, switch view to plain text mode
You must know the basics of matrix and coordinate transformations if you want to understand above code.
Bookmarks