summaryrefslogtreecommitdiffstats
path: root/examples/opengl/hellowindow
diff options
context:
space:
mode:
Diffstat (limited to 'examples/opengl/hellowindow')
-rw-r--r--examples/opengl/hellowindow/hellowindow.cpp56
-rw-r--r--examples/opengl/hellowindow/hellowindow.h13
-rw-r--r--examples/opengl/hellowindow/main.cpp20
3 files changed, 38 insertions, 51 deletions
diff --git a/examples/opengl/hellowindow/hellowindow.cpp b/examples/opengl/hellowindow/hellowindow.cpp
index b5166abe50..b1140c4f1d 100644
--- a/examples/opengl/hellowindow/hellowindow.cpp
+++ b/examples/opengl/hellowindow/hellowindow.cpp
@@ -41,9 +41,6 @@
#include "hellowindow.h"
#include <QOpenGLContext>
-
-#include <QTimer>
-
#include <qmath.h>
Renderer::Renderer(const QSurfaceFormat &format, Renderer *share, QScreen *screen)
@@ -77,10 +74,8 @@ HelloWindow::HelloWindow(const QSharedPointer<Renderer> &renderer)
updateColor();
}
-void HelloWindow::exposeEvent(QExposeEvent *event)
+void HelloWindow::exposeEvent(QExposeEvent *)
{
- Q_UNUSED(event);
-
render();
if (!m_timer) {
@@ -109,10 +104,7 @@ void HelloWindow::updateColor()
};
m_color = colors[m_colorIndex];
-
- m_colorIndex++;
- if (m_colorIndex >= int(sizeof(colors) / sizeof(colors[0])))
- m_colorIndex = 0;
+ m_colorIndex = 1 - m_colorIndex;
}
void Renderer::render(QSurface *surface, const QColor &color, const QSize &viewSize)
@@ -171,31 +163,29 @@ void Renderer::initialize()
glClearColor(0.1f, 0.1f, 0.2f, 1.0f);
QOpenGLShader *vshader = new QOpenGLShader(QOpenGLShader::Vertex, this);
- const char *vsrc =
- "attribute highp vec4 vertex;\n"
- "attribute mediump vec3 normal;\n"
- "uniform mediump mat4 matrix;\n"
- "uniform lowp vec4 sourceColor;\n"
- "varying mediump vec4 color;\n"
- "void main(void)\n"
- "{\n"
- " vec3 toLight = normalize(vec3(0.0, 0.3, 1.0));\n"
- " float angle = max(dot(normal, toLight), 0.0);\n"
- " vec3 col = sourceColor.rgb;\n"
- " color = vec4(col * 0.2 + col * 0.8 * angle, 1.0);\n"
- " color = clamp(color, 0.0, 1.0);\n"
- " gl_Position = matrix * vertex;\n"
- "}\n";
- vshader->compileSourceCode(vsrc);
+ vshader->compileSourceCode(
+ "attribute highp vec4 vertex;"
+ "attribute mediump vec3 normal;"
+ "uniform mediump mat4 matrix;"
+ "uniform lowp vec4 sourceColor;"
+ "varying mediump vec4 color;"
+ "void main(void)"
+ "{"
+ " vec3 toLight = normalize(vec3(0.0, 0.3, 1.0));"
+ " float angle = max(dot(normal, toLight), 0.0);"
+ " vec3 col = sourceColor.rgb;"
+ " color = vec4(col * 0.2 + col * 0.8 * angle, 1.0);"
+ " color = clamp(color, 0.0, 1.0);"
+ " gl_Position = matrix * vertex;"
+ "}");
QOpenGLShader *fshader = new QOpenGLShader(QOpenGLShader::Fragment, this);
- const char *fsrc =
- "varying mediump vec4 color;\n"
- "void main(void)\n"
- "{\n"
- " gl_FragColor = color;\n"
- "}\n";
- fshader->compileSourceCode(fsrc);
+ fshader->compileSourceCode(
+ "varying mediump vec4 color;"
+ "void main(void)"
+ "{"
+ " gl_FragColor = color;"
+ "}");
m_program = new QOpenGLShaderProgram(this);
m_program->addShader(vshader);
diff --git a/examples/opengl/hellowindow/hellowindow.h b/examples/opengl/hellowindow/hellowindow.h
index adb85c1a6e..27cae4be7d 100644
--- a/examples/opengl/hellowindow/hellowindow.h
+++ b/examples/opengl/hellowindow/hellowindow.h
@@ -40,21 +40,15 @@
#include <QWindow>
-#include <QtGui/qopengl.h>
-#include <QtGui/qopenglshaderprogram.h>
-
#include <QColor>
-#include <QTime>
+#include <QOpenGLShaderProgram>
#include <QSharedPointer>
-
-QT_BEGIN_NAMESPACE
-class QOpenGLContext;
-class QTimer;
-QT_END_NAMESPACE
+#include <QTimer>
class Renderer : public QObject
{
Q_OBJECT
+
public:
explicit Renderer(const QSurfaceFormat &format, Renderer *share = 0, QScreen *screen = 0);
@@ -89,6 +83,7 @@ private:
class HelloWindow : public QWindow
{
Q_OBJECT
+
public:
explicit HelloWindow(const QSharedPointer<Renderer> &renderer);
diff --git a/examples/opengl/hellowindow/main.cpp b/examples/opengl/hellowindow/main.cpp
index 343160f755..e63b27d093 100644
--- a/examples/opengl/hellowindow/main.cpp
+++ b/examples/opengl/hellowindow/main.cpp
@@ -38,21 +38,22 @@
**
****************************************************************************/
-#include <QGuiApplication>
+#include "hellowindow.h"
+
#include <qpa/qplatformintegration.h>
#include <private/qguiapplication_p.h>
+
+#include <QGuiApplication>
#include <QScreen>
#include <QThread>
-#include "hellowindow.h"
-
-int main(int argc, char **argv)
+int main(int argc, char *argv[])
{
QGuiApplication app(argc, argv);
const bool multipleWindows =
QGuiApplicationPrivate::platformIntegration()->hasCapability(QPlatformIntegration::ThreadedOpenGL)
- && !QGuiApplication::arguments().contains(QLatin1String("--single"));
+ && !QGuiApplication::arguments().contains(QStringLiteral("--single"));
QScreen *screen = QGuiApplication::primaryScreen();
@@ -71,7 +72,7 @@ int main(int argc, char **argv)
HelloWindow *windowA = new HelloWindow(rendererA);
windowA->setGeometry(QRect(center, windowSize).translated(-windowSize.width() - delta / 2, 0));
- windowA->setTitle(QLatin1String("Thread A - Context A"));
+ windowA->setTitle(QStringLiteral("Thread A - Context A"));
windowA->setVisible(true);
windows.prepend(windowA);
@@ -85,13 +86,13 @@ int main(int argc, char **argv)
HelloWindow *windowB = new HelloWindow(rendererA);
windowB->setGeometry(QRect(center, windowSize).translated(delta / 2, 0));
- windowB->setTitle(QLatin1String("Thread A - Context A"));
+ windowB->setTitle(QStringLiteral("Thread A - Context A"));
windowB->setVisible(true);
windows.prepend(windowB);
HelloWindow *windowC = new HelloWindow(rendererB);
windowC->setGeometry(QRect(center, windowSize).translated(-windowSize.width() / 2, windowSize.height() + delta));
- windowC->setTitle(QLatin1String("Thread B - Context B"));
+ windowC->setTitle(QStringLiteral("Thread B - Context B"));
windowC->setVisible(true);
windows.prepend(windowC);
@@ -113,7 +114,7 @@ int main(int argc, char **argv)
window->setGeometry(QRect(center, windowSize).translated(-windowSize.width() / 2, -windowSize.height() / 2));
QChar id = QChar('B' + i);
- window->setTitle(QLatin1String("Thread ") + id + QLatin1String(" - Context ") + id);
+ window->setTitle(QStringLiteral("Thread ") + id + QStringLiteral(" - Context ") + id);
window->setVisible(true);
windows.prepend(window);
}
@@ -128,6 +129,7 @@ int main(int argc, char **argv)
for (int i = 0; i < renderThreads.size(); ++i)
renderThreads.at(i)->wait();
+
qDeleteAll(windows);
qDeleteAll(renderThreads);