{
painter.setPen(Qt::NoPen);
painter.setBrush(gradient);
painter.drawRect(rect()); //paint the background with linear gradient
painter.end();
makeCurrent();
glMatrixMode(GL_MODELVIEW);
glPushMatrix();
glShadeModel(GL_SMOOTH);
glEnable(GL_DEPTH_TEST);
glEnable(GL_CULL_FACE);
glEnable(GL_LIGHTING);
glEnable(GL_LIGHT0);
glEnable(GL_MULTISAMPLE);
static GLfloat lightPosition[4] = { 0.5, 5.0, 7.0, 1.0 };
glLightfv(GL_LIGHT0, GL_POSITION, lightPosition);
setupViewport(width(), height());
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glLoadIdentity();
glTranslatef(0.0, 0.0, -10.0);
glRotatef(xRot / 16.0, 1.0, 0.0, 0.0);
glRotatef(yRot / 16.0, 0.0, 1.0, 0.0);
glRotatef(zRot / 16.0, 0.0, 0.0, 1.0);
glPushAttrib(GL_ALL_ATTRIB_BITS);
qglColor
(QColor(255,
239,
191));
glBegin(GL_TRIANGLES); //draw 2 random triangles to test
glVertex3f(+0.3, +0.3, -0.3);
glVertex3f(-0.3, +0.3, -0.3);
glVertex3f(+0.3, -0.3, -0.3);
glVertex3f(-0.3, -0.3, -0.3);
glVertex3f(+0.3, -0.3, +0.3);
glVertex3f(-0.3, -0.3, +0.3);
glEnd();
glPopAttrib();
glShadeModel(GL_FLAT);
glDisable(GL_CULL_FACE);
glDisable(GL_DEPTH_TEST);
glDisable(GL_LIGHTING);
glMatrixMode(GL_MODELVIEW);
glPopMatrix();
}
void GLWidget::paintEvent(QPaintEvent *event)
{
QPainter painter(this);
painter.setPen(Qt::NoPen);
painter.setBrush(gradient);
painter.drawRect(rect()); //paint the background with linear gradient
painter.end();
makeCurrent();
glMatrixMode(GL_MODELVIEW);
glPushMatrix();
glShadeModel(GL_SMOOTH);
glEnable(GL_DEPTH_TEST);
glEnable(GL_CULL_FACE);
glEnable(GL_LIGHTING);
glEnable(GL_LIGHT0);
glEnable(GL_MULTISAMPLE);
static GLfloat lightPosition[4] = { 0.5, 5.0, 7.0, 1.0 };
glLightfv(GL_LIGHT0, GL_POSITION, lightPosition);
setupViewport(width(), height());
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glLoadIdentity();
glTranslatef(0.0, 0.0, -10.0);
glRotatef(xRot / 16.0, 1.0, 0.0, 0.0);
glRotatef(yRot / 16.0, 0.0, 1.0, 0.0);
glRotatef(zRot / 16.0, 0.0, 0.0, 1.0);
glPushAttrib(GL_ALL_ATTRIB_BITS);
qglColor(QColor(255, 239, 191));
glBegin(GL_TRIANGLES); //draw 2 random triangles to test
glVertex3f(+0.3, +0.3, -0.3);
glVertex3f(-0.3, +0.3, -0.3);
glVertex3f(+0.3, -0.3, -0.3);
glVertex3f(-0.3, -0.3, -0.3);
glVertex3f(+0.3, -0.3, +0.3);
glVertex3f(-0.3, -0.3, +0.3);
glEnd();
glPopAttrib();
glShadeModel(GL_FLAT);
glDisable(GL_CULL_FACE);
glDisable(GL_DEPTH_TEST);
glDisable(GL_LIGHTING);
glMatrixMode(GL_MODELVIEW);
glPopMatrix();
}
To copy to clipboard, switch view to plain text mode
Bookmarks