diff options
author | Samuel Rødal <sroedal@trolltech.com> | 2010-02-08 15:22:21 +0100 |
---|---|---|
committer | Samuel Rødal <sroedal@trolltech.com> | 2010-02-08 15:22:21 +0100 |
commit | 1bddf1bc1eb21ff484853997f46ae023e4a4d734 (patch) | |
tree | 9ec899550b21e6b9ea5a82457273a6e54017b1f7 | |
parent | 1c75826d9bf09da1ba3ef968fad31ac51becb343 (diff) |
Updated to support OpenGL 2 paint engine.
-rw-r--r-- | openglscene.cpp | 57 |
1 files changed, 31 insertions, 26 deletions
diff --git a/openglscene.cpp b/openglscene.cpp index 38dbd5a..75687c8 100644 --- a/openglscene.cpp +++ b/openglscene.cpp @@ -97,47 +97,52 @@ OpenGLScene::OpenGLScene() void OpenGLScene::drawBackground(QPainter *painter, const QRectF &) { - if (painter->paintEngine()->type() != QPaintEngine::OpenGL) { + if (painter->paintEngine()->type() != QPaintEngine::OpenGL + && painter->paintEngine()->type() != QPaintEngine::OpenGL2) + { qWarning("OpenGLScene: drawBackground needs a QGLWidget to be set as viewport on the graphics view"); return; } + painter->beginNativePainting(); + glClearColor(m_backgroundColor.redF(), m_backgroundColor.greenF(), m_backgroundColor.blueF(), 1.0f); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); - if (!m_model) - return; + if (m_model) { + glMatrixMode(GL_PROJECTION); + glPushMatrix(); + glLoadIdentity(); + gluPerspective(70, width() / height(), 0.01, 1000); - glMatrixMode(GL_PROJECTION); - glPushMatrix(); - glLoadIdentity(); - gluPerspective(70, width() / height(), 0.01, 1000); + glMatrixMode(GL_MODELVIEW); + glPushMatrix(); + glLoadIdentity(); - glMatrixMode(GL_MODELVIEW); - glPushMatrix(); - glLoadIdentity(); + const float pos[] = { m_lightItem->x() - width() / 2, height() / 2 - m_lightItem->y(), 512, 0 }; + glLightfv(GL_LIGHT0, GL_POSITION, pos); + glColor4f(m_modelColor.redF(), m_modelColor.greenF(), m_modelColor.blueF(), 1.0f); - const float pos[] = { m_lightItem->x() - width() / 2, height() / 2 - m_lightItem->y(), 512, 0 }; - glLightfv(GL_LIGHT0, GL_POSITION, pos); - glColor4f(m_modelColor.redF(), m_modelColor.greenF(), m_modelColor.blueF(), 1.0f); + const int delta = m_time.elapsed() - m_lastTime; + m_rotation += m_angularMomentum * (delta / 1000.0); + m_lastTime += delta; - const int delta = m_time.elapsed() - m_lastTime; - m_rotation += m_angularMomentum * (delta / 1000.0); - m_lastTime += delta; + glTranslatef(0, 0, -m_distance); + glRotatef(m_rotation.x, 1, 0, 0); + glRotatef(m_rotation.y, 0, 1, 0); + glRotatef(m_rotation.z, 0, 0, 1); - glTranslatef(0, 0, -m_distance); - glRotatef(m_rotation.x, 1, 0, 0); - glRotatef(m_rotation.y, 0, 1, 0); - glRotatef(m_rotation.z, 0, 0, 1); + glEnable(GL_MULTISAMPLE); + m_model->render(m_wireframeEnabled, m_normalsEnabled); + glDisable(GL_MULTISAMPLE); - glEnable(GL_MULTISAMPLE); - m_model->render(m_wireframeEnabled, m_normalsEnabled); - glDisable(GL_MULTISAMPLE); + glPopMatrix(); - glPopMatrix(); + glMatrixMode(GL_PROJECTION); + glPopMatrix(); + } - glMatrixMode(GL_PROJECTION); - glPopMatrix(); + painter->endNativePainting(); QTimer::singleShot(20, this, SLOT(update())); } |