diff --git a/src/ViewCube.cpp b/src/ViewCube.cpp index 0441602..1fb88b1 100644 --- a/src/ViewCube.cpp +++ b/src/ViewCube.cpp @@ -34,17 +34,31 @@ void ViewCube::initializeGL() setupBuffers(); } -void ViewCube::paintGL(QOpenGLShaderProgram* simpleShader, int simpleShaderColorLoc, const QMatrix4x4& viewMatrix, int width, int height) +void ViewCube::paintGL(QOpenGLShaderProgram* simpleShader, int simpleShaderColorLoc, const QMatrix4x4& viewMatrix, int width, int height, const QPoint& mousePos) { int viewCubeSize = 150 * QGuiApplication::primaryScreen()->devicePixelRatio(); glViewport(width - viewCubeSize, height - viewCubeSize, viewCubeSize, viewCubeSize); + + QRect viewCubeRect(width - viewCubeSize, 0, viewCubeSize, viewCubeSize); + QPoint physicalMousePos = mousePos * QGuiApplication::primaryScreen()->devicePixelRatio(); + + float opacity = 0.25f; + if (viewCubeRect.contains(physicalMousePos)) { + opacity = 1.0f; + } + + glEnable(GL_BLEND); + glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); + glClear(GL_DEPTH_BUFFER_BIT); QMatrix4x4 viewCubeProjection; viewCubeProjection.ortho(-2, 2, -2, 2, -10, 10); - drawViewCube(viewCubeProjection, viewMatrix); + drawViewCube(viewCubeProjection, viewMatrix, opacity); drawAxes(simpleShader, simpleShaderColorLoc, viewCubeProjection, viewMatrix); + + glDisable(GL_BLEND); } void ViewCube::createFaceTextures() @@ -146,7 +160,7 @@ void ViewCube::setupBuffers() m_axesVbo.release(); } -void ViewCube::drawViewCube(const QMatrix4x4& projection, const QMatrix4x4& view) +void ViewCube::drawViewCube(const QMatrix4x4& projection, const QMatrix4x4& view, float opacity) { if (!m_textureShaderProgram || !m_textureShaderProgram->isLinked()) return; @@ -155,6 +169,7 @@ void ViewCube::drawViewCube(const QMatrix4x4& projection, const QMatrix4x4& view m_textureShaderProgram->setUniformValue("projectionMatrix", projection); m_textureShaderProgram->setUniformValue("modelViewMatrix", view); m_textureShaderProgram->setUniformValue("texture_diffuse1", 0); + m_textureShaderProgram->setUniformValue("opacity", opacity); QOpenGLVertexArrayObject::Binder vaoBinder(&m_cubeVao); for (int i = 0; i < 6; ++i) { diff --git a/src/ViewCube.h b/src/ViewCube.h index c003cd1..f635ae8 100644 --- a/src/ViewCube.h +++ b/src/ViewCube.h @@ -5,6 +5,7 @@ #include #include #include +#include class QOpenGLShaderProgram; class QOpenGLTexture; @@ -16,13 +17,13 @@ public: ~ViewCube(); void initializeGL(); - void paintGL(QOpenGLShaderProgram* simpleShader, int simpleShaderColorLoc, const QMatrix4x4& viewMatrix, int width, int height); + void paintGL(QOpenGLShaderProgram* simpleShader, int simpleShaderColorLoc, const QMatrix4x4& viewMatrix, int width, int height, const QPoint& mousePos); private: void createFaceTextures(); void initShaders(); void setupBuffers(); - void drawViewCube(const QMatrix4x4& projection, const QMatrix4x4& view); + void drawViewCube(const QMatrix4x4& projection, const QMatrix4x4& view, float opacity); void drawAxes(QOpenGLShaderProgram* simpleShader, int colorLoc, const QMatrix4x4& projection, const QMatrix4x4& view); QOpenGLTexture* m_faceTextures[6]; diff --git a/src/ViewportWidget.cpp b/src/ViewportWidget.cpp index 2a9d0c9..e42af83 100644 --- a/src/ViewportWidget.cpp +++ b/src/ViewportWidget.cpp @@ -191,7 +191,7 @@ void ViewportWidget::paintGL() QMatrix4x4 viewCubeModel; viewCubeModel.rotate(m_camera->xRotation() / 16.0f, 1, 0, 0); viewCubeModel.rotate(m_camera->yRotation() / 16.0f, 0, 1, 0); - m_viewCube->paintGL(m_shaderProgram, m_colorLoc, viewCubeModel, width() * retinaScale, height() * retinaScale); + m_viewCube->paintGL(m_shaderProgram, m_colorLoc, viewCubeModel, width() * retinaScale, height() * retinaScale, m_currentMousePos); glViewport(0, 0, width() * retinaScale, height() * retinaScale); glDisable(GL_DEPTH_TEST); diff --git a/src/shaders/texture.frag b/src/shaders/texture.frag index d8ef8cd..82bacbc 100644 --- a/src/shaders/texture.frag +++ b/src/shaders/texture.frag @@ -5,8 +5,10 @@ out vec4 FragColor; in vec2 TexCoord; uniform sampler2D texture_diffuse1; +uniform float opacity; void main() { - FragColor = texture(texture_diffuse1, TexCoord); + vec4 texColor = texture(texture_diffuse1, TexCoord); + FragColor = vec4(texColor.rgb, texColor.a * opacity); }