From af94ecd541424dded04884efdd88441fb5e27d62 Mon Sep 17 00:00:00 2001 From: Anakin Date: Fri, 20 Jan 2017 16:39:17 +0100 Subject: [PATCH] change background when the light is on --- QtMeshViewer/Header/OglViewerWidget.h | 2 ++ QtMeshViewer/Source/MainWindow.cpp | 1 + QtMeshViewer/Source/OglViewerWidget.cpp | 12 +++++++++--- 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/QtMeshViewer/Header/OglViewerWidget.h b/QtMeshViewer/Header/OglViewerWidget.h index fd1e6a7..b6ccdb5 100644 --- a/QtMeshViewer/Header/OglViewerWidget.h +++ b/QtMeshViewer/Header/OglViewerWidget.h @@ -44,6 +44,8 @@ private: float ambientCoefficient = 0.005f; } m_light; + QVector4D m_backgroundColor = {0.5f, 0.8f, 1.0f, 1.0f}; + QOpenGLShaderProgram m_program; GeometryEngine *m_dataEngine; diff --git a/QtMeshViewer/Source/MainWindow.cpp b/QtMeshViewer/Source/MainWindow.cpp index c8e0f13..beafc2a 100644 --- a/QtMeshViewer/Source/MainWindow.cpp +++ b/QtMeshViewer/Source/MainWindow.cpp @@ -188,6 +188,7 @@ void MainWindow::setFileInfo(QString name, QVector* materials, int ver int count(0); //TODO: mark not opened textures + //TODO: add more information for (auto& it : *materials) { m_fileInfo += "Material "; diff --git a/QtMeshViewer/Source/OglViewerWidget.cpp b/QtMeshViewer/Source/OglViewerWidget.cpp index 5985ab4..d74d5a9 100644 --- a/QtMeshViewer/Source/OglViewerWidget.cpp +++ b/QtMeshViewer/Source/OglViewerWidget.cpp @@ -184,7 +184,7 @@ void OglViewerWidget::initializeGL() { initializeOpenGLFunctions(); - glClearColor(0.5000f, 0.8000f, 1.0000f, 0.0000f); + //glClearColor(0.5000f, 0.8000f, 1.0000f, 0.0000f); initShaders(); @@ -222,6 +222,12 @@ void OglViewerWidget::paintGL() // Clear color and depth buffer glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); + if (m_backgroundColor[3] == 1.0) + { + glClearColor(m_backgroundColor[0], m_backgroundColor[1], m_backgroundColor[2], 0.0000f); + m_backgroundColor[3] = 0.0; + } + // Calculate model view transformation QMatrix4x4 view; view.translate(m_translation); @@ -330,13 +336,13 @@ void OglViewerWidget::toggleLight() if (m_lightOn) { - glClearColor(m_light.intensities.x() / 100, m_light.intensities.y() / 100, m_light.intensities.z() / 100, 0.0000f); + m_backgroundColor = { m_light.intensities.x() / 100, m_light.intensities.y() / 100, m_light.intensities.z() / 100, 1.0 }; updateLightPosition(); } else { - glClearColor(0.5000f, 0.8000f, 1.0000f, 0.0000f); + m_backgroundColor = { 0.5f, 0.8f, 1.0f, 1.0 }; } update();