summaryrefslogtreecommitdiffstats
path: root/examples/opengl/qopenglwindow
diff options
context:
space:
mode:
Diffstat (limited to 'examples/opengl/qopenglwindow')
-rw-r--r--examples/opengl/qopenglwindow/background.frag13
-rw-r--r--examples/opengl/qopenglwindow/background_renderer.cpp22
-rw-r--r--examples/opengl/qopenglwindow/background_renderer.h8
-rw-r--r--examples/opengl/qopenglwindow/main.cpp10
4 files changed, 29 insertions, 24 deletions
diff --git a/examples/opengl/qopenglwindow/background.frag b/examples/opengl/qopenglwindow/background.frag
index 572c941f08..eecb6d3120 100644
--- a/examples/opengl/qopenglwindow/background.frag
+++ b/examples/opengl/qopenglwindow/background.frag
@@ -1,3 +1,6 @@
+#define M_PI 3.1415926535897932384626433832795
+#define SPEED 10000.0
+
uniform int currentTime;
uniform highp vec2 windowSize;
@@ -8,18 +11,20 @@ highp float noise(highp vec2 co)
highp float curvSpeed()
{
- return mod(float(currentTime), 1000000.0) / 500.0;
+ return (mod(float(currentTime), SPEED) / SPEED) * (2.0 * M_PI);
}
-highp float curv()
+highp float curv(int curvCount)
{
- return 1.0 - abs((gl_FragCoord.y / (windowSize.y / 10.0) - 5.0) - sin((gl_FragCoord.x / (windowSize.x/20.0)) - curvSpeed()));
+ highp float curv_y = 0.1 *(cos((gl_FragCoord.x / windowSize.x) * (float(curvCount * 2) * M_PI) - curvSpeed())) + 0.5;
+ highp float frag_y = gl_FragCoord.y / windowSize.y;
+ return 1.0 - abs(curv_y - frag_y);
}
void main()
{
highp float coordNoise = noise(gl_FragCoord.xy);
- highp float proximity = smoothstep(0.5, 1.0, (curv() + 1.0) * (coordNoise ));
+ highp float proximity = smoothstep(0.85, 1.0, (curv(6) + 1.0) * (coordNoise ));
highp vec3 color = vec3(coordNoise) * proximity;
gl_FragColor = vec4(color, 1.0);
}
diff --git a/examples/opengl/qopenglwindow/background_renderer.cpp b/examples/opengl/qopenglwindow/background_renderer.cpp
index 2c830ac13c..bf42ffff8a 100644
--- a/examples/opengl/qopenglwindow/background_renderer.cpp
+++ b/examples/opengl/qopenglwindow/background_renderer.cpp
@@ -1,7 +1,7 @@
/****************************************************************************
**
-** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
-** Contact: http://www.qt-project.org/legal
+** Copyright (C) 2015 The Qt Company Ltd.
+** Contact: http://www.qt.io/licensing/
**
** This file is part of the examples of the Qt Toolkit.
**
@@ -17,8 +17,8 @@
** notice, this list of conditions and the following disclaimer in
** the documentation and/or other materials provided with the
** distribution.
-** * Neither the name of Digia Plc and its Subsidiary(-ies) nor the names
-** of its contributors may be used to endorse or promote products derived
+** * Neither the name of The Qt Company Ltd nor the names of its
+** contributors may be used to endorse or promote products derived
** from this software without specific prior written permission.
**
**
@@ -75,8 +75,8 @@ FragmentToy::FragmentToy(const QString &fragmentSource, QObject *parent)
m_fragment_file_last_modified = info.lastModified();
m_fragment_file = fragmentSource;
#ifndef QT_NO_FILESYSTEMWATCHER
- m_watcher.addPath(info.canonicalFilePath());
- QObject::connect(&m_watcher, &QFileSystemWatcher::fileChanged, this, &FragmentToy::fileChanged);
+ m_watcher.addPath(info.canonicalPath());
+ QObject::connect(&m_watcher, &QFileSystemWatcher::directoryChanged, this, &FragmentToy::fileChanged);
#endif
}
}
@@ -94,7 +94,7 @@ void FragmentToy::draw(const QSize &windowSize)
if (!m_vao.isCreated())
m_vao.create();
- m_vao.bind();
+ QOpenGLVertexArrayObject::Binder binder(&m_vao);
if (!m_vertex_buffer.isCreated()) {
m_vertex_buffer.create();
@@ -115,7 +115,7 @@ void FragmentToy::draw(const QSize &windowSize)
}
}
- if (!m_fragment_shader) {
+ if (!m_fragment_shader && m_recompile_shaders) {
QByteArray data;
if (m_fragment_file.size()) {
QFile file(m_fragment_file);
@@ -160,6 +160,9 @@ void FragmentToy::draw(const QSize &windowSize)
}
+ if (!m_program->isLinked())
+ return;
+
m_program->bind();
m_vertex_buffer.bind();
@@ -167,15 +170,12 @@ void FragmentToy::draw(const QSize &windowSize)
m_program->enableAttributeArray("vertexCoord");
m_vertex_buffer.release();
- float radiens = (QTime::currentTime().msecsSinceStartOfDay() / 60) / (2 * M_PI);
m_program->setUniformValue("currentTime", (uint) QDateTime::currentDateTime().toMSecsSinceEpoch());
- m_program->setUniformValue("radiens", radiens);
m_program->setUniformValue("windowSize", windowSize);
QOpenGLContext::currentContext()->functions()->glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
m_program->release();
- m_vao.release();
}
void FragmentToy::fileChanged(const QString &path)
diff --git a/examples/opengl/qopenglwindow/background_renderer.h b/examples/opengl/qopenglwindow/background_renderer.h
index 3759de478c..111d68977b 100644
--- a/examples/opengl/qopenglwindow/background_renderer.h
+++ b/examples/opengl/qopenglwindow/background_renderer.h
@@ -1,7 +1,7 @@
/****************************************************************************
**
-** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
-** Contact: http://www.qt-project.org/legal
+** Copyright (C) 2015 The Qt Company Ltd.
+** Contact: http://www.qt.io/licensing/
**
** This file is part of the examples of the Qt Toolkit.
**
@@ -17,8 +17,8 @@
** notice, this list of conditions and the following disclaimer in
** the documentation and/or other materials provided with the
** distribution.
-** * Neither the name of Digia Plc and its Subsidiary(-ies) nor the names
-** of its contributors may be used to endorse or promote products derived
+** * Neither the name of The Qt Company Ltd nor the names of its
+** contributors may be used to endorse or promote products derived
** from this software without specific prior written permission.
**
**
diff --git a/examples/opengl/qopenglwindow/main.cpp b/examples/opengl/qopenglwindow/main.cpp
index bf95d09ecd..123bebbe2a 100644
--- a/examples/opengl/qopenglwindow/main.cpp
+++ b/examples/opengl/qopenglwindow/main.cpp
@@ -1,7 +1,7 @@
/****************************************************************************
**
-** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
-** Contact: http://www.qt-project.org/legal
+** Copyright (C) 2015 The Qt Company Ltd.
+** Contact: http://www.qt.io/licensing/
**
** This file is part of the examples of the Qt Toolkit.
**
@@ -17,8 +17,8 @@
** notice, this list of conditions and the following disclaimer in
** the documentation and/or other materials provided with the
** distribution.
-** * Neither the name of Digia Plc and its Subsidiary(-ies) nor the names
-** of its contributors may be used to endorse or promote products derived
+** * Neither the name of The Qt Company Ltd nor the names of its
+** contributors may be used to endorse or promote products derived
** from this software without specific prior written permission.
**
**
@@ -97,7 +97,7 @@ private:
// typical in pure QWindow-based applications.
OpenGLWindow::OpenGLWindow()
: QOpenGLWindow(QOpenGLWindow::NoPartialUpdate)
- , m_fragment_toy("background.frag")
+ , m_fragment_toy("./background.frag")
, m_text_layout("The triangle and this text is rendered with QPainter")
, m_animate(true)
{