summaryrefslogtreecommitdiffstats
path: root/examples/opengl
diff options
context:
space:
mode:
Diffstat (limited to 'examples/opengl')
-rw-r--r--examples/opengl/2dpainting/2dpainting.pro2
-rw-r--r--examples/opengl/2dpainting/CMakeLists.txt43
-rw-r--r--examples/opengl/2dpainting/glwidget.cpp51
-rw-r--r--examples/opengl/2dpainting/glwidget.h51
-rw-r--r--examples/opengl/2dpainting/helper.cpp51
-rw-r--r--examples/opengl/2dpainting/helper.h51
-rw-r--r--examples/opengl/2dpainting/main.cpp51
-rw-r--r--examples/opengl/2dpainting/widget.cpp51
-rw-r--r--examples/opengl/2dpainting/widget.h51
-rw-r--r--examples/opengl/2dpainting/window.cpp51
-rw-r--r--examples/opengl/2dpainting/window.h51
-rw-r--r--examples/opengl/CMakeLists.txt12
-rw-r--r--examples/opengl/computegles31/Qt-logo-medium.pngbin24817 -> 0 bytes
-rw-r--r--examples/opengl/computegles31/computegles31.pro11
-rw-r--r--examples/opengl/computegles31/computegles31.qrc5
-rw-r--r--examples/opengl/computegles31/glwindow.cpp419
-rw-r--r--examples/opengl/computegles31/glwindow.h110
-rw-r--r--examples/opengl/computegles31/main.cpp148
-rw-r--r--examples/opengl/contextinfo/contextinfo.pro14
-rw-r--r--examples/opengl/contextinfo/main.cpp72
-rw-r--r--examples/opengl/contextinfo/renderwindow.cpp238
-rw-r--r--examples/opengl/contextinfo/renderwindow.h95
-rw-r--r--examples/opengl/contextinfo/widget.cpp400
-rw-r--r--examples/opengl/contextinfo/widget.h93
-rw-r--r--examples/opengl/cube/CMakeLists.txt65
-rw-r--r--examples/opengl/cube/cube.pngbin30341 -> 88913 bytes
-rw-r--r--examples/opengl/cube/cube.pro2
-rw-r--r--examples/opengl/cube/fshader.glsl2
-rw-r--r--examples/opengl/cube/geometryengine.cpp51
-rw-r--r--examples/opengl/cube/geometryengine.h51
-rw-r--r--examples/opengl/cube/main.cpp51
-rw-r--r--examples/opengl/cube/mainwidget.cpp72
-rw-r--r--examples/opengl/cube/mainwidget.h51
-rw-r--r--examples/opengl/cube/vshader.glsl2
-rw-r--r--examples/opengl/doc/images/hellogles3-example.png (renamed from examples/opengl/hellogles3/doc/images/hellogles3-example.png)bin61792 -> 61792 bytes
-rw-r--r--examples/opengl/doc/images/stereoexample-leftbuffer.pngbin0 -> 9987 bytes
-rw-r--r--examples/opengl/doc/images/stereoexample-rightbuffer.pngbin0 -> 10002 bytes
-rw-r--r--examples/opengl/doc/src/2dpainting.qdoc56
-rw-r--r--examples/opengl/doc/src/cube.qdoc49
-rw-r--r--examples/opengl/doc/src/hellogl2.qdoc29
-rw-r--r--examples/opengl/doc/src/hellogles3.qdoc149
-rw-r--r--examples/opengl/doc/src/openglwindow.qdoc138
-rw-r--r--examples/opengl/doc/src/stereoqopenglwidget.qdoc46
-rw-r--r--examples/opengl/doc/src/textures.qdoc28
-rw-r--r--examples/opengl/hellogl2/CMakeLists.txt43
-rw-r--r--examples/opengl/hellogl2/glwidget.cpp60
-rw-r--r--examples/opengl/hellogl2/glwidget.h51
-rw-r--r--examples/opengl/hellogl2/hellogl2.pro2
-rw-r--r--examples/opengl/hellogl2/logo.cpp51
-rw-r--r--examples/opengl/hellogl2/logo.h55
-rw-r--r--examples/opengl/hellogl2/main.cpp57
-rw-r--r--examples/opengl/hellogl2/mainwindow.cpp69
-rw-r--r--examples/opengl/hellogl2/mainwindow.h51
-rw-r--r--examples/opengl/hellogl2/window.cpp132
-rw-r--r--examples/opengl/hellogl2/window.h63
-rw-r--r--examples/opengl/hellogles3/CMakeLists.txt51
-rw-r--r--examples/opengl/hellogles3/doc/src/hellogles3.qdoc46
-rw-r--r--examples/opengl/hellogles3/glwindow.cpp51
-rw-r--r--examples/opengl/hellogles3/glwindow.h63
-rw-r--r--examples/opengl/hellogles3/main.cpp51
-rw-r--r--examples/opengl/hellowindow/hellowindow.cpp375
-rw-r--r--examples/opengl/hellowindow/hellowindow.h125
-rw-r--r--examples/opengl/hellowindow/hellowindow.pro9
-rw-r--r--examples/opengl/hellowindow/main.cpp172
-rw-r--r--examples/opengl/legacy/README4
-rw-r--r--examples/opengl/legacy/framebufferobject2/cubelogo.pngbin2884 -> 0 bytes
-rw-r--r--examples/opengl/legacy/framebufferobject2/framebufferobject2.pro11
-rw-r--r--examples/opengl/legacy/framebufferobject2/framebufferobject2.qrc5
-rw-r--r--examples/opengl/legacy/framebufferobject2/glwidget.cpp257
-rw-r--r--examples/opengl/legacy/framebufferobject2/glwidget.h75
-rw-r--r--examples/opengl/legacy/framebufferobject2/main.cpp71
-rw-r--r--examples/opengl/legacy/grabber/glwidget.cpp286
-rw-r--r--examples/opengl/legacy/grabber/glwidget.h107
-rw-r--r--examples/opengl/legacy/grabber/grabber.pro12
-rw-r--r--examples/opengl/legacy/grabber/main.cpp61
-rw-r--r--examples/opengl/legacy/grabber/mainwindow.cpp216
-rw-r--r--examples/opengl/legacy/grabber/mainwindow.h104
-rw-r--r--examples/opengl/legacy/hellogl/glwidget.cpp207
-rw-r--r--examples/opengl/legacy/hellogl/glwidget.h105
-rw-r--r--examples/opengl/legacy/hellogl/hellogl.pro17
-rw-r--r--examples/opengl/legacy/hellogl/main.cpp69
-rw-r--r--examples/opengl/legacy/hellogl/window.cpp107
-rw-r--r--examples/opengl/legacy/hellogl/window.h82
-rw-r--r--examples/opengl/legacy/legacy.pro16
-rw-r--r--examples/opengl/legacy/overpainting/bubble.cpp122
-rw-r--r--examples/opengl/legacy/overpainting/bubble.h77
-rw-r--r--examples/opengl/legacy/overpainting/glwidget.cpp293
-rw-r--r--examples/opengl/legacy/overpainting/glwidget.h114
-rw-r--r--examples/opengl/legacy/overpainting/main.cpp61
-rw-r--r--examples/opengl/legacy/overpainting/overpainting.pro19
-rw-r--r--examples/opengl/legacy/pbuffers/cube.cpp338
-rw-r--r--examples/opengl/legacy/pbuffers/cube.h159
-rw-r--r--examples/opengl/legacy/pbuffers/cubelogo.pngbin2884 -> 0 bytes
-rw-r--r--examples/opengl/legacy/pbuffers/glwidget.cpp256
-rw-r--r--examples/opengl/legacy/pbuffers/glwidget.h99
-rw-r--r--examples/opengl/legacy/pbuffers/main.cpp75
-rw-r--r--examples/opengl/legacy/pbuffers/pbuffers.pro13
-rw-r--r--examples/opengl/legacy/pbuffers/pbuffers.qrc5
-rw-r--r--examples/opengl/legacy/pbuffers2/bubbles.svg215
-rw-r--r--examples/opengl/legacy/pbuffers2/designer.pngbin2810 -> 0 bytes
-rw-r--r--examples/opengl/legacy/pbuffers2/glwidget.cpp328
-rw-r--r--examples/opengl/legacy/pbuffers2/glwidget.h94
-rw-r--r--examples/opengl/legacy/pbuffers2/main.cpp71
-rw-r--r--examples/opengl/legacy/pbuffers2/pbuffers2.pro11
-rw-r--r--examples/opengl/legacy/pbuffers2/pbuffers2.qrc6
-rw-r--r--examples/opengl/legacy/samplebuffers/glwidget.cpp174
-rw-r--r--examples/opengl/legacy/samplebuffers/glwidget.h71
-rw-r--r--examples/opengl/legacy/samplebuffers/main.cpp81
-rw-r--r--examples/opengl/legacy/samplebuffers/samplebuffers.pro10
-rw-r--r--examples/opengl/legacy/shared/qtlogo.cpp398
-rw-r--r--examples/opengl/legacy/shared/qtlogo.h78
-rw-r--r--examples/opengl/opengl.pro16
-rw-r--r--examples/opengl/openglwindow/CMakeLists.txt38
-rw-r--r--examples/opengl/openglwindow/main.cpp125
-rw-r--r--examples/opengl/openglwindow/openglwindow.cpp114
-rw-r--r--examples/opengl/openglwindow/openglwindow.h46
-rw-r--r--examples/opengl/openglwindow/openglwindow.pri4
-rw-r--r--examples/opengl/openglwindow/openglwindow.pro7
-rw-r--r--examples/opengl/paintedwindow/main.cpp65
-rw-r--r--examples/opengl/paintedwindow/paintedwindow.cpp231
-rw-r--r--examples/opengl/paintedwindow/paintedwindow.h104
-rw-r--r--examples/opengl/paintedwindow/paintedwindow.pro6
-rw-r--r--examples/opengl/qopenglwidget/bubble.cpp146
-rw-r--r--examples/opengl/qopenglwidget/bubble.h86
-rw-r--r--examples/opengl/qopenglwidget/glwidget.cpp560
-rw-r--r--examples/opengl/qopenglwidget/glwidget.h133
-rw-r--r--examples/opengl/qopenglwidget/main.cpp88
-rw-r--r--examples/opengl/qopenglwidget/mainwindow.cpp187
-rw-r--r--examples/opengl/qopenglwidget/mainwindow.h83
-rw-r--r--examples/opengl/qopenglwidget/qopenglwidget.pro15
-rw-r--r--examples/opengl/qopenglwidget/qt.pngbin2991 -> 0 bytes
-rw-r--r--examples/opengl/qopenglwidget/texture.qrc5
-rw-r--r--examples/opengl/qopenglwindow/background.frag30
-rw-r--r--examples/opengl/qopenglwindow/background_renderer.cpp214
-rw-r--r--examples/opengl/qopenglwindow/background_renderer.h93
-rw-r--r--examples/opengl/qopenglwindow/main.cpp200
-rw-r--r--examples/opengl/qopenglwindow/qopenglwindow.pro16
-rw-r--r--examples/opengl/qopenglwindow/shaders.qrc5
-rw-r--r--examples/opengl/stereoqopenglwidget/CMakeLists.txt42
-rw-r--r--examples/opengl/stereoqopenglwidget/glwidget.cpp277
-rw-r--r--examples/opengl/stereoqopenglwidget/glwidget.h53
-rw-r--r--examples/opengl/stereoqopenglwidget/main.cpp31
-rw-r--r--examples/opengl/stereoqopenglwidget/mainwindow.cpp25
-rw-r--r--examples/opengl/stereoqopenglwidget/mainwindow.h21
-rw-r--r--examples/opengl/stereoqopenglwidget/stereoqopenglwidget.pro (renamed from examples/opengl/threadedqopenglwidget/threadedqopenglwidget.pro)4
-rw-r--r--examples/opengl/textures/CMakeLists.txt58
-rw-r--r--examples/opengl/textures/glwidget.cpp69
-rw-r--r--examples/opengl/textures/glwidget.h51
-rw-r--r--examples/opengl/textures/main.cpp53
-rw-r--r--examples/opengl/textures/textures.pro2
-rw-r--r--examples/opengl/textures/window.cpp51
-rw-r--r--examples/opengl/textures/window.h51
-rw-r--r--examples/opengl/threadedqopenglwidget/glwidget.cpp367
-rw-r--r--examples/opengl/threadedqopenglwidget/glwidget.h136
-rw-r--r--examples/opengl/threadedqopenglwidget/main.cpp131
-rw-r--r--examples/opengl/threadedqopenglwidget/mainwindow.cpp63
-rw-r--r--examples/opengl/threadedqopenglwidget/mainwindow.h64
157 files changed, 1595 insertions, 12091 deletions
diff --git a/examples/opengl/2dpainting/2dpainting.pro b/examples/opengl/2dpainting/2dpainting.pro
index 20fe4739a5..751c2022fd 100644
--- a/examples/opengl/2dpainting/2dpainting.pro
+++ b/examples/opengl/2dpainting/2dpainting.pro
@@ -1,4 +1,4 @@
-QT += widgets opengl
+QT += widgets opengl openglwidgets
HEADERS = glwidget.h \
helper.h \
diff --git a/examples/opengl/2dpainting/CMakeLists.txt b/examples/opengl/2dpainting/CMakeLists.txt
new file mode 100644
index 0000000000..b4ae3aa313
--- /dev/null
+++ b/examples/opengl/2dpainting/CMakeLists.txt
@@ -0,0 +1,43 @@
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
+
+cmake_minimum_required(VERSION 3.16)
+project(2dpainting LANGUAGES CXX)
+
+find_package(Qt6 REQUIRED COMPONENTS Core Gui OpenGL OpenGLWidgets Widgets)
+
+qt_standard_project_setup()
+
+qt_add_executable(2dpainting
+ glwidget.cpp glwidget.h
+ helper.cpp helper.h
+ main.cpp
+ widget.cpp widget.h
+ window.cpp window.h
+)
+
+set_target_properties(2dpainting PROPERTIES
+ WIN32_EXECUTABLE TRUE
+ MACOSX_BUNDLE TRUE
+)
+
+target_link_libraries(2dpainting PRIVATE
+ Qt6::Core
+ Qt6::Gui
+ Qt6::OpenGL
+ Qt6::OpenGLWidgets
+ Qt6::Widgets
+)
+
+install(TARGETS 2dpainting
+ BUNDLE DESTINATION .
+ RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
+ LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
+)
+
+qt_generate_deploy_app_script(
+ TARGET 2dpainting
+ OUTPUT_SCRIPT deploy_script
+ NO_UNSUPPORTED_PLATFORM_ERROR
+)
+install(SCRIPT ${deploy_script})
diff --git a/examples/opengl/2dpainting/glwidget.cpp b/examples/opengl/2dpainting/glwidget.cpp
index 0f645896cc..9351c657df 100644
--- a/examples/opengl/2dpainting/glwidget.cpp
+++ b/examples/opengl/2dpainting/glwidget.cpp
@@ -1,52 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the examples of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:BSD$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** BSD License Usage
-** Alternatively, you may use this file under the terms of the BSD license
-** as follows:
-**
-** "Redistribution and use in source and binary forms, with or without
-** modification, are permitted provided that the following conditions are
-** met:
-** * Redistributions of source code must retain the above copyright
-** notice, this list of conditions and the following disclaimer.
-** * Redistributions in binary form must reproduce the above copyright
-** notice, this list of conditions and the following disclaimer in
-** the documentation and/or other materials provided with the
-** distribution.
-** * 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.
-**
-**
-** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
-** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
-** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
-** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
-** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
-** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
-** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
-** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
-** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
#include "glwidget.h"
#include "helper.h"
diff --git a/examples/opengl/2dpainting/glwidget.h b/examples/opengl/2dpainting/glwidget.h
index 16ad1a95f3..d441954818 100644
--- a/examples/opengl/2dpainting/glwidget.h
+++ b/examples/opengl/2dpainting/glwidget.h
@@ -1,52 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the examples of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:BSD$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** BSD License Usage
-** Alternatively, you may use this file under the terms of the BSD license
-** as follows:
-**
-** "Redistribution and use in source and binary forms, with or without
-** modification, are permitted provided that the following conditions are
-** met:
-** * Redistributions of source code must retain the above copyright
-** notice, this list of conditions and the following disclaimer.
-** * Redistributions in binary form must reproduce the above copyright
-** notice, this list of conditions and the following disclaimer in
-** the documentation and/or other materials provided with the
-** distribution.
-** * 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.
-**
-**
-** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
-** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
-** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
-** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
-** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
-** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
-** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
-** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
-** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
#ifndef GLWIDGET_H
#define GLWIDGET_H
diff --git a/examples/opengl/2dpainting/helper.cpp b/examples/opengl/2dpainting/helper.cpp
index c0582e1dec..953e3d9b17 100644
--- a/examples/opengl/2dpainting/helper.cpp
+++ b/examples/opengl/2dpainting/helper.cpp
@@ -1,52 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the examples of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:BSD$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** BSD License Usage
-** Alternatively, you may use this file under the terms of the BSD license
-** as follows:
-**
-** "Redistribution and use in source and binary forms, with or without
-** modification, are permitted provided that the following conditions are
-** met:
-** * Redistributions of source code must retain the above copyright
-** notice, this list of conditions and the following disclaimer.
-** * Redistributions in binary form must reproduce the above copyright
-** notice, this list of conditions and the following disclaimer in
-** the documentation and/or other materials provided with the
-** distribution.
-** * 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.
-**
-**
-** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
-** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
-** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
-** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
-** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
-** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
-** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
-** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
-** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
#include "helper.h"
diff --git a/examples/opengl/2dpainting/helper.h b/examples/opengl/2dpainting/helper.h
index 37058d0a75..288b3d80e1 100644
--- a/examples/opengl/2dpainting/helper.h
+++ b/examples/opengl/2dpainting/helper.h
@@ -1,52 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the examples of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:BSD$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** BSD License Usage
-** Alternatively, you may use this file under the terms of the BSD license
-** as follows:
-**
-** "Redistribution and use in source and binary forms, with or without
-** modification, are permitted provided that the following conditions are
-** met:
-** * Redistributions of source code must retain the above copyright
-** notice, this list of conditions and the following disclaimer.
-** * Redistributions in binary form must reproduce the above copyright
-** notice, this list of conditions and the following disclaimer in
-** the documentation and/or other materials provided with the
-** distribution.
-** * 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.
-**
-**
-** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
-** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
-** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
-** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
-** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
-** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
-** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
-** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
-** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
#ifndef HELPER_H
#define HELPER_H
diff --git a/examples/opengl/2dpainting/main.cpp b/examples/opengl/2dpainting/main.cpp
index bcc13a14aa..668673caa6 100644
--- a/examples/opengl/2dpainting/main.cpp
+++ b/examples/opengl/2dpainting/main.cpp
@@ -1,52 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the examples of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:BSD$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** BSD License Usage
-** Alternatively, you may use this file under the terms of the BSD license
-** as follows:
-**
-** "Redistribution and use in source and binary forms, with or without
-** modification, are permitted provided that the following conditions are
-** met:
-** * Redistributions of source code must retain the above copyright
-** notice, this list of conditions and the following disclaimer.
-** * Redistributions in binary form must reproduce the above copyright
-** notice, this list of conditions and the following disclaimer in
-** the documentation and/or other materials provided with the
-** distribution.
-** * 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.
-**
-**
-** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
-** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
-** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
-** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
-** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
-** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
-** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
-** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
-** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
#include "window.h"
diff --git a/examples/opengl/2dpainting/widget.cpp b/examples/opengl/2dpainting/widget.cpp
index a1000930f9..3da9f20d7d 100644
--- a/examples/opengl/2dpainting/widget.cpp
+++ b/examples/opengl/2dpainting/widget.cpp
@@ -1,52 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the examples of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:BSD$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** BSD License Usage
-** Alternatively, you may use this file under the terms of the BSD license
-** as follows:
-**
-** "Redistribution and use in source and binary forms, with or without
-** modification, are permitted provided that the following conditions are
-** met:
-** * Redistributions of source code must retain the above copyright
-** notice, this list of conditions and the following disclaimer.
-** * Redistributions in binary form must reproduce the above copyright
-** notice, this list of conditions and the following disclaimer in
-** the documentation and/or other materials provided with the
-** distribution.
-** * 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.
-**
-**
-** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
-** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
-** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
-** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
-** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
-** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
-** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
-** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
-** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
#include "widget.h"
#include "helper.h"
diff --git a/examples/opengl/2dpainting/widget.h b/examples/opengl/2dpainting/widget.h
index 40d20bc0a1..6ab97a4a9d 100644
--- a/examples/opengl/2dpainting/widget.h
+++ b/examples/opengl/2dpainting/widget.h
@@ -1,52 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the examples of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:BSD$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** BSD License Usage
-** Alternatively, you may use this file under the terms of the BSD license
-** as follows:
-**
-** "Redistribution and use in source and binary forms, with or without
-** modification, are permitted provided that the following conditions are
-** met:
-** * Redistributions of source code must retain the above copyright
-** notice, this list of conditions and the following disclaimer.
-** * Redistributions in binary form must reproduce the above copyright
-** notice, this list of conditions and the following disclaimer in
-** the documentation and/or other materials provided with the
-** distribution.
-** * 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.
-**
-**
-** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
-** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
-** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
-** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
-** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
-** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
-** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
-** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
-** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
#ifndef WIDGET_H
#define WIDGET_H
diff --git a/examples/opengl/2dpainting/window.cpp b/examples/opengl/2dpainting/window.cpp
index d6d6f8b468..98a06eaff2 100644
--- a/examples/opengl/2dpainting/window.cpp
+++ b/examples/opengl/2dpainting/window.cpp
@@ -1,52 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the examples of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:BSD$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** BSD License Usage
-** Alternatively, you may use this file under the terms of the BSD license
-** as follows:
-**
-** "Redistribution and use in source and binary forms, with or without
-** modification, are permitted provided that the following conditions are
-** met:
-** * Redistributions of source code must retain the above copyright
-** notice, this list of conditions and the following disclaimer.
-** * Redistributions in binary form must reproduce the above copyright
-** notice, this list of conditions and the following disclaimer in
-** the documentation and/or other materials provided with the
-** distribution.
-** * 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.
-**
-**
-** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
-** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
-** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
-** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
-** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
-** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
-** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
-** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
-** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
#include "glwidget.h"
#include "widget.h"
diff --git a/examples/opengl/2dpainting/window.h b/examples/opengl/2dpainting/window.h
index be23216d6b..d3d62ce0cf 100644
--- a/examples/opengl/2dpainting/window.h
+++ b/examples/opengl/2dpainting/window.h
@@ -1,52 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the examples of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:BSD$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** BSD License Usage
-** Alternatively, you may use this file under the terms of the BSD license
-** as follows:
-**
-** "Redistribution and use in source and binary forms, with or without
-** modification, are permitted provided that the following conditions are
-** met:
-** * Redistributions of source code must retain the above copyright
-** notice, this list of conditions and the following disclaimer.
-** * Redistributions in binary form must reproduce the above copyright
-** notice, this list of conditions and the following disclaimer in
-** the documentation and/or other materials provided with the
-** distribution.
-** * 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.
-**
-**
-** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
-** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
-** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
-** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
-** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
-** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
-** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
-** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
-** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
#ifndef WINDOW_H
#define WINDOW_H
diff --git a/examples/opengl/CMakeLists.txt b/examples/opengl/CMakeLists.txt
new file mode 100644
index 0000000000..09e31defe5
--- /dev/null
+++ b/examples/opengl/CMakeLists.txt
@@ -0,0 +1,12 @@
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
+
+qt_internal_add_example(openglwindow)
+qt_internal_add_example(hellogles3)
+if(TARGET Qt6::Widgets)
+ qt_internal_add_example(2dpainting)
+ qt_internal_add_example(hellogl2)
+ qt_internal_add_example(cube)
+ qt_internal_add_example(textures)
+ qt_internal_add_example(stereoqopenglwidget)
+endif()
diff --git a/examples/opengl/computegles31/Qt-logo-medium.png b/examples/opengl/computegles31/Qt-logo-medium.png
deleted file mode 100644
index a1ca1f1830..0000000000
--- a/examples/opengl/computegles31/Qt-logo-medium.png
+++ /dev/null
Binary files differ
diff --git a/examples/opengl/computegles31/computegles31.pro b/examples/opengl/computegles31/computegles31.pro
deleted file mode 100644
index 8d9b00ba83..0000000000
--- a/examples/opengl/computegles31/computegles31.pro
+++ /dev/null
@@ -1,11 +0,0 @@
-QT += opengl
-
-HEADERS = $$PWD/glwindow.h
-
-SOURCES = $$PWD/glwindow.cpp \
- $$PWD/main.cpp
-
-RESOURCES += computegles31.qrc
-
-target.path = $$[QT_INSTALL_EXAMPLES]/opengl/computegles31
-INSTALLS += target
diff --git a/examples/opengl/computegles31/computegles31.qrc b/examples/opengl/computegles31/computegles31.qrc
deleted file mode 100644
index b99eb0a82e..0000000000
--- a/examples/opengl/computegles31/computegles31.qrc
+++ /dev/null
@@ -1,5 +0,0 @@
-<RCC>
- <qresource prefix="/">
- <file>Qt-logo-medium.png</file>
- </qresource>
-</RCC>
diff --git a/examples/opengl/computegles31/glwindow.cpp b/examples/opengl/computegles31/glwindow.cpp
deleted file mode 100644
index 5e8d45da24..0000000000
--- a/examples/opengl/computegles31/glwindow.cpp
+++ /dev/null
@@ -1,419 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2017 The Qt Company Ltd.
-** Contact: http://www.qt.io/licensing/
-**
-** This file is part of the examples of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:BSD$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** BSD License Usage
-** Alternatively, you may use this file under the terms of the BSD license
-** as follows:
-**
-** "Redistribution and use in source and binary forms, with or without
-** modification, are permitted provided that the following conditions are
-** met:
-** * Redistributions of source code must retain the above copyright
-** notice, this list of conditions and the following disclaimer.
-** * Redistributions in binary form must reproduce the above copyright
-** notice, this list of conditions and the following disclaimer in
-** the documentation and/or other materials provided with the
-** distribution.
-** * 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.
-**
-**
-** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
-** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
-** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
-** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
-** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
-** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
-** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
-** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
-** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include "glwindow.h"
-#include <QImage>
-#include <QOpenGLShaderProgram>
-#include <QOpenGLContext>
-#include <QOpenGLFunctions>
-#include <QOpenGLExtraFunctions>
-#include <QOpenGLVertexArrayObject>
-#include <QtGui/qopengl.h>
-#include <QDebug>
-#include <QTimer>
-#include <math.h>
-
-#ifndef GL_READ_WRITE
-#define GL_READ_WRITE 0x88BA
-#endif
-
-#ifndef GL_RGBA8
-#define GL_RGBA8 0x8058
-#endif
-
-#ifndef GL_SHADER_IMAGE_ACCESS_BARRIER_BIT
-#define GL_SHADER_IMAGE_ACCESS_BARRIER_BIT 0x00000020
-#endif
-
-GLWindow::GLWindow()
-{
- const float animationStart = 0.0;
- const float animationEnd = 10.0;
- const float animationLength = 1000;
-
- m_animationGroup = new QSequentialAnimationGroup(this);
- m_animationGroup->setLoopCount(-1);
-
- m_animationForward = new QPropertyAnimation(this, QByteArrayLiteral("blurRadius"));
- m_animationForward->setStartValue(animationStart);
- m_animationForward->setEndValue(animationEnd);
- m_animationForward->setDuration(animationLength);
- m_animationGroup->addAnimation(m_animationForward);
-
- m_animationBackward = new QPropertyAnimation(this, QByteArrayLiteral("blurRadius"));
- m_animationBackward->setStartValue(animationEnd);
- m_animationBackward->setEndValue(animationStart);
- m_animationBackward->setDuration(animationLength);
- m_animationGroup->addAnimation(m_animationBackward);
-
- m_animationGroup->start();
-}
-
-GLWindow::~GLWindow()
-{
- makeCurrent();
- delete m_texImageInput;
- delete m_texImageProcessed;
- delete m_texImageTmp;
- delete m_shaderDisplay;
- delete m_shaderComputeH;
- delete m_shaderComputeV;
- delete m_animationGroup;
- delete m_animationForward;
- delete m_animationBackward;
- delete m_vao;
-}
-
-void GLWindow::setBlurRadius(float blurRadius)
-{
- int radius = int(blurRadius);
- if (radius != m_blurRadius) {
- m_blurRadius = radius;
- update();
- }
-}
-
-void GLWindow::setAnimating(bool animate)
-{
- m_animate = animate;
- if (animate)
- m_animationGroup->start();
- else
- m_animationGroup->stop();
-}
-
-void GLWindow::keyPressEvent(QKeyEvent *e)
-{
- if (e->key() == Qt::Key_Space) { // pause
- setAnimating(!m_animate);
- }
- update();
-}
-
-
-
-
-static const char *vsDisplaySource =
- "const vec4 vertices[4] = vec4[4] (\n"
- " vec4( -1.0, 1.0, 0.0, 1.0),\n"
- " vec4( -1.0, -1.0, 0.0, 1.0),\n"
- " vec4( 1.0, 1.0, 0.0, 1.0),\n"
- " vec4( 1.0, -1.0, 0.0, 1.0)\n"
- ");\n"
- "const vec2 texCoords[4] = vec2[4] (\n"
- " vec2( 0.0, 1.0),\n"
- " vec2( 0.0, 0.0),\n"
- " vec2( 1.0, 1.0),\n"
- " vec2( 1.0, 0.0)\n"
- ");\n"
- "out vec2 texCoord;\n"
- "uniform mat4 matProjection;\n"
- "uniform vec2 imageRatio;\n"
- "void main() {\n"
- " gl_Position = matProjection * ( vertices[gl_VertexID] * vec4(imageRatio,0,1) );\n"
- " texCoord = texCoords[gl_VertexID];\n"
- "}\n";
-
-static const char *fsDisplaySource =
- "in lowp vec2 texCoord; \n"
- "uniform sampler2D samImage; \n"
- "layout(location = 0) out lowp vec4 color;\n"
- "void main() {\n"
- " lowp vec4 texColor = texture(samImage,texCoord);\n"
- " color = vec4(texColor.rgb, 1.0);\n"
- "}\n";
-
-static const char *csComputeSourceV =
- "#define COMPUTEPATCHSIZE 10 // Setting this to 10 to comply with MAX_COMPUTE_WORK_GROUP_INVOCATIONS for both OpenGL and OpenGLES - see QTBUG-79374 \n"
- "#define IMGFMT rgba8 \n"
- "layout (local_size_x = COMPUTEPATCHSIZE, local_size_y = COMPUTEPATCHSIZE) in;\n"
- "layout(binding=0, IMGFMT) uniform readonly highp image2D inputImage; // Use a sampler to improve performance \n"
- "layout(binding=1, IMGFMT) uniform writeonly highp image2D resultImage;\n"
- "uniform int radius;\n"
- "const float cutoff = 2.2;\n"
-
- "float expFactor() { // a function, otherwise MESA produces error: initializer of global variable `expFactor' must be a constant expression\n"
- " float sigma = clamp(float(radius) / cutoff,0.02,100.0);\n"
- " return 1.0 / (2.0 * sigma * sigma);\n"
- "}\n"
-
- "float gaussian(float distance, float expfactor) {\n"
- " return exp( -(distance * distance) * expfactor);\n"
- "}\n"
-
- "void main() {\n"
- " ivec2 imgSize = imageSize(resultImage);\n"
- " int x = int(gl_GlobalInvocationID.x);\n"
- " int y = int(gl_GlobalInvocationID.y);\n"
- " if ( (x >= imgSize.x) || (y >= imgSize.y) ) return;\n"
- " vec4 sumPixels = vec4(0.0);\n"
- " float sumWeights = 0.0;\n"
- " int left = clamp(x - radius, 0, imgSize.x - 1);\n"
- " int right = clamp(x + radius, 0, imgSize.x - 1);\n"
- " int top = clamp(y - radius, 0, imgSize.y - 1);\n"
- " int bottom = clamp(y + radius, 0, imgSize.y - 1);\n"
- " float expfactor = expFactor();\n"
- " for (int iY = top; iY <= bottom; iY++) {\n"
- " float dy = float(abs(iY - y));\n"
- " vec4 imgValue = imageLoad(inputImage, ivec2(x,iY));\n"
- " float weight = gaussian(dy, expfactor);\n"
- " sumWeights += weight;\n"
- " sumPixels += (imgValue * weight);\n"
- " }\n"
- " sumPixels /= sumWeights;\n"
- " imageStore(resultImage, ivec2(x,y), sumPixels);\n"
- "}\n";
-
-static const char *csComputeSourceH =
- "#define COMPUTEPATCHSIZE 10 \n"
- "#define IMGFMT rgba8 \n"
- "layout (local_size_x = COMPUTEPATCHSIZE, local_size_y = COMPUTEPATCHSIZE) in;\n"
- "layout(binding=0, IMGFMT) uniform readonly highp image2D inputImage; // Use a sampler to improve performance \n"
- "layout(binding=1, IMGFMT) uniform writeonly highp image2D resultImage;\n"
- "uniform int radius;\n"
- "const float cutoff = 2.2;\n"
-
- "float expFactor() { // a function, otherwise MESA produces error: initializer of global variable `expFactor' must be a constant expression\n"
- " float sigma = clamp(float(radius) / cutoff,0.02,100.0);\n"
- " return 1.0 / (2.0 * sigma * sigma);\n"
- "}\n"
-
- "float gaussian(float distance, float expfactor) {\n"
- " return exp( -(distance * distance) * expfactor);\n"
- "}\n"
-
- "void main() {\n"
- " ivec2 imgSize = imageSize(resultImage);\n"
- " int x = int(gl_GlobalInvocationID.x);\n"
- " int y = int(gl_GlobalInvocationID.y);\n"
- " if ( (x >= imgSize.x) || (y >= imgSize.y) ) return;\n"
- " vec4 sumPixels = vec4(0.0);\n"
- " float sumWeights = 0.0;\n"
- " int left = clamp(x - radius, 0, imgSize.x - 1);\n"
- " int right = clamp(x + radius, 0, imgSize.x - 1);\n"
- " int top = clamp(y - radius, 0, imgSize.y - 1);\n"
- " int bottom = clamp(y + radius, 0, imgSize.y - 1);\n"
- " float expfactor = expFactor();\n"
- " for (int iX = left; iX <= right; iX++) {\n"
- " float dx = float(abs(iX - x));\n"
- " vec4 imgValue = imageLoad(inputImage, ivec2(iX,y));\n"
- " float weight = gaussian(dx, expfactor);\n"
- " sumWeights += weight;\n"
- " sumPixels += (imgValue * weight);\n"
- " }\n"
- " sumPixels /= sumWeights;\n"
- " imageStore(resultImage, ivec2(x,y), sumPixels);\n"
- "}\n";
-
-
-
-QByteArray versionedShaderCode(const char *src)
-{
- QByteArray versionedSrc;
-
- if (QOpenGLContext::currentContext()->isOpenGLES())
- versionedSrc.append(QByteArrayLiteral("#version 310 es\n"));
- else
- versionedSrc.append(QByteArrayLiteral("#version 430 core\n"));
-
- versionedSrc.append(src);
- return versionedSrc;
-}
-
-void computeProjection(int winWidth, int winHeight, int imgWidth, int imgHeight, QMatrix4x4 &outProjection, QSizeF &outQuadSize)
-{
- float ratioImg = float(imgWidth) / float(imgHeight);
- float ratioCanvas = float(winWidth) / float(winHeight);
-
- float correction = ratioImg / ratioCanvas;
- float rescaleFactor = 1.0f;
- float quadWidth = 1.0f;
- float quadHeight = 1.0f;
-
- if (correction < 1.0f) // canvas larger than image -- height = 1.0, vertical black bands
- {
- quadHeight = 1.0f;
- quadWidth = 1.0f * ratioImg;
- rescaleFactor = ratioCanvas;
- correction = 1.0f / rescaleFactor;
- }
- else // image larger than canvas -- width = 1.0, horizontal black bands
- {
- quadWidth = 1.0f;
- quadHeight = 1.0f / ratioImg;
- correction = 1.0f / ratioCanvas;
- }
-
- const float frustumWidth = 1.0f * rescaleFactor;
- const float frustumHeight = 1.0f * rescaleFactor * correction;
-
- outProjection = QMatrix4x4();
- outProjection.ortho(
- -frustumWidth,
- frustumWidth,
- -frustumHeight,
- frustumHeight,
- -1.0f,
- 1.0f);
- outQuadSize = QSizeF(quadWidth,quadHeight);
-}
-
-void GLWindow::initializeGL()
-{
- QOpenGLContext *ctx = QOpenGLContext::currentContext();
- qDebug() << "Got a "
- << ctx->format().majorVersion()
- << "."
- << ctx->format().minorVersion()
- << ((ctx->format().renderableType() == QSurfaceFormat::OpenGLES) ? (" GLES") : (" GL"))
- << " context";
-
- QImage img(":/Qt-logo-medium.png");
- Q_ASSERT(!img.isNull());
- delete m_texImageInput;
- m_texImageInput = new QOpenGLTexture(img.convertToFormat(QImage::Format_RGBA8888).mirrored());
-
- delete m_texImageTmp;
- m_texImageTmp = new QOpenGLTexture(QOpenGLTexture::Target2D);
- m_texImageTmp->setFormat(m_texImageInput->format());
- m_texImageTmp->setSize(m_texImageInput->width(),m_texImageInput->height());
- m_texImageTmp->allocateStorage(QOpenGLTexture::RGBA,QOpenGLTexture::UInt8); // WTF?
-
- delete m_texImageProcessed;
- m_texImageProcessed = new QOpenGLTexture(QOpenGLTexture::Target2D);
- m_texImageProcessed->setFormat(m_texImageInput->format());
- m_texImageProcessed->setSize(m_texImageInput->width(),m_texImageInput->height());
- m_texImageProcessed->allocateStorage(QOpenGLTexture::RGBA,QOpenGLTexture::UInt8);
-
- m_texImageProcessed->setMagnificationFilter(QOpenGLTexture::Linear);
- m_texImageProcessed->setMinificationFilter(QOpenGLTexture::Linear);
- m_texImageProcessed->setWrapMode(QOpenGLTexture::ClampToEdge);
-
- delete m_shaderDisplay;
- m_shaderDisplay = new QOpenGLShaderProgram;
- // Prepend the correct version directive to the sources. The rest is the
- // same, thanks to the common GLSL syntax.
- m_shaderDisplay->addShaderFromSourceCode(QOpenGLShader::Vertex, versionedShaderCode(vsDisplaySource));
- m_shaderDisplay->addShaderFromSourceCode(QOpenGLShader::Fragment, versionedShaderCode(fsDisplaySource));
- m_shaderDisplay->link();
-
- delete m_shaderComputeV;
- m_shaderComputeV = new QOpenGLShaderProgram;
- m_shaderComputeV->addShaderFromSourceCode(QOpenGLShader::Compute, versionedShaderCode(csComputeSourceV));
- m_shaderComputeV->link();
-
- delete m_shaderComputeH;
- m_shaderComputeH = new QOpenGLShaderProgram;
- m_shaderComputeH->addShaderFromSourceCode(QOpenGLShader::Compute, versionedShaderCode(csComputeSourceH));
- m_shaderComputeH->link();
-
- // Create a VAO. Not strictly required for ES 3, but it is for plain OpenGL core context.
- m_vao = new QOpenGLVertexArrayObject;
- m_vao->create();
-}
-
-void GLWindow::resizeGL(int w, int h)
-{
- computeProjection(w,h,m_texImageInput->width(),m_texImageInput->height(),m_proj,m_quadSize);
-}
-
-QSize getWorkGroups(int workGroupSize, const QSize &imageSize)
-{
- int x = imageSize.width();
- x = (x % workGroupSize) ? (x / workGroupSize) + 1 : (x / workGroupSize);
- int y = imageSize.height();
- y = (y % workGroupSize) ? (y / workGroupSize) + 1 : (y / workGroupSize);
- return QSize(x,y);
-}
-
-void GLWindow::paintGL()
-{
- // Now use QOpenGLExtraFunctions instead of QOpenGLFunctions as we want to
- // do more than what GL(ES) 2.0 offers.
- QOpenGLExtraFunctions *f = QOpenGLContext::currentContext()->extraFunctions();
-
-
- // Process input image
- QSize workGroups = getWorkGroups(10, QSize(m_texImageInput->width(), m_texImageInput->height()));
- // Pass 1
- f->glBindImageTexture(0, m_texImageInput->textureId(), 0, 0, 0, GL_READ_WRITE, GL_RGBA8);
- f->glBindImageTexture(1, m_texImageTmp->textureId(), 0, 0, 0, GL_READ_WRITE, GL_RGBA8);
- m_shaderComputeV->bind();
- m_shaderComputeV->setUniformValue("radius",m_blurRadius);
- f->glDispatchCompute(workGroups.width(),workGroups.height(),1);
- f->glMemoryBarrier(GL_SHADER_IMAGE_ACCESS_BARRIER_BIT);
- m_shaderComputeV->release();
- // Pass 2
- f->glBindImageTexture(0, m_texImageTmp->textureId(), 0, 0, 0, GL_READ_WRITE, GL_RGBA8);
- f->glBindImageTexture(1, m_texImageProcessed->textureId(), 0, 0, 0, GL_READ_WRITE, GL_RGBA8);
- m_shaderComputeH->bind();
- m_shaderComputeH->setUniformValue("radius",m_blurRadius);
- f->glDispatchCompute(workGroups.width(),workGroups.height(),1);
- f->glMemoryBarrier(GL_SHADER_IMAGE_ACCESS_BARRIER_BIT);
- m_shaderComputeH->release();
- // Compute cleanup
- f->glBindImageTexture(0, 0, 0, 0, 0, GL_READ_WRITE, GL_RGBA8);
- f->glBindImageTexture(1, 0, 0, 0, 0, GL_READ_WRITE, GL_RGBA8);
-
- // Display processed image
- f->glClearColor(0, 0, 0, 1);
- f->glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
- m_texImageProcessed->bind(0);
- m_shaderDisplay->bind();
- m_shaderDisplay->setUniformValue("matProjection",m_proj);
- m_shaderDisplay->setUniformValue("imageRatio",m_quadSize);
- m_shaderDisplay->setUniformValue("samImage",0);
- m_vao->bind();
- f->glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
- m_vao->release();
- m_shaderDisplay->release();
- m_texImageProcessed->release(0);
-}
-
diff --git a/examples/opengl/computegles31/glwindow.h b/examples/opengl/computegles31/glwindow.h
deleted file mode 100644
index 5375fbb488..0000000000
--- a/examples/opengl/computegles31/glwindow.h
+++ /dev/null
@@ -1,110 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2017 The Qt Company Ltd.
-** Contact: http://www.qt.io/licensing/
-**
-** This file is part of the examples of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:BSD$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** BSD License Usage
-** Alternatively, you may use this file under the terms of the BSD license
-** as follows:
-**
-** "Redistribution and use in source and binary forms, with or without
-** modification, are permitted provided that the following conditions are
-** met:
-** * Redistributions of source code must retain the above copyright
-** notice, this list of conditions and the following disclaimer.
-** * Redistributions in binary form must reproduce the above copyright
-** notice, this list of conditions and the following disclaimer in
-** the documentation and/or other materials provided with the
-** distribution.
-** * 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.
-**
-**
-** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
-** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
-** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
-** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
-** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
-** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
-** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
-** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
-** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef GLWIDGET_H
-#define GLWIDGET_H
-
-#include <QOpenGLWindow>
-#include <QOpenGLTexture>
-#include <QMatrix4x4>
-#include <QVector3D>
-#include <QKeyEvent>
-#include <QPropertyAnimation>
-#include <QSequentialAnimationGroup>
-#include <QRectF>
-
-QT_BEGIN_NAMESPACE
-
-class QOpenGLTexture;
-class QOpenGLShaderProgram;
-class QOpenGLBuffer;
-class QOpenGLVertexArrayObject;
-
-QT_END_NAMESPACE
-
-class GLWindow : public QOpenGLWindow
-{
- Q_OBJECT
- Q_PROPERTY(float blurRadius READ blurRadius WRITE setBlurRadius)
-
-public:
- GLWindow();
- ~GLWindow();
-
- void initializeGL() override;
- void resizeGL(int w, int h) override;
- void paintGL() override;
-
- float blurRadius() const { return m_blurRadius; }
- void setBlurRadius(float blurRadius);
-
-protected:
- void keyPressEvent(QKeyEvent *e) override;
- void setAnimating(bool animate);
-
-private:
- QPropertyAnimation *m_animationForward = nullptr;
- QPropertyAnimation *m_animationBackward = nullptr;
- QSequentialAnimationGroup *m_animationGroup;
- QOpenGLTexture *m_texImageInput = nullptr;
- QOpenGLTexture *m_texImageTmp = nullptr;
- QOpenGLTexture *m_texImageProcessed = nullptr;
- QOpenGLShaderProgram *m_shaderDisplay = nullptr;
- QOpenGLShaderProgram *m_shaderComputeV = nullptr;
- QOpenGLShaderProgram *m_shaderComputeH = nullptr;
- QMatrix4x4 m_proj;
- QSizeF m_quadSize;
-
- int m_blurRadius = 0;
- bool m_animate = true;
- QOpenGLVertexArrayObject *m_vao = nullptr;
-};
-
-#endif
diff --git a/examples/opengl/computegles31/main.cpp b/examples/opengl/computegles31/main.cpp
deleted file mode 100644
index 88f0f36115..0000000000
--- a/examples/opengl/computegles31/main.cpp
+++ /dev/null
@@ -1,148 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2017 The Qt Company Ltd.
-** Contact: http://www.qt.io/licensing/
-**
-** This file is part of the examples of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:BSD$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** BSD License Usage
-** Alternatively, you may use this file under the terms of the BSD license
-** as follows:
-**
-** "Redistribution and use in source and binary forms, with or without
-** modification, are permitted provided that the following conditions are
-** met:
-** * Redistributions of source code must retain the above copyright
-** notice, this list of conditions and the following disclaimer.
-** * Redistributions in binary form must reproduce the above copyright
-** notice, this list of conditions and the following disclaimer in
-** the documentation and/or other materials provided with the
-** distribution.
-** * 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.
-**
-**
-** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
-** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
-** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
-** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
-** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
-** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
-** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
-** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
-** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include <QGuiApplication>
-#include <QSurfaceFormat>
-#include <QOffscreenSurface>
-#include <QOpenGLContext>
-#include <QDebug>
-#include <QPair>
-#include "glwindow.h"
-
-bool OGLSupports(int major, int minor, bool gles = false, QSurfaceFormat::OpenGLContextProfile profile = QSurfaceFormat::NoProfile)
-{
- QOpenGLContext ctx;
- QSurfaceFormat fmt;
- fmt.setVersion(major, minor);
- if (gles) {
- fmt.setRenderableType(QSurfaceFormat::OpenGLES);
- } else {
- fmt.setRenderableType(QSurfaceFormat::OpenGL);
- fmt.setProfile(profile);
- }
-
- ctx.setFormat(fmt);
- ctx.create();
- if (!ctx.isValid())
- return false;
- int ctxMajor = ctx.format().majorVersion();
- int ctxMinor = ctx.format().minorVersion();
- bool isGles = (ctx.format().renderableType() == QSurfaceFormat::OpenGLES);
-
- if (isGles != gles) return false;
- if (ctxMajor < major) return false;
- if (ctxMajor == major && ctxMinor < minor)
- return false;
- if (!gles && ctx.format().profile() != profile)
- return false;
- return true;
-}
-
-int main(int argc, char *argv[])
-{
- QGuiApplication app(argc, argv);
-
- qDebug() << "Support for GL 2.0 noprof "<<( OGLSupports(2,0,false) ? "yes" : "no");
- qDebug() << "Support for GL 2.0 core "<<( OGLSupports(2,0,false, QSurfaceFormat::CoreProfile) ? "yes" : "no");
- qDebug() << "Support for GL 2.0 compat "<<( OGLSupports(2,0,false, QSurfaceFormat::CompatibilityProfile) ? "yes" : "no");
- qDebug() << "Support for GL 2.1 noprof "<<( OGLSupports(2,1,false) ? "yes" : "no");
- qDebug() << "Support for GL 2.1 core "<<( OGLSupports(2,1,false, QSurfaceFormat::CoreProfile) ? "yes" : "no");
- qDebug() << "Support for GL 2.1 compat "<<( OGLSupports(2,1,false, QSurfaceFormat::CompatibilityProfile) ? "yes" : "no");
- qDebug() << "Support for GL 3.0 noprof "<<( OGLSupports(3,0,false) ? "yes" : "no");
- qDebug() << "Support for GL 3.0 core "<<( OGLSupports(3,0,false, QSurfaceFormat::CoreProfile) ? "yes" : "no");
- qDebug() << "Support for GL 3.0 compat "<<( OGLSupports(3,0,false, QSurfaceFormat::CompatibilityProfile) ? "yes" : "no");
- qDebug() << "Support for GL 3.1 noprof "<<( OGLSupports(3,1,false) ? "yes" : "no");
- qDebug() << "Support for GL 3.1 core "<<( OGLSupports(3,1,false, QSurfaceFormat::CoreProfile) ? "yes" : "no");
- qDebug() << "Support for GL 3.1 compat "<<( OGLSupports(3,1,false, QSurfaceFormat::CompatibilityProfile) ? "yes" : "no");
- qDebug() << "Support for GL 3.2 core "<<( OGLSupports(3,2,false,QSurfaceFormat::CoreProfile) ? "yes" : "no");
- qDebug() << "Support for GL 3.2 compat "<<( OGLSupports(3,2,false,QSurfaceFormat::CompatibilityProfile) ? "yes" : "no");
- qDebug() << "Support for GL 3.3 core "<<( OGLSupports(3,3,false,QSurfaceFormat::CoreProfile) ? "yes" : "no");
- qDebug() << "Support for GL 3.3 compat "<<( OGLSupports(3,3,false,QSurfaceFormat::CompatibilityProfile) ? "yes" : "no");
- qDebug() << "Support for GL 4.0 core "<<( OGLSupports(4,0,false,QSurfaceFormat::CoreProfile) ? "yes" : "no");
- qDebug() << "Support for GL 4.0 compat "<<( OGLSupports(4,0,false,QSurfaceFormat::CompatibilityProfile) ? "yes" : "no");
- qDebug() << "Support for GL 4.1 core "<<( OGLSupports(4,1,false,QSurfaceFormat::CoreProfile) ? "yes" : "no");
- qDebug() << "Support for GL 4.1 compat "<<( OGLSupports(4,1,false,QSurfaceFormat::CompatibilityProfile) ? "yes" : "no");
- qDebug() << "Support for GL 4.2 core "<<( OGLSupports(4,2,false,QSurfaceFormat::CoreProfile) ? "yes" : "no");
- qDebug() << "Support for GL 4.2 compat "<<( OGLSupports(4,2,false,QSurfaceFormat::CompatibilityProfile) ? "yes" : "no");
- qDebug() << "Support for GL 4.3 core "<<( OGLSupports(4,3,false,QSurfaceFormat::CoreProfile) ? "yes" : "no");
- qDebug() << "Support for GL 4.3 compat "<<( OGLSupports(4,3,false,QSurfaceFormat::CompatibilityProfile) ? "yes" : "no");
- qDebug() << "Support for GL 4.4 core "<<( OGLSupports(4,4,false,QSurfaceFormat::CoreProfile) ? "yes" : "no");
- qDebug() << "Support for GL 4.4 compat "<<( OGLSupports(4,4,false,QSurfaceFormat::CompatibilityProfile) ? "yes" : "no");
- qDebug() << "Support for GL 4.5 core "<<( OGLSupports(4,5,false,QSurfaceFormat::CoreProfile) ? "yes" : "no");
- qDebug() << "Support for GL 4.5 compat "<<( OGLSupports(4,5,false,QSurfaceFormat::CompatibilityProfile) ? "yes" : "no");
- qDebug() << "Support for GLES 2.0 "<<( OGLSupports(2,0,true) ? "yes" : "no");
- qDebug() << "Support for GLES 3.0 "<<( OGLSupports(3,0,true) ? "yes" : "no");
- qDebug() << "Support for GLES 3.1 "<<( OGLSupports(3,1,true) ? "yes" : "no");
- qDebug() << "Support for GLES 3.2 "<<( OGLSupports(3,2,true) ? "yes" : "no");
-
- QSurfaceFormat fmt;
- fmt.setDepthBufferSize(24);
-
- // Request OpenGL ES 3.1 context, as this is a GLES example. If not available, go for OpenGL 4.3 core.
- if (OGLSupports(3,1,true)) {
- qDebug("Requesting 3.1 GLES context");
- fmt.setVersion(3, 1);
- fmt.setRenderableType(QSurfaceFormat::OpenGLES);
- } else if (OGLSupports(4,3,false,QSurfaceFormat::CoreProfile)) {
- qDebug("Requesting 4.3 core context");
- fmt.setVersion(4, 3);
- fmt.setRenderableType(QSurfaceFormat::OpenGL);
- fmt.setProfile(QSurfaceFormat::CoreProfile);
- } else {
- qWarning("Error: This system does not support OpenGL Compute Shaders! Exiting.");
- return -1;
- }
- QSurfaceFormat::setDefaultFormat(fmt);
-
- GLWindow glWindow;
- glWindow.showMaximized();
-
- return app.exec();
-}
diff --git a/examples/opengl/contextinfo/contextinfo.pro b/examples/opengl/contextinfo/contextinfo.pro
deleted file mode 100644
index 3d948dd282..0000000000
--- a/examples/opengl/contextinfo/contextinfo.pro
+++ /dev/null
@@ -1,14 +0,0 @@
-TEMPLATE = app
-QT += widgets
-requires(qtConfig(filedialog))
-
-SOURCES += main.cpp \
- widget.cpp \
- renderwindow.cpp
-
-HEADERS += widget.h \
- renderwindow.h
-
-# install
-target.path = $$[QT_INSTALL_EXAMPLES]/opengl/contextinfo
-INSTALLS += target
diff --git a/examples/opengl/contextinfo/main.cpp b/examples/opengl/contextinfo/main.cpp
deleted file mode 100644
index 88ab4a7334..0000000000
--- a/examples/opengl/contextinfo/main.cpp
+++ /dev/null
@@ -1,72 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the examples of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:BSD$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** BSD License Usage
-** Alternatively, you may use this file under the terms of the BSD license
-** as follows:
-**
-** "Redistribution and use in source and binary forms, with or without
-** modification, are permitted provided that the following conditions are
-** met:
-** * Redistributions of source code must retain the above copyright
-** notice, this list of conditions and the following disclaimer.
-** * Redistributions in binary form must reproduce the above copyright
-** notice, this list of conditions and the following disclaimer in
-** the documentation and/or other materials provided with the
-** distribution.
-** * 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.
-**
-**
-** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
-** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
-** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
-** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
-** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
-** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
-** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
-** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
-** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include <QApplication>
-#include "widget.h"
-
-int main(int argc, char **argv)
-{
- for (int i = 1; i < argc; ++i) {
- if (!qstrcmp(argv[i], "-g"))
- QCoreApplication::setAttribute(Qt::AA_UseOpenGLES);
- else if (!qstrcmp(argv[i], "-s"))
- QCoreApplication::setAttribute(Qt::AA_UseSoftwareOpenGL);
- else if (!qstrcmp(argv[i], "-d"))
- QCoreApplication::setAttribute(Qt::AA_UseDesktopOpenGL);
- }
-
- QApplication app(argc, argv);
-
- Widget w;
- w.resize(700, 800);
- w.show();
-
- return app.exec();
-}
diff --git a/examples/opengl/contextinfo/renderwindow.cpp b/examples/opengl/contextinfo/renderwindow.cpp
deleted file mode 100644
index ea9a7a24cb..0000000000
--- a/examples/opengl/contextinfo/renderwindow.cpp
+++ /dev/null
@@ -1,238 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the examples of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:BSD$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** BSD License Usage
-** Alternatively, you may use this file under the terms of the BSD license
-** as follows:
-**
-** "Redistribution and use in source and binary forms, with or without
-** modification, are permitted provided that the following conditions are
-** met:
-** * Redistributions of source code must retain the above copyright
-** notice, this list of conditions and the following disclaimer.
-** * Redistributions in binary form must reproduce the above copyright
-** notice, this list of conditions and the following disclaimer in
-** the documentation and/or other materials provided with the
-** distribution.
-** * 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.
-**
-**
-** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
-** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
-** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
-** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
-** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
-** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
-** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
-** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
-** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include "renderwindow.h"
-#include <QTimer>
-#include <QMatrix4x4>
-#include <QOpenGLContext>
-#include <QOpenGLShaderProgram>
-#include <QOpenGLFunctions>
-
-RenderWindow::RenderWindow(const QSurfaceFormat &format)
- : m_context(nullptr),
- m_initialized(false),
- m_forceGLSL110(false),
- m_angle(0.0f)
-{
- setSurfaceType(QWindow::OpenGLSurface);
- setFormat(format);
- m_context = new QOpenGLContext(this);
- m_context->setFormat(requestedFormat());
- if (!m_context->create()) {
- delete m_context;
- m_context = nullptr;
- }
-}
-
-void RenderWindow::exposeEvent(QExposeEvent *)
-{
- if (isExposed())
- render();
-}
-
-// ES needs the precision qualifiers.
-// On desktop GL QOpenGLShaderProgram inserts dummy defines for highp/mediump/lowp.
-static const char *vertexShaderSource110 =
- "attribute highp vec4 posAttr;\n"
- "attribute lowp vec4 colAttr;\n"
- "varying lowp vec4 col;\n"
- "uniform highp mat4 matrix;\n"
- "void main() {\n"
- " col = colAttr;\n"
- " gl_Position = matrix * posAttr;\n"
- "}\n";
-
-static const char *fragmentShaderSource110 =
- "varying lowp vec4 col;\n"
- "void main() {\n"
- " gl_FragColor = col;\n"
- "}\n";
-
-static const char *vertexShaderSource =
- "#version 150\n"
- "in vec4 posAttr;\n"
- "in vec4 colAttr;\n"
- "out vec4 col;\n"
- "uniform mat4 matrix;\n"
- "void main() {\n"
- " col = colAttr;\n"
- " gl_Position = matrix * posAttr;\n"
- "}\n";
-
-static const char *fragmentShaderSource =
- "#version 150\n"
- "in vec4 col;\n"
- "out vec4 fragColor;\n"
- "void main() {\n"
- " fragColor = col;\n"
- "}\n";
-
-static GLfloat vertices[] = {
- 0.0f, 0.707f,
- -0.5f, -0.5f,
- 0.5f, -0.5f
-};
-
-static GLfloat colors[] = {
- 1.0f, 0.0f, 0.0f,
- 0.0f, 1.0f, 0.0f,
- 0.0f, 0.0f, 1.0f
-};
-
-void RenderWindow::init()
-{
- m_program = new QOpenGLShaderProgram(this);
-
- QSurfaceFormat format = m_context->format();
- bool useNewStyleShader = format.profile() == QSurfaceFormat::CoreProfile;
- // Try to handle 3.0 & 3.1 that do not have the core/compatibility profile concept 3.2+ has.
- // This may still fail since version 150 (3.2) is specified in the sources but it's worth a try.
- if (format.renderableType() == QSurfaceFormat::OpenGL && format.majorVersion() == 3 && format.minorVersion() <= 1)
- useNewStyleShader = !format.testOption(QSurfaceFormat::DeprecatedFunctions);
- if (m_forceGLSL110)
- useNewStyleShader = false;
-
- const char *vsrc = useNewStyleShader ? vertexShaderSource : vertexShaderSource110;
- const char *fsrc = useNewStyleShader ? fragmentShaderSource : fragmentShaderSource110;
- qDebug("Using version %s shader", useNewStyleShader ? "150" : "110");
-
- if (!m_program->addShaderFromSourceCode(QOpenGLShader::Vertex, vsrc)) {
- emit error(m_program->log());
- return;
- }
- if (!m_program->addShaderFromSourceCode(QOpenGLShader::Fragment, fsrc)) {
- emit error(m_program->log());
- return;
- }
- if (!m_program->link()) {
- emit error(m_program->log());
- return;
- }
-
- m_posAttr = m_program->attributeLocation("posAttr");
- m_colAttr = m_program->attributeLocation("colAttr");
- m_matrixUniform = m_program->uniformLocation("matrix");
-
- m_vbo.create();
- m_vbo.bind();
- m_vbo.allocate(vertices, sizeof(vertices) + sizeof(colors));
- m_vbo.write(sizeof(vertices), colors, sizeof(colors));
- m_vbo.release();
-
- QOpenGLVertexArrayObject::Binder vaoBinder(&m_vao);
- if (m_vao.isCreated()) // have VAO support, use it
- setupVertexAttribs();
-}
-
-void RenderWindow::setupVertexAttribs()
-{
- m_vbo.bind();
- m_program->setAttributeBuffer(m_posAttr, GL_FLOAT, 0, 2);
- m_program->setAttributeBuffer(m_colAttr, GL_FLOAT, sizeof(vertices), 3);
- m_program->enableAttributeArray(m_posAttr);
- m_program->enableAttributeArray(m_colAttr);
- m_vbo.release();
-}
-
-bool RenderWindow::event(QEvent *ev)
-{
- if (ev->type() == QEvent::UpdateRequest)
- render();
- return QWindow::event(ev);
-}
-
-void RenderWindow::render()
-{
- if (!m_context->makeCurrent(this)) {
- emit error(tr("makeCurrent() failed"));
- return;
- }
-
- QOpenGLFunctions *f = m_context->functions();
- if (!m_initialized) {
- m_initialized = true;
- f->glEnable(GL_DEPTH_TEST);
- f->glClearColor(0, 0, 0, 1);
- init();
- emit ready();
- }
-
- if (!m_vbo.isCreated()) // init() failed, don't bother with trying to render
- return;
-
- const qreal retinaScale = devicePixelRatio();
- f->glViewport(0, 0, width() * retinaScale, height() * retinaScale);
- f->glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
-
- m_program->bind();
- QMatrix4x4 matrix;
- matrix.perspective(60.0f, 4.0f / 3.0f, 0.1f, 100.0f);
- matrix.translate(0.0f, 0.0f, -2.0f);
- matrix.rotate(m_angle, 0.0f, 1.0f, 0.0f);
- m_program->setUniformValue(m_matrixUniform, matrix);
-
- if (m_vao.isCreated())
- m_vao.bind();
- else // no VAO support, set the vertex attribute arrays now
- setupVertexAttribs();
-
- f->glDrawArrays(GL_TRIANGLES, 0, 3);
-
- m_vao.release();
- m_program->release();
-
- // swapInterval is 1 by default which means that swapBuffers() will (hopefully) block
- // and wait for vsync.
- m_context->swapBuffers(this);
-
- m_angle += 1.0f;
-
- requestUpdate();
-}
diff --git a/examples/opengl/contextinfo/renderwindow.h b/examples/opengl/contextinfo/renderwindow.h
deleted file mode 100644
index 1b4a79dfcf..0000000000
--- a/examples/opengl/contextinfo/renderwindow.h
+++ /dev/null
@@ -1,95 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the examples of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:BSD$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** BSD License Usage
-** Alternatively, you may use this file under the terms of the BSD license
-** as follows:
-**
-** "Redistribution and use in source and binary forms, with or without
-** modification, are permitted provided that the following conditions are
-** met:
-** * Redistributions of source code must retain the above copyright
-** notice, this list of conditions and the following disclaimer.
-** * Redistributions in binary form must reproduce the above copyright
-** notice, this list of conditions and the following disclaimer in
-** the documentation and/or other materials provided with the
-** distribution.
-** * 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.
-**
-**
-** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
-** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
-** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
-** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
-** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
-** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
-** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
-** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
-** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef RENDERWINDOW_H
-#define RENDERWINDOW_H
-
-#include <QWindow>
-#include <QOpenGLVertexArrayObject>
-#include <QOpenGLBuffer>
-
-QT_FORWARD_DECLARE_CLASS(QOpenGLContext)
-QT_FORWARD_DECLARE_CLASS(QOpenGLShaderProgram)
-
-class RenderWindow : public QWindow
-{
- Q_OBJECT
-
-public:
- RenderWindow(const QSurfaceFormat &format);
- QOpenGLContext *context() { return m_context; }
- void exposeEvent(QExposeEvent *) override;
- void setForceGLSL110(bool enable) { m_forceGLSL110 = enable; }
-
-signals:
- void ready();
- void error(const QString &msg);
-
-protected:
- bool event(QEvent *ev) override;
-
-private slots:
- void render();
-
-private:
- void init();
- void setupVertexAttribs();
-
- QOpenGLContext *m_context;
- bool m_initialized;
- bool m_forceGLSL110;
- QOpenGLShaderProgram *m_program;
- int m_posAttr, m_colAttr, m_matrixUniform;
- QOpenGLVertexArrayObject m_vao;
- QOpenGLBuffer m_vbo;
- float m_angle;
-};
-
-#endif // RENDERWINDOW_H
diff --git a/examples/opengl/contextinfo/widget.cpp b/examples/opengl/contextinfo/widget.cpp
deleted file mode 100644
index 0762c91662..0000000000
--- a/examples/opengl/contextinfo/widget.cpp
+++ /dev/null
@@ -1,400 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the examples of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:BSD$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** BSD License Usage
-** Alternatively, you may use this file under the terms of the BSD license
-** as follows:
-**
-** "Redistribution and use in source and binary forms, with or without
-** modification, are permitted provided that the following conditions are
-** met:
-** * Redistributions of source code must retain the above copyright
-** notice, this list of conditions and the following disclaimer.
-** * Redistributions in binary form must reproduce the above copyright
-** notice, this list of conditions and the following disclaimer in
-** the documentation and/or other materials provided with the
-** distribution.
-** * 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.
-**
-**
-** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
-** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
-** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
-** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
-** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
-** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
-** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
-** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
-** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include "widget.h"
-#include "renderwindow.h"
-#include <QVBoxLayout>
-#include <QComboBox>
-#include <QGroupBox>
-#include <QRadioButton>
-#include <QCheckBox>
-#include <QHBoxLayout>
-#include <QLabel>
-#include <QPushButton>
-#include <QTextEdit>
-#include <QSplitter>
-#include <QGuiApplication>
-#include <QSurfaceFormat>
-#include <QOpenGLContext>
-#include <QOpenGLFunctions>
-#include <QDebug>
-#include <QTextStream>
-
-struct Version {
- const char *str;
- int major;
- int minor;
-};
-
-static struct Version versions[] = {
- { "1.0", 1, 0 },
- { "1.1", 1, 1 },
- { "1.2", 1, 2 },
- { "1.3", 1, 3 },
- { "1.4", 1, 4 },
- { "1.5", 1, 5 },
- { "2.0", 2, 0 },
- { "2.1", 2, 1 },
- { "3.0", 3, 0 },
- { "3.1", 3, 1 },
- { "3.2", 3, 2 },
- { "3.3", 3, 3 },
- { "4.0", 4, 0 },
- { "4.1", 4, 1 },
- { "4.2", 4, 2 },
- { "4.3", 4, 3 },
- { "4.4", 4, 4 },
- { "4.5", 4, 5 }
-};
-
-struct Profile {
- const char *str;
- QSurfaceFormat::OpenGLContextProfile profile;
-};
-
-static struct Profile profiles[] = {
- { "none", QSurfaceFormat::NoProfile },
- { "core", QSurfaceFormat::CoreProfile },
- { "compatibility", QSurfaceFormat::CompatibilityProfile }
-};
-
-struct Option {
- const char *str;
- QSurfaceFormat::FormatOption option;
-};
-
-static struct Option options[] = {
- { "deprecated functions (not forward compatible)", QSurfaceFormat::DeprecatedFunctions },
- { "debug context", QSurfaceFormat::DebugContext },
- { "stereo buffers", QSurfaceFormat::StereoBuffers },
- // This is not a QSurfaceFormat option but is helpful to determine if the driver
- // allows compiling old-style shaders with core profile.
- { "force version 110 shaders", QSurfaceFormat::FormatOption(0) }
-};
-
-struct Renderable {
- const char *str;
- QSurfaceFormat::RenderableType renderable;
-};
-
-static struct Renderable renderables[] = {
- { "default", QSurfaceFormat::DefaultRenderableType },
- { "OpenGL", QSurfaceFormat::OpenGL },
- { "OpenGL ES", QSurfaceFormat::OpenGLES }
-};
-
-void Widget::addVersions(QLayout *layout)
-{
- QHBoxLayout *hbox = new QHBoxLayout;
- hbox->setSpacing(20);
- QLabel *label = new QLabel(tr("Context &version: "));
- hbox->addWidget(label);
- m_version = new QComboBox;
- m_version->setMinimumWidth(60);
- label->setBuddy(m_version);
- hbox->addWidget(m_version);
- for (size_t i = 0; i < sizeof(versions) / sizeof(Version); ++i) {
- m_version->addItem(QString::fromLatin1(versions[i].str));
- if (versions[i].major == 2 && versions[i].minor == 0)
- m_version->setCurrentIndex(m_version->count() - 1);
- }
-
- QPushButton *btn = new QPushButton(tr("Create context"));
- connect(btn, &QPushButton::clicked, this, &Widget::start);
- btn->setMinimumSize(120, 40);
- hbox->addWidget(btn);
-
- layout->addItem(hbox);
-}
-
-void Widget::addProfiles(QLayout *layout)
-{
- QGroupBox *groupBox = new QGroupBox(tr("Profile"));
- QVBoxLayout *vbox = new QVBoxLayout;
- for (size_t i = 0; i < sizeof(profiles) / sizeof(Profile); ++i)
- vbox->addWidget(new QRadioButton(QString::fromLatin1(profiles[i].str)));
- static_cast<QRadioButton *>(vbox->itemAt(0)->widget())->setChecked(true);
- groupBox->setLayout(vbox);
- layout->addWidget(groupBox);
- m_profiles = vbox;
-}
-
-void Widget::addOptions(QLayout *layout)
-{
- QGroupBox *groupBox = new QGroupBox(tr("Options"));
- QVBoxLayout *vbox = new QVBoxLayout;
- for (size_t i = 0; i < sizeof(options) / sizeof(Option); ++i)
- vbox->addWidget(new QCheckBox(QString::fromLatin1(options[i].str)));
- groupBox->setLayout(vbox);
- layout->addWidget(groupBox);
- m_options = vbox;
-}
-
-void Widget::addRenderableTypes(QLayout *layout)
-{
- QGroupBox *groupBox = new QGroupBox(tr("Renderable type"));
- QVBoxLayout *vbox = new QVBoxLayout;
- for (size_t i = 0; i < sizeof(renderables) / sizeof(Renderable); ++i)
- vbox->addWidget(new QRadioButton(QString::fromLatin1(renderables[i].str)));
- static_cast<QRadioButton *>(vbox->itemAt(0)->widget())->setChecked(true);
- groupBox->setLayout(vbox);
- layout->addWidget(groupBox);
- m_renderables = vbox;
-}
-
-void Widget::addRenderWindow()
-{
- m_renderWindowLayout->addWidget(m_renderWindowContainer);
-}
-
-static QWidget *widgetWithLayout(QLayout *layout)
-{
- QWidget *w = new QWidget;
- w->setLayout(layout);
- return w;
-}
-
-Widget::Widget(QWidget *parent)
- : QWidget(parent)
-{
- QVBoxLayout *layout = new QVBoxLayout;
- QSplitter *vsplit = new QSplitter(Qt::Vertical);
- layout->addWidget(vsplit);
-
- QSplitter *hsplit = new QSplitter;
-
- QVBoxLayout *settingsLayout = new QVBoxLayout;
- addVersions(settingsLayout);
- addProfiles(settingsLayout);
- addOptions(settingsLayout);
- addRenderableTypes(settingsLayout);
- hsplit->addWidget(widgetWithLayout(settingsLayout));
-
- QVBoxLayout *outputLayout = new QVBoxLayout;
- m_output = new QTextEdit;
- m_output->setReadOnly(true);
- outputLayout->addWidget(m_output);
- m_extensions = new QTextEdit;
- m_extensions->setReadOnly(true);
- outputLayout->addWidget(m_extensions);
- hsplit->addWidget(widgetWithLayout(outputLayout));
-
- hsplit->setStretchFactor(0, 4);
- hsplit->setStretchFactor(1, 6);
- vsplit->addWidget(hsplit);
-
- m_renderWindowLayout = new QVBoxLayout;
- vsplit->addWidget(widgetWithLayout(m_renderWindowLayout));
- vsplit->setStretchFactor(1, 5);
-
- m_renderWindowContainer = new QWidget;
- addRenderWindow();
-
- QString description;
- QTextStream str(&description);
- str << "Qt " << QT_VERSION_STR << ' ' << QGuiApplication::platformName();
- const char *openGlVariables[] =
- {"QT_ANGLE_PLATFORM", "QT_OPENGL", "QT_OPENGL_BUGLIST", "QT_OPENGL_DLL"};
- const size_t variableCount = sizeof(openGlVariables) / sizeof(openGlVariables[0]);
- for (size_t v = 0; v < variableCount; ++v) {
- if (qEnvironmentVariableIsSet(openGlVariables[v]))
- str << ' ' << openGlVariables[v] << '=' << qgetenv(openGlVariables[v]);
- }
- if (QCoreApplication::testAttribute(Qt::AA_UseOpenGLES))
- str << " Qt::AA_UseOpenGLES";
- if (QCoreApplication::testAttribute(Qt::AA_UseSoftwareOpenGL))
- str << " Qt::AA_UseSoftwareOpenGL";
- if (QCoreApplication::testAttribute(Qt::AA_UseDesktopOpenGL))
- str << " Qt::AA_UseDesktopOpenGL";
- layout->addWidget(new QLabel(description));
-
- setLayout(layout);
-}
-
-void Widget::start()
-{
- QSurfaceFormat fmt;
-
- int idx = m_version->currentIndex();
- if (idx < 0)
- return;
- fmt.setVersion(versions[idx].major, versions[idx].minor);
-
- for (size_t i = 0; i < sizeof(profiles) / sizeof(Profile); ++i)
- if (static_cast<QRadioButton *>(m_profiles->itemAt(int(i))->widget())->isChecked()) {
- fmt.setProfile(profiles[i].profile);
- break;
- }
-
- bool forceGLSL110 = false;
- for (size_t i = 0; i < sizeof(options) / sizeof(Option); ++i)
- if (static_cast<QCheckBox *>(m_options->itemAt(int(i))->widget())->isChecked()) {
- if (options[i].option)
- fmt.setOption(options[i].option);
- else if (i == 3)
- forceGLSL110 = true;
- }
-
- for (size_t i = 0; i < sizeof(renderables) / sizeof(Renderable); ++i)
- if (static_cast<QRadioButton *>(m_renderables->itemAt(int(i))->widget())->isChecked()) {
- fmt.setRenderableType(renderables[i].renderable);
- break;
- }
-
- // The example rendering will need a depth buffer.
- fmt.setDepthBufferSize(16);
-
- m_output->clear();
- m_extensions->clear();
- qDebug() << "Requesting surface format" << fmt;
-
- m_renderWindowLayout->removeWidget(m_renderWindowContainer);
- delete m_renderWindowContainer;
-
- RenderWindow *renderWindow = new RenderWindow(fmt);
- if (!renderWindow->context()) {
- m_output->append(tr("Failed to create context"));
- delete renderWindow;
- m_renderWindowContainer = new QWidget;
- addRenderWindow();
- return;
- }
- m_surface = renderWindow;
-
- renderWindow->setForceGLSL110(forceGLSL110);
- connect(renderWindow, &RenderWindow::ready, this, &Widget::renderWindowReady);
- connect(renderWindow, &RenderWindow::error, this, &Widget::renderWindowError);
-
- m_renderWindowContainer = QWidget::createWindowContainer(renderWindow);
- addRenderWindow();
-}
-
-void Widget::printFormat(const QSurfaceFormat &format)
-{
- m_output->append(tr("OpenGL version: %1.%2").arg(format.majorVersion()).arg(format.minorVersion()));
-
- for (size_t i = 0; i < sizeof(profiles) / sizeof(Profile); ++i)
- if (profiles[i].profile == format.profile()) {
- m_output->append(tr("Profile: %1").arg(QString::fromLatin1(profiles[i].str)));
- break;
- }
-
- QString opts;
- for (size_t i = 0; i < sizeof(options) / sizeof(Option); ++i)
- if (format.testOption(options[i].option))
- opts += QString::fromLatin1(options[i].str) + QLatin1Char(' ');
- m_output->append(tr("Options: %1").arg(opts));
-
- for (size_t i = 0; i < sizeof(renderables) / sizeof(Renderable); ++i)
- if (renderables[i].renderable == format.renderableType()) {
- m_output->append(tr("Renderable type: %1").arg(QString::fromLatin1(renderables[i].str)));
- break;
- }
-
- m_output->append(tr("Depth buffer size: %1").arg(QString::number(format.depthBufferSize())));
- m_output->append(tr("Stencil buffer size: %1").arg(QString::number(format.stencilBufferSize())));
- m_output->append(tr("Samples: %1").arg(QString::number(format.samples())));
- m_output->append(tr("Red buffer size: %1").arg(QString::number(format.redBufferSize())));
- m_output->append(tr("Green buffer size: %1").arg(QString::number(format.greenBufferSize())));
- m_output->append(tr("Blue buffer size: %1").arg(QString::number(format.blueBufferSize())));
- m_output->append(tr("Alpha buffer size: %1").arg(QString::number(format.alphaBufferSize())));
- m_output->append(tr("Swap interval: %1").arg(QString::number(format.swapInterval())));
-}
-
-void Widget::renderWindowReady()
-{
- QOpenGLContext *context = QOpenGLContext::currentContext();
- Q_ASSERT(context);
-
- QString vendor, renderer, version, glslVersion;
- const GLubyte *p;
- QOpenGLFunctions *f = context->functions();
- if ((p = f->glGetString(GL_VENDOR)))
- vendor = QString::fromLatin1(reinterpret_cast<const char *>(p));
- if ((p = f->glGetString(GL_RENDERER)))
- renderer = QString::fromLatin1(reinterpret_cast<const char *>(p));
- if ((p = f->glGetString(GL_VERSION)))
- version = QString::fromLatin1(reinterpret_cast<const char *>(p));
- if ((p = f->glGetString(GL_SHADING_LANGUAGE_VERSION)))
- glslVersion = QString::fromLatin1(reinterpret_cast<const char *>(p));
-
- m_output->append(tr("*** Context information ***"));
- m_output->append(tr("Vendor: %1").arg(vendor));
- m_output->append(tr("Renderer: %1").arg(renderer));
- m_output->append(tr("OpenGL version: %1").arg(version));
- m_output->append(tr("GLSL version: %1").arg(glslVersion));
-
- m_output->append(tr("\n*** QSurfaceFormat from context ***"));
- printFormat(context->format());
-
- m_output->append(tr("\n*** QSurfaceFormat from window surface ***"));
- printFormat(m_surface->format());
-
- m_output->append(tr("\n*** Qt build information ***"));
- const char *gltype[] = { "Desktop", "GLES 2", "GLES 1" };
- m_output->append(tr("Qt OpenGL configuration: %1")
- .arg(QString::fromLatin1(gltype[QOpenGLContext::openGLModuleType()])));
- m_output->append(tr("Qt OpenGL library handle: %1")
- .arg(QString::number(qintptr(QOpenGLContext::openGLModuleHandle()), 16)));
-
- QList<QByteArray> extensionList = context->extensions().values();
- std::sort(extensionList.begin(), extensionList.end());
- m_extensions->append(tr("Found %1 extensions:").arg(extensionList.count()));
- for (const QByteArray &ext : qAsConst(extensionList))
- m_extensions->append(QString::fromLatin1(ext));
-
- m_output->moveCursor(QTextCursor::Start);
- m_extensions->moveCursor(QTextCursor::Start);
-}
-
-void Widget::renderWindowError(const QString &msg)
-{
- m_output->append(tr("An error has occurred:\n%1").arg(msg));
-}
diff --git a/examples/opengl/contextinfo/widget.h b/examples/opengl/contextinfo/widget.h
deleted file mode 100644
index 85d181a229..0000000000
--- a/examples/opengl/contextinfo/widget.h
+++ /dev/null
@@ -1,93 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the examples of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:BSD$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** BSD License Usage
-** Alternatively, you may use this file under the terms of the BSD license
-** as follows:
-**
-** "Redistribution and use in source and binary forms, with or without
-** modification, are permitted provided that the following conditions are
-** met:
-** * Redistributions of source code must retain the above copyright
-** notice, this list of conditions and the following disclaimer.
-** * Redistributions in binary form must reproduce the above copyright
-** notice, this list of conditions and the following disclaimer in
-** the documentation and/or other materials provided with the
-** distribution.
-** * 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.
-**
-**
-** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
-** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
-** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
-** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
-** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
-** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
-** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
-** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
-** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef WIDGET_H
-#define WIDGET_H
-
-#include <QWidget>
-
-QT_FORWARD_DECLARE_CLASS(QComboBox)
-QT_FORWARD_DECLARE_CLASS(QTextEdit)
-QT_FORWARD_DECLARE_CLASS(QVBoxLayout)
-QT_FORWARD_DECLARE_CLASS(QSurfaceFormat)
-QT_FORWARD_DECLARE_CLASS(QSurface)
-
-class Widget : public QWidget
-{
- Q_OBJECT
-
-public:
- explicit Widget(QWidget *parent = nullptr);
-
-private slots:
- void start();
- void renderWindowReady();
- void renderWindowError(const QString &msg);
-
-private:
- void addVersions(QLayout *layout);
- void addProfiles(QLayout *layout);
- void addOptions(QLayout *layout);
- void addRenderableTypes(QLayout *layout);
- void addRenderWindow();
- void printFormat(const QSurfaceFormat &format);
-
- QComboBox *m_version;
- QLayout *m_profiles;
- QLayout *m_options;
- QLayout *m_renderables;
- QTextEdit *m_output;
- QTextEdit *m_extensions;
- QVBoxLayout *m_renderWindowLayout;
- QWidget *m_renderWindowContainer;
- QSurface *m_surface;
-};
-
-#endif // WIDGET_H
diff --git a/examples/opengl/cube/CMakeLists.txt b/examples/opengl/cube/CMakeLists.txt
new file mode 100644
index 0000000000..7486d058a4
--- /dev/null
+++ b/examples/opengl/cube/CMakeLists.txt
@@ -0,0 +1,65 @@
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
+
+cmake_minimum_required(VERSION 3.16)
+project(cube LANGUAGES CXX)
+
+find_package(Qt6 REQUIRED COMPONENTS Core Gui OpenGL OpenGLWidgets Widgets)
+
+qt_standard_project_setup()
+
+qt_add_executable(cube
+ geometryengine.cpp geometryengine.h
+ main.cpp
+ mainwidget.cpp mainwidget.h
+)
+
+set_target_properties(cube PROPERTIES
+ WIN32_EXECUTABLE TRUE
+ MACOSX_BUNDLE TRUE
+)
+
+target_link_libraries(cube PRIVATE
+ Qt6::Core
+ Qt6::Gui
+ Qt6::OpenGL
+ Qt6::OpenGLWidgets
+ Qt6::Widgets
+)
+
+# Resources:
+set(shaders_resource_files
+ "fshader.glsl"
+ "vshader.glsl"
+)
+
+qt6_add_resources(cube "shaders"
+ PREFIX
+ "/"
+ FILES
+ ${shaders_resource_files}
+)
+
+set(textures_resource_files
+ "cube.png"
+)
+
+qt6_add_resources(cube "textures"
+ PREFIX
+ "/"
+ FILES
+ ${textures_resource_files}
+)
+
+install(TARGETS cube
+ BUNDLE DESTINATION .
+ RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
+ LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
+)
+
+qt_generate_deploy_app_script(
+ TARGET cube
+ OUTPUT_SCRIPT deploy_script
+ NO_UNSUPPORTED_PLATFORM_ERROR
+)
+install(SCRIPT ${deploy_script})
diff --git a/examples/opengl/cube/cube.png b/examples/opengl/cube/cube.png
index 42c8c51b3a..c3abbfe84d 100644
--- a/examples/opengl/cube/cube.png
+++ b/examples/opengl/cube/cube.png
Binary files differ
diff --git a/examples/opengl/cube/cube.pro b/examples/opengl/cube/cube.pro
index 07724e247e..95a411322a 100644
--- a/examples/opengl/cube/cube.pro
+++ b/examples/opengl/cube/cube.pro
@@ -1,4 +1,4 @@
-QT += core gui widgets opengl
+QT += core gui widgets opengl openglwidgets
TARGET = cube
TEMPLATE = app
diff --git a/examples/opengl/cube/fshader.glsl b/examples/opengl/cube/fshader.glsl
index 18068cf0e6..0c056b6165 100644
--- a/examples/opengl/cube/fshader.glsl
+++ b/examples/opengl/cube/fshader.glsl
@@ -1,3 +1,5 @@
+// Copyright (C) 2024 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
#ifdef GL_ES
// Set default precision to medium
precision mediump int;
diff --git a/examples/opengl/cube/geometryengine.cpp b/examples/opengl/cube/geometryengine.cpp
index 24e014201e..0e673b84d3 100644
--- a/examples/opengl/cube/geometryengine.cpp
+++ b/examples/opengl/cube/geometryengine.cpp
@@ -1,52 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtCore module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:BSD$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** BSD License Usage
-** Alternatively, you may use this file under the terms of the BSD license
-** as follows:
-**
-** "Redistribution and use in source and binary forms, with or without
-** modification, are permitted provided that the following conditions are
-** met:
-** * Redistributions of source code must retain the above copyright
-** notice, this list of conditions and the following disclaimer.
-** * Redistributions in binary form must reproduce the above copyright
-** notice, this list of conditions and the following disclaimer in
-** the documentation and/or other materials provided with the
-** distribution.
-** * 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.
-**
-**
-** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
-** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
-** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
-** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
-** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
-** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
-** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
-** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
-** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
#include "geometryengine.h"
diff --git a/examples/opengl/cube/geometryengine.h b/examples/opengl/cube/geometryengine.h
index 36f7797d16..d1e34b7f93 100644
--- a/examples/opengl/cube/geometryengine.h
+++ b/examples/opengl/cube/geometryengine.h
@@ -1,52 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtCore module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:BSD$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** BSD License Usage
-** Alternatively, you may use this file under the terms of the BSD license
-** as follows:
-**
-** "Redistribution and use in source and binary forms, with or without
-** modification, are permitted provided that the following conditions are
-** met:
-** * Redistributions of source code must retain the above copyright
-** notice, this list of conditions and the following disclaimer.
-** * Redistributions in binary form must reproduce the above copyright
-** notice, this list of conditions and the following disclaimer in
-** the documentation and/or other materials provided with the
-** distribution.
-** * 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.
-**
-**
-** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
-** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
-** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
-** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
-** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
-** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
-** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
-** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
-** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
#ifndef GEOMETRYENGINE_H
#define GEOMETRYENGINE_H
diff --git a/examples/opengl/cube/main.cpp b/examples/opengl/cube/main.cpp
index 0134387ebd..c5c77d3d5b 100644
--- a/examples/opengl/cube/main.cpp
+++ b/examples/opengl/cube/main.cpp
@@ -1,52 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtCore module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:BSD$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** BSD License Usage
-** Alternatively, you may use this file under the terms of the BSD license
-** as follows:
-**
-** "Redistribution and use in source and binary forms, with or without
-** modification, are permitted provided that the following conditions are
-** met:
-** * Redistributions of source code must retain the above copyright
-** notice, this list of conditions and the following disclaimer.
-** * Redistributions in binary form must reproduce the above copyright
-** notice, this list of conditions and the following disclaimer in
-** the documentation and/or other materials provided with the
-** distribution.
-** * 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.
-**
-**
-** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
-** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
-** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
-** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
-** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
-** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
-** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
-** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
-** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
#include <QApplication>
#include <QLabel>
diff --git a/examples/opengl/cube/mainwidget.cpp b/examples/opengl/cube/mainwidget.cpp
index 558ecd1299..e67c93da5a 100644
--- a/examples/opengl/cube/mainwidget.cpp
+++ b/examples/opengl/cube/mainwidget.cpp
@@ -1,52 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtCore module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:BSD$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** BSD License Usage
-** Alternatively, you may use this file under the terms of the BSD license
-** as follows:
-**
-** "Redistribution and use in source and binary forms, with or without
-** modification, are permitted provided that the following conditions are
-** met:
-** * Redistributions of source code must retain the above copyright
-** notice, this list of conditions and the following disclaimer.
-** * Redistributions in binary form must reproduce the above copyright
-** notice, this list of conditions and the following disclaimer in
-** the documentation and/or other materials provided with the
-** distribution.
-** * 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.
-**
-**
-** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
-** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
-** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
-** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
-** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
-** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
-** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
-** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
-** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
#include "mainwidget.h"
@@ -68,13 +21,13 @@ MainWidget::~MainWidget()
void MainWidget::mousePressEvent(QMouseEvent *e)
{
// Save mouse press position
- mousePressPosition = QVector2D(e->localPos());
+ mousePressPosition = QVector2D(e->position());
}
void MainWidget::mouseReleaseEvent(QMouseEvent *e)
{
// Mouse release position - mouse press position
- QVector2D diff = QVector2D(e->localPos()) - mousePressPosition;
+ QVector2D diff = QVector2D(e->position()) - mousePressPosition;
// Rotation axis is perpendicular to the mouse position difference
// vector
@@ -119,14 +72,6 @@ void MainWidget::initializeGL()
initShaders();
initTextures();
-//! [2]
- // Enable depth buffer
- glEnable(GL_DEPTH_TEST);
-
- // Enable back face culling
- glEnable(GL_CULL_FACE);
-//! [2]
-
geometries = new GeometryEngine;
// Use QBasicTimer because its faster than QTimer
@@ -194,7 +139,16 @@ void MainWidget::paintGL()
// Clear color and depth buffer
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
+//! [2]
+ // Enable depth buffer
+ glEnable(GL_DEPTH_TEST);
+
+ // Enable back face culling
+ glEnable(GL_CULL_FACE);
+//! [2]
+
texture->bind();
+ program.bind();
//! [6]
// Calculate model view transformation
diff --git a/examples/opengl/cube/mainwidget.h b/examples/opengl/cube/mainwidget.h
index b6a03d454a..fd5dc5612b 100644
--- a/examples/opengl/cube/mainwidget.h
+++ b/examples/opengl/cube/mainwidget.h
@@ -1,52 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtCore module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:BSD$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** BSD License Usage
-** Alternatively, you may use this file under the terms of the BSD license
-** as follows:
-**
-** "Redistribution and use in source and binary forms, with or without
-** modification, are permitted provided that the following conditions are
-** met:
-** * Redistributions of source code must retain the above copyright
-** notice, this list of conditions and the following disclaimer.
-** * Redistributions in binary form must reproduce the above copyright
-** notice, this list of conditions and the following disclaimer in
-** the documentation and/or other materials provided with the
-** distribution.
-** * 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.
-**
-**
-** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
-** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
-** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
-** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
-** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
-** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
-** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
-** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
-** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
#ifndef MAINWIDGET_H
#define MAINWIDGET_H
diff --git a/examples/opengl/cube/vshader.glsl b/examples/opengl/cube/vshader.glsl
index cfdc061852..ac57d96285 100644
--- a/examples/opengl/cube/vshader.glsl
+++ b/examples/opengl/cube/vshader.glsl
@@ -1,3 +1,5 @@
+// Copyright (C) 2024 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
#ifdef GL_ES
// Set default precision to medium
precision mediump int;
diff --git a/examples/opengl/hellogles3/doc/images/hellogles3-example.png b/examples/opengl/doc/images/hellogles3-example.png
index e089b9470a..e089b9470a 100644
--- a/examples/opengl/hellogles3/doc/images/hellogles3-example.png
+++ b/examples/opengl/doc/images/hellogles3-example.png
Binary files differ
diff --git a/examples/opengl/doc/images/stereoexample-leftbuffer.png b/examples/opengl/doc/images/stereoexample-leftbuffer.png
new file mode 100644
index 0000000000..6ae7d5118b
--- /dev/null
+++ b/examples/opengl/doc/images/stereoexample-leftbuffer.png
Binary files differ
diff --git a/examples/opengl/doc/images/stereoexample-rightbuffer.png b/examples/opengl/doc/images/stereoexample-rightbuffer.png
new file mode 100644
index 0000000000..3e2dc3c671
--- /dev/null
+++ b/examples/opengl/doc/images/stereoexample-rightbuffer.png
Binary files differ
diff --git a/examples/opengl/doc/src/2dpainting.qdoc b/examples/opengl/doc/src/2dpainting.qdoc
index e6b33e2a14..5196c78937 100644
--- a/examples/opengl/doc/src/2dpainting.qdoc
+++ b/examples/opengl/doc/src/2dpainting.qdoc
@@ -1,37 +1,14 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the documentation of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:FDL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Free Documentation License Usage
-** Alternatively, this file may be used under the terms of the GNU Free
-** Documentation License version 1.3 as published by the Free Software
-** Foundation and appearing in the file included in the packaging of
-** this file. Please review the following information to ensure
-** the GNU Free Documentation License version 1.3 requirements
-** will be met: https://www.gnu.org/licenses/fdl-1.3.html.
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GFDL-1.3-no-invariants-only
/*!
\example 2dpainting
\title 2D Painting Example
\ingroup examples-widgets-opengl
+ \examplecategory {Graphics}
- \brief The 2D Painting example shows how QPainter and QGLWidget can be used
- together to display accelerated 2D graphics on supported hardware.
+ \brief The 2D Painting example shows how QPainter and QOpenGLWidget can be
+ used together to display accelerated 2D graphics on supported hardware.
\image 2dpainting-example.png
@@ -39,23 +16,23 @@
paint devices provided by QPaintDevice subclasses, such as QWidget
and QImage.
- Since QGLWidget is a subclass of QWidget, it is possible
+ Since QOpenGLWidget is a subclass of QWidget, it is possible
to reimplement its \l{QWidget::paintEvent()}{paintEvent()} and use
QPainter to draw on the device, just as you would with a QWidget.
The only difference is that the painting operations will be accelerated
in hardware if it is supported by your system's OpenGL drivers.
In this example, we perform the same painting operations on a
- QWidget and a QGLWidget. The QWidget is shown with anti-aliasing
- enabled, and the QGLWidget will also use anti-aliasing if the
+ QWidget and a QOpenGLWidget. The QWidget is shown with anti-aliasing
+ enabled, and the QOpenGLWidget will also use anti-aliasing if the
required extensions are supported by your system's OpenGL driver.
\section1 Overview
- To be able to compare the results of painting onto a QGLWidget subclass
+ To be able to compare the results of painting onto a QOpenGLWidget subclass
with native drawing in a QWidget subclass, we want to show both kinds
of widget side by side. To do this, we derive subclasses of QWidget and
- QGLWidget, using a separate \c Helper class to perform the same painting
+ QOpenGLWidget, using a separate \c Helper class to perform the same painting
operations for each, and lay them out in a top-level widget, itself
provided a the \c Window class.
@@ -63,7 +40,7 @@
In this example, the painting operations are performed by a helper class.
We do this because we want the same painting operations to be performed
- for both our QWidget subclass and the QGLWidget subclass.
+ for both our QWidget subclass and the QOpenGLWidget subclass.
The \c Helper class is minimal:
@@ -81,7 +58,7 @@
The actual painting is performed in the \c paint() function. This takes
a QPainter that has already been set up to paint onto a paint device
- (either a QWidget or a QGLWidget), a QPaintEvent that provides information
+ (either a QWidget or a QOpenGLWidget), a QPaintEvent that provides information
about the region to be painted, and a measure of the elapsed time (in
milliseconds) since the paint device was last updated.
@@ -148,7 +125,7 @@
\section1 GLWidget Class Definition
The \c GLWidget class definition is basically the same as the \c Widget
- class except that it is derived from QGLWidget.
+ class except that it is derived from QOpenGLWidget.
\snippet 2dpainting/glwidget.h 0
@@ -161,11 +138,8 @@
\snippet 2dpainting/glwidget.cpp 0
- As well as initializing the \c elapsed member variable and storing the
- \c Helper object used to paint the widget, the base class's constructor
- is called with the format that specifies the \l QGL::SampleBuffers flag.
- This enables anti-aliasing if it is supported by your system's OpenGL
- driver.
+ The \c elapsed member variable is initialized and the \c Helper object used
+ to paint the widget is stored.
The \c animate() slot is exactly the same as that provided by the \c Widget
class:
diff --git a/examples/opengl/doc/src/cube.qdoc b/examples/opengl/doc/src/cube.qdoc
index 1fdfe0c6ec..d01985701c 100644
--- a/examples/opengl/doc/src/cube.qdoc
+++ b/examples/opengl/doc/src/cube.qdoc
@@ -1,39 +1,18 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the documentation of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:FDL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Free Documentation License Usage
-** Alternatively, this file may be used under the terms of the GNU Free
-** Documentation License version 1.3 as published by the Free Software
-** Foundation and appearing in the file included in the packaging of
-** this file. Please review the following information to ensure
-** the GNU Free Documentation License version 1.3 requirements
-** will be met: https://www.gnu.org/licenses/fdl-1.3.html.
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2020 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GFDL-1.3-no-invariants-only
/*!
\example cube
\ingroup examples-widgets-opengl
\title Cube OpenGL ES 2.0 example
+ \examplecategory {3D}
- \brief The Cube OpenGL ES 2.0 example shows how to write mouse rotateable
- textured 3D cube using OpenGL ES 2.0 with Qt. It shows how to handle
- polygon geometries efficiently and how to write simple vertex and
- fragment shader for programmable graphics pipeline. In addition it
+ \brief Shows how to manually rotate a textured 3D cube with user input.
+
+ The Cube OpenGL ES 2.0 example shows how to manually rotate a textured 3D
+ cube with user input, using OpenGL ES 2.0 with Qt. It shows how to
+ handle polygon geometries efficiently and how to write a simple vertex and
+ fragment shader for a programmable graphics pipeline. In addition it
shows how to use quaternions for representing 3D object orientation.
This example has been written for OpenGL ES 2.0 but it works also on
@@ -47,7 +26,7 @@
The example consist of two classes:
\list
- \li \c MainWidget extends QGLWidget and contains OpenGL ES 2.0
+ \li \c MainWidget extends QOpenGLWidget and contains OpenGL ES 2.0
initialization and drawing and mouse and timer event handling
\li \c GeometryEngine handles polygon geometries. Transfers polygon geometry
to vertex buffer objects and draws geometries from vertex buffer objects.
@@ -81,7 +60,7 @@
\snippet cube/fshader.glsl 0
- Using \c QGLShaderProgram we can compile, link and bind shader code to
+ Using QOpenGLShaderProgram we can compile, link and bind shader code to
graphics pipeline. This code uses Qt Resource files to access shader source code.
\snippet cube/mainwidget.cpp 3
@@ -92,9 +71,9 @@
\section1 Loading Textures from Qt Resource Files
- \c QGLWidget interface implements methods for loading textures from QImage to GL
- texture memory. We still need to use OpenGL provided functions for specifying
- the GL texture unit and configuring texture filtering options.
+ The \c QOpenGLWidget interface implements methods for loading textures from QImage
+ to OpenGL texture memory. We still need to use OpenGL provided functions for
+ specifying the OpenGL texture unit and configuring texture filtering options.
\snippet cube/mainwidget.cpp 4
diff --git a/examples/opengl/doc/src/hellogl2.qdoc b/examples/opengl/doc/src/hellogl2.qdoc
index 2fb2e22e0b..29e8ef85cd 100644
--- a/examples/opengl/doc/src/hellogl2.qdoc
+++ b/examples/opengl/doc/src/hellogl2.qdoc
@@ -1,34 +1,11 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the documentation of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:FDL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Free Documentation License Usage
-** Alternatively, this file may be used under the terms of the GNU Free
-** Documentation License version 1.3 as published by the Free Software
-** Foundation and appearing in the file included in the packaging of
-** this file. Please review the following information to ensure
-** the GNU Free Documentation License version 1.3 requirements
-** will be met: https://www.gnu.org/licenses/fdl-1.3.html.
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GFDL-1.3-no-invariants-only
/*!
\example hellogl2
\title Hello GL2 Example
\ingroup examples-widgets-opengl
+ \examplecategory {3D}
\brief The Hello GL2 example demonstrates the basic use of the OpenGL-related classes
provided with Qt.
diff --git a/examples/opengl/doc/src/hellogles3.qdoc b/examples/opengl/doc/src/hellogles3.qdoc
new file mode 100644
index 0000000000..d85f40a29f
--- /dev/null
+++ b/examples/opengl/doc/src/hellogles3.qdoc
@@ -0,0 +1,149 @@
+// Copyright (C) 2018 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GFDL-1.3-no-invariants-only
+
+/*!
+ \example hellogles3
+ \title Hello GLES3 Example
+ \ingroup examples-widgets-opengl
+ \examplecategory {Graphics}
+ \examplecategory {Mobile}
+
+ \brief Demonstrates OpenGL ES 3.0 functions via QOpenGLExtraFunctions.
+
+ \image hellogles3-example.png
+ \section1 Overview
+
+ This example demonstrates easy, cross-platform usage of OpenGL ES 3.0
+ functions via QOpenGLExtraFunctions in an application that
+ works identically on desktop platforms with OpenGL 3.3 and mobile/embedded
+ devices with OpenGL ES 3.0.
+
+ This example has no QWidget dependencies, it uses QOpenGLWindow, a
+ convenience subclass of QWindow that allows easy implementation of windows
+ that contain OpenGL-rendered content. In this sense it complements the
+ \l{OpenGL Window Example}, which shows the implementation of an OpenGL-based
+ QWindow without using the convenience subclass.
+
+ The Qt logo shape implementation is included from the \l{Hello GL2 Example}.
+
+ In other aspects pertaining to using OpenGL there are the following
+ differences.
+
+ \list
+ \li The OpenGL context creation has to have a sufficiently high version
+ number for the features that are in use.
+ \li The shader's version directive is different.
+ \endlist
+
+ \section1 Setting up in main.cpp
+
+ Here we instantiate our QGuiApplication, QSurfaceformat and set its
+ \l{QSurfaceFormat::depthBufferSize()}{depth buffer size}:
+
+ \quotefromfile hellogles3/main.cpp
+ \skipto int main(int argc, char *argv[])
+ \printuntil fmt.setDepthBufferSize(24);
+
+ We request an OpenGL 3.3 core or OpenGL ES 3.0 context, depending on
+ QOpenGLContext::openGLModuleType():
+
+ \skipto if (QOpenGLContext::openGLModuleType() == QOpenGLContext::LibGL) {
+ \printuntil QSurfaceFormat::setDefaultFormat(fmt);
+
+ We set the default surface format and instantiate our GLWindow \c glWindow.
+
+ \section1 Implementing GLWindow
+
+ This class delivers the features of the example application.
+
+ To start, \c GLWindow is declared by implementing a subclass of
+ QOpenGLWindow:
+
+ \quotefromfile hellogles3/glwindow.h
+ \skipto class GLWindow : public QOpenGLWindow
+ \printto {
+
+ The following properties are declared using Q_PROPERTY:
+
+ \printto public:
+
+ The following public functions are declared:
+
+ \printto private slots:
+
+ The following private objects are declared:
+
+ \printto };
+
+ On the implementation side, those functions that are not declared inline are
+ implemented (or re-implemented) in \c{glwindow.cpp}. The following selections
+ will cover implementation particulars pertaining to the use of OpenGL ES 3.0.
+
+ \section2 Animations
+
+ The following code pertains to the animations, and won't be explored here:
+
+ \quotefromfile hellogles3/glwindow.cpp
+ \skipto GLWindow::GLWindow()
+ \printto static const char *vertexShaderSource =
+
+ For more information see the documentation for \l QPropertyAnimation,
+ \l QSequentialAnimationGroup.
+
+ \section2 Shaders
+ The shaders are defined like so:
+
+ \printto QByteArray versionedShaderCode(const char *src)
+
+ \note These are OpenGL version agnostic. We take this and append
+ the version like so:
+
+ \printto void GLWindow::initializeGL()
+
+ \section2 Initializing OpenGL
+
+ Initializing the shader program in handled by \c initializeGL():
+
+ \printuntil m_program = new QOpenGLShaderProgram;
+ \skipto m_program->addShaderFromSourceCode(QOpenGLShader::Vertex, versionedShaderCode(vertexShaderSource));
+
+ Now the OpenGL version is prepended and the various matrices and light
+ position is set:
+
+ \printuntil m_lightPosLoc = m_program->uniformLocation("lightPos");
+
+ While not strictly required for ES 3, a vertex array object is created.
+
+ \skipto delete m_vao;
+ \printuntil f->glEnable(GL_CULL_FACE);
+
+ \section2 Resizing the window
+
+ The perspective needs to be aligned with the new window size as so:
+
+ \skipto void GLWindow::resizeGL(int w, int h)
+ \printto void GLWindow::paintGL()
+
+ \section2 Painting
+
+ We use QOpenGLExtraFunctions instead of QOpenGLFunctions as we want to
+ do more than what GL(ES) 2.0 offers:
+
+ \printuntil QOpenGLExtraFunctions *f = QOpenGLContext::currentContext()->extraFunctions();
+
+ We clear the screen and buffers and bind our shader program and texture:
+
+ \printuntil m_texture->bind();
+
+ Logic for handling an initial \c paintGL() call or a call after a
+ \c resizeGL() call is implemented like so:
+
+ \printuntil }
+
+ Last, we demonstrate a function introduced in OpenGL 3.1 or OpenGL ES 3.0:
+
+ \skipto f->glDrawArraysInstanced(GL_TRIANGLES, 0, m_logo.vertexCount(), 32 * 36);
+ \printuntil }
+
+ This works because we earlier requested 3.3 or 3.0 context.
+*/
diff --git a/examples/opengl/doc/src/openglwindow.qdoc b/examples/opengl/doc/src/openglwindow.qdoc
new file mode 100644
index 0000000000..cade2f009a
--- /dev/null
+++ b/examples/opengl/doc/src/openglwindow.qdoc
@@ -0,0 +1,138 @@
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GFDL-1.3-no-invariants-only
+
+/*!
+ \example openglwindow
+ \title OpenGL Window Example
+ \ingroup examples-widgets-opengl
+ \examplecategory {Graphics}
+
+ \brief This example shows how to create a minimal QWindow based application
+ for the purpose of using OpenGL.
+
+ \image openglwindow-example.png Screenshot of the OpenGLWindow example
+
+ \note This is a low level example of how to use QWindow with OpenGL.
+ In practice you should consider using the higher level QOpenGLWindow class.
+ See the \l{Hello GLES3 Example} for a demonstration of the QOpenGLWindow
+ convenience class.
+
+ \section1 OpenGLWindow Super Class
+
+ Our OpenGLWindow class acts as an API which is then subclassed to do the
+ actual rendering. It has functions to make a request for render() to be
+ called, either immediately with renderNow() or as soon as the event loop
+ has finished processing the current batch of events with renderLater().
+ The OpenGLWindow subclass can either reimplement render() for OpenGL based
+ rendering, or render(QPainter *) for rendering with a QPainter. Use
+ OpenGLWindow::setAnimating(true) for render() to be called at the vertical
+ refresh rate, assuming vertical sync is enabled in the underlying OpenGL
+ drivers.
+
+ In the class that does the OpenGL rendering you will typically want to
+ inherit from QOpenGLFunctions, as our OpenGLWindow does, in order to get
+ platform independent access to OpenGL ES 2.0 functions. By inheriting from
+ QOpenGLFunctions the OpenGL functions it contains will get precedence, and
+ you will not have to worry about resolving those functions if you want your
+ application to work with OpenGL as well as OpenGL ES 2.0.
+
+ \snippet openglwindow/openglwindow.h 1
+
+ The window's surface type must be set to QSurface::OpenGLSurface to
+ indicate that the window is to be used for OpenGL rendering and not for
+ rendering raster content with QPainter using a QBackingStore.
+
+ \snippet openglwindow/openglwindow.cpp 1
+
+ Any OpenGL initialization needed can be done by overriding the initialize()
+ function, which is called once before the first call to render(), with a
+ valid current QOpenGLContext. As can be seen in the following code snippet,
+ the default render(QPainter *) and initialize() implementations are empty,
+ whereas the default render() implementation initializes a
+ QOpenGLPaintDevice and then calls into render(QPainter *).
+
+ \snippet openglwindow/openglwindow.cpp 2
+
+ The renderLater() function simply calls QWindow::requestUpdate() to schedule
+ an update for when the system is ready to repaint.
+
+ We also call renderNow() when we get an expose event. The exposeEvent() is
+ the notification to the window that its exposure, meaning visibility, on
+ the screen has changed. When the expose event is received you can query
+ QWindow::isExposed() to find out whether or not the window is currently
+ exposed. Do not render to or call QOpenGLContext::swapBuffers() on a window
+ before it has received its first expose event, as before then its final
+ size might be unknown, and in addition what is rendered might not even end
+ up on the screen.
+
+ \snippet openglwindow/openglwindow.cpp 3
+
+ In renderNow() we return if we are not currently exposed, in which case
+ rendering is delayed until we actually get an expose event. If we have not
+ yet done so, we create the QOpenGLContext with the same QSurfaceFormat as
+ was set on the OpenGLWindow, and call initialize() for the sake of the sub
+ class, and initializeOpenGLFunctions() in order for the QOpenGLFunctions
+ super class to be associated with the correct QOpenGLContext. In any case
+ we make the context current by calling QOpenGLContext::makeCurrent(), call
+ render() to do the actual rendering, and finally we schedule for the
+ rendered contents to be made visible by calling
+ QOpenGLContext::swapBuffers() with the OpenGLWindow as parameter.
+
+ Once the rendering of a frame using an OpenGL context is initiated by
+ calling QOpenGLContext::makeCurrent(), giving the surface on which to
+ render as a parameter, OpenGL commands can be issued. The commands can be
+ issued either directly by including <qopengl.h>, which also includes the
+ system's OpenGL headers, or as by using QOpenGLFunctions, which can
+ either be inherited from for convenience, or accessed using
+ QOpenGLContext::functions(). QOpenGLFunctions gives access to all the
+ OpenGL ES 2.0 level OpenGL calls that are not already standard in both
+ OpenGL ES 2.0 and desktop OpenGL. For more information about the OpenGL and
+ OpenGL ES APIs, refer to the official \l{http://www.opengl.org/registry/}{OpenGL Registry} and
+ \l {http://www.khronos.org/registry/gles/}{Khronos OpenGL ES API Registry}.
+
+ If animation has been enabled with OpenGLWindow::setAnimating(true), we
+ call renderLater() to schedule another update request.
+
+ \snippet openglwindow/openglwindow.cpp 4
+
+ Enabling animation also schedules an update request as shown in the
+ following code snippet.
+
+ \snippet openglwindow/openglwindow.cpp 5
+
+ \section1 Example OpenGL Rendering Sub Class
+
+ Here we sub class OpenGLWindow to show how to do OpenGL to render a
+ rotating triangle. By indirectly sub classing QOpenGLFunctions we gain
+ access to all OpenGL ES 2.0 level functionality.
+
+ \snippet openglwindow/main.cpp 1
+
+ In our main function we initialize QGuiApplication and instantiate our
+ TriangleOpenGLWindow. We give it a QSurfaceFormat specifying that we want
+ four samples of multisample antialiasing, as well as a default geometry.
+ Since we want to have animation we call the above mentioned setAnimating()
+ function with an argument of true.
+
+ \snippet openglwindow/main.cpp 2
+
+ The following code snippet shows the OpenGL shader program used in this
+ example. The vertex and fragment shaders are relatively simple, doing
+ vertex transformation and interpolated vertex coloring.
+
+ \snippet openglwindow/main.cpp 3
+
+ Here is the code that loads the shaders and initializes the shader program
+ By using QOpenGLShaderProgram instead of raw OpenGL we get the convenience
+ that strips out the highp, mediump, and lowp qualifiers on desktop OpenGL,
+ where they are not part of the standard. We store the attribute and uniform
+ locations in member variables to avoid having to do the location lookup
+ each frame.
+
+ \snippet openglwindow/main.cpp 4
+
+ Finally, here is our render() function, where we use OpenGL to set up the
+ viewport, clear the background, and render a rotating triangle.
+
+ \snippet openglwindow/main.cpp 5
+*/
diff --git a/examples/opengl/doc/src/stereoqopenglwidget.qdoc b/examples/opengl/doc/src/stereoqopenglwidget.qdoc
new file mode 100644
index 0000000000..0cb45b9808
--- /dev/null
+++ b/examples/opengl/doc/src/stereoqopenglwidget.qdoc
@@ -0,0 +1,46 @@
+// Copyright (C) 2022 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GFDL-1.3-no-invariants-only
+
+/*!
+ \example stereoqopenglwidget
+ \title QOpenGLWidget Stereoscopic Rendering Example
+ \examplecategory {Graphics}
+ \ingroup examples-widgets-opengl
+ \brief This example shows how to create a minimal QOpenGLWidget based
+ application with stereoscopic rendering support.
+
+ \note Support for stereoscopic rendering has certain hardware requirements,
+ such as, a graphics card with stereo support, 3D glasses and specific
+ monitors.
+
+ \note This example renders two images to two separate buffers. When you
+ view the images through 3D glasses, they give a 3D holographic effect.
+
+ \image stereoexample-leftbuffer.png
+
+ The above image is what will be rendered to the left buffer.
+
+ \image stereoexample-rightbuffer.png
+
+ The above image is what will be rendered to the right buffer.
+
+ \section1 Setting the correct surface flag
+ To enable stereoscopic rendering you need to set the flag
+ QSurfaceFormat::StereoBuffers globally. Just doing it on the widget is not enough
+ because of how the flag is handled internally. The safest is to do it on
+ QSurfaceFormat::SetDefaultFormat prior to starting the application.
+
+ \snippet stereoqopenglwidget/main.cpp 1
+
+ \section1 Rendering twice
+ After QSurfaceFormat::StereoBuffers is set, then paintGL() will be called twice,
+ once for each buffer. In paintGL() you can call currentTargetBuffer() to query
+ which TargetBuffer is currently active.
+
+ In the following snippet we slightly translate the matrix to not render the
+ vertices on top of each other. This is a simple example just too see that if the
+ necessary support is there, at runtime you should see two objects, one on the left
+ and one on the right.
+
+ \snippet stereoqopenglwidget/glwidget.cpp 1
+*/
diff --git a/examples/opengl/doc/src/textures.qdoc b/examples/opengl/doc/src/textures.qdoc
index 34c92b8f6e..b7dd6bca80 100644
--- a/examples/opengl/doc/src/textures.qdoc
+++ b/examples/opengl/doc/src/textures.qdoc
@@ -1,29 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the documentation of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:FDL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Free Documentation License Usage
-** Alternatively, this file may be used under the terms of the GNU Free
-** Documentation License version 1.3 as published by the Free Software
-** Foundation and appearing in the file included in the packaging of
-** this file. Please review the following information to ensure
-** the GNU Free Documentation License version 1.3 requirements
-** will be met: https://www.gnu.org/licenses/fdl-1.3.html.
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GFDL-1.3-no-invariants-only
/*!
\example textures
diff --git a/examples/opengl/hellogl2/CMakeLists.txt b/examples/opengl/hellogl2/CMakeLists.txt
new file mode 100644
index 0000000000..74ef4a8c24
--- /dev/null
+++ b/examples/opengl/hellogl2/CMakeLists.txt
@@ -0,0 +1,43 @@
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
+
+cmake_minimum_required(VERSION 3.16)
+project(hellogl2 LANGUAGES CXX)
+
+find_package(Qt6 REQUIRED COMPONENTS Core Gui OpenGL OpenGLWidgets Widgets)
+
+qt_standard_project_setup()
+
+qt_add_executable(hellogl2
+ glwidget.cpp glwidget.h
+ logo.cpp logo.h
+ main.cpp
+ mainwindow.cpp mainwindow.h
+ window.cpp window.h
+)
+
+set_target_properties(hellogl2 PROPERTIES
+ WIN32_EXECUTABLE TRUE
+ MACOSX_BUNDLE TRUE
+)
+
+target_link_libraries(hellogl2 PRIVATE
+ Qt6::Core
+ Qt6::Gui
+ Qt6::OpenGL
+ Qt6::OpenGLWidgets
+ Qt6::Widgets
+)
+
+install(TARGETS hellogl2
+ BUNDLE DESTINATION .
+ RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
+ LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
+)
+
+qt_generate_deploy_app_script(
+ TARGET hellogl2
+ OUTPUT_SCRIPT deploy_script
+ NO_UNSUPPORTED_PLATFORM_ERROR
+)
+install(SCRIPT ${deploy_script})
diff --git a/examples/opengl/hellogl2/glwidget.cpp b/examples/opengl/hellogl2/glwidget.cpp
index 543e70f8ac..6d2ffb3b58 100644
--- a/examples/opengl/hellogl2/glwidget.cpp
+++ b/examples/opengl/hellogl2/glwidget.cpp
@@ -1,52 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the examples of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:BSD$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** BSD License Usage
-** Alternatively, you may use this file under the terms of the BSD license
-** as follows:
-**
-** "Redistribution and use in source and binary forms, with or without
-** modification, are permitted provided that the following conditions are
-** met:
-** * Redistributions of source code must retain the above copyright
-** notice, this list of conditions and the following disclaimer.
-** * Redistributions in binary form must reproduce the above copyright
-** notice, this list of conditions and the following disclaimer in
-** the documentation and/or other materials provided with the
-** distribution.
-** * 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.
-**
-**
-** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
-** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
-** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
-** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
-** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
-** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
-** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
-** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
-** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
#include "glwidget.h"
#include <QMouseEvent>
@@ -131,6 +84,7 @@ void GLWidget::cleanup()
delete m_program;
m_program = nullptr;
doneCurrent();
+ QObject::disconnect(context(), &QOpenGLContext::aboutToBeDestroyed, this, &GLWidget::cleanup);
}
static const char *vertexShaderSourceCore =
@@ -284,13 +238,13 @@ void GLWidget::resizeGL(int w, int h)
void GLWidget::mousePressEvent(QMouseEvent *event)
{
- m_lastPos = event->pos();
+ m_lastPos = event->position().toPoint();
}
void GLWidget::mouseMoveEvent(QMouseEvent *event)
{
- int dx = event->x() - m_lastPos.x();
- int dy = event->y() - m_lastPos.y();
+ int dx = event->position().toPoint().x() - m_lastPos.x();
+ int dy = event->position().toPoint().y() - m_lastPos.y();
if (event->buttons() & Qt::LeftButton) {
setXRotation(m_xRot + 8 * dy);
@@ -299,5 +253,5 @@ void GLWidget::mouseMoveEvent(QMouseEvent *event)
setXRotation(m_xRot + 8 * dy);
setZRotation(m_zRot + 8 * dx);
}
- m_lastPos = event->pos();
+ m_lastPos = event->position().toPoint();
}
diff --git a/examples/opengl/hellogl2/glwidget.h b/examples/opengl/hellogl2/glwidget.h
index f8526fb7ae..985d8a4afa 100644
--- a/examples/opengl/hellogl2/glwidget.h
+++ b/examples/opengl/hellogl2/glwidget.h
@@ -1,52 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the examples of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:BSD$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** BSD License Usage
-** Alternatively, you may use this file under the terms of the BSD license
-** as follows:
-**
-** "Redistribution and use in source and binary forms, with or without
-** modification, are permitted provided that the following conditions are
-** met:
-** * Redistributions of source code must retain the above copyright
-** notice, this list of conditions and the following disclaimer.
-** * Redistributions in binary form must reproduce the above copyright
-** notice, this list of conditions and the following disclaimer in
-** the documentation and/or other materials provided with the
-** distribution.
-** * 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.
-**
-**
-** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
-** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
-** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
-** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
-** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
-** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
-** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
-** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
-** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
#ifndef GLWIDGET_H
#define GLWIDGET_H
diff --git a/examples/opengl/hellogl2/hellogl2.pro b/examples/opengl/hellogl2/hellogl2.pro
index 834ae82e1f..d7cd38de53 100644
--- a/examples/opengl/hellogl2/hellogl2.pro
+++ b/examples/opengl/hellogl2/hellogl2.pro
@@ -8,7 +8,7 @@ SOURCES = glwidget.cpp \
mainwindow.cpp \
logo.cpp
-QT += widgets opengl
+QT += widgets opengl openglwidgets
# install
target.path = $$[QT_INSTALL_EXAMPLES]/opengl/hellogl2
diff --git a/examples/opengl/hellogl2/logo.cpp b/examples/opengl/hellogl2/logo.cpp
index 6fcece16d4..b924ba043d 100644
--- a/examples/opengl/hellogl2/logo.cpp
+++ b/examples/opengl/hellogl2/logo.cpp
@@ -1,52 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the examples of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:BSD$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** BSD License Usage
-** Alternatively, you may use this file under the terms of the BSD license
-** as follows:
-**
-** "Redistribution and use in source and binary forms, with or without
-** modification, are permitted provided that the following conditions are
-** met:
-** * Redistributions of source code must retain the above copyright
-** notice, this list of conditions and the following disclaimer.
-** * Redistributions in binary form must reproduce the above copyright
-** notice, this list of conditions and the following disclaimer in
-** the documentation and/or other materials provided with the
-** distribution.
-** * 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.
-**
-**
-** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
-** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
-** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
-** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
-** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
-** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
-** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
-** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
-** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
#include "logo.h"
#include <qmath.h>
diff --git a/examples/opengl/hellogl2/logo.h b/examples/opengl/hellogl2/logo.h
index 2f3dc7e649..0eed3f6978 100644
--- a/examples/opengl/hellogl2/logo.h
+++ b/examples/opengl/hellogl2/logo.h
@@ -1,58 +1,11 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the examples of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:BSD$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** BSD License Usage
-** Alternatively, you may use this file under the terms of the BSD license
-** as follows:
-**
-** "Redistribution and use in source and binary forms, with or without
-** modification, are permitted provided that the following conditions are
-** met:
-** * Redistributions of source code must retain the above copyright
-** notice, this list of conditions and the following disclaimer.
-** * Redistributions in binary form must reproduce the above copyright
-** notice, this list of conditions and the following disclaimer in
-** the documentation and/or other materials provided with the
-** distribution.
-** * 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.
-**
-**
-** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
-** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
-** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
-** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
-** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
-** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
-** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
-** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
-** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
#ifndef LOGO_H
#define LOGO_H
#include <qopengl.h>
-#include <QVector>
+#include <QList>
#include <QVector3D>
class Logo
@@ -68,7 +21,7 @@ private:
void extrude(GLfloat x1, GLfloat y1, GLfloat x2, GLfloat y2);
void add(const QVector3D &v, const QVector3D &n);
- QVector<GLfloat> m_data;
+ QList<GLfloat> m_data;
int m_count = 0;
};
diff --git a/examples/opengl/hellogl2/main.cpp b/examples/opengl/hellogl2/main.cpp
index b52a5a37d3..6ecd4cfe1a 100644
--- a/examples/opengl/hellogl2/main.cpp
+++ b/examples/opengl/hellogl2/main.cpp
@@ -1,56 +1,9 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the examples of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:BSD$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** BSD License Usage
-** Alternatively, you may use this file under the terms of the BSD license
-** as follows:
-**
-** "Redistribution and use in source and binary forms, with or without
-** modification, are permitted provided that the following conditions are
-** met:
-** * Redistributions of source code must retain the above copyright
-** notice, this list of conditions and the following disclaimer.
-** * Redistributions in binary form must reproduce the above copyright
-** notice, this list of conditions and the following disclaimer in
-** the documentation and/or other materials provided with the
-** distribution.
-** * 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.
-**
-**
-** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
-** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
-** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
-** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
-** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
-** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
-** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
-** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
-** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
#include <QApplication>
-#include <QDesktopWidget>
#include <QSurfaceFormat>
+#include <QScreen>
#include <QCommandLineParser>
#include <QCommandLineOption>
@@ -95,8 +48,8 @@ int main(int argc, char *argv[])
mainWindow.setAttribute(Qt::WA_NoSystemBackground, false);
}
mainWindow.resize(mainWindow.sizeHint());
- int desktopArea = QApplication::desktop()->width() *
- QApplication::desktop()->height();
+ int desktopArea = QGuiApplication::primaryScreen()->size().width() *
+ QGuiApplication::primaryScreen()->size().height();
int widgetArea = mainWindow.width() * mainWindow.height();
if (((float)widgetArea / (float)desktopArea) < 0.75f)
mainWindow.show();
diff --git a/examples/opengl/hellogl2/mainwindow.cpp b/examples/opengl/hellogl2/mainwindow.cpp
index aa20cd678c..5ee2b738c2 100644
--- a/examples/opengl/hellogl2/mainwindow.cpp
+++ b/examples/opengl/hellogl2/mainwindow.cpp
@@ -1,68 +1,21 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the examples of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:BSD$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** BSD License Usage
-** Alternatively, you may use this file under the terms of the BSD license
-** as follows:
-**
-** "Redistribution and use in source and binary forms, with or without
-** modification, are permitted provided that the following conditions are
-** met:
-** * Redistributions of source code must retain the above copyright
-** notice, this list of conditions and the following disclaimer.
-** * Redistributions in binary form must reproduce the above copyright
-** notice, this list of conditions and the following disclaimer in
-** the documentation and/or other materials provided with the
-** distribution.
-** * 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.
-**
-**
-** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
-** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
-** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
-** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
-** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
-** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
-** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
-** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
-** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
#include "mainwindow.h"
#include "window.h"
+#include <QApplication>
+#include <QKeySequence>
#include <QMenuBar>
#include <QMenu>
#include <QMessageBox>
MainWindow::MainWindow()
{
- QMenuBar *menuBar = new QMenuBar;
- QMenu *menuWindow = menuBar->addMenu(tr("&Window"));
- QAction *addNew = new QAction(menuWindow);
- addNew->setText(tr("Add new"));
- menuWindow->addAction(addNew);
- connect(addNew, &QAction::triggered, this, &MainWindow::onAddNew);
- setMenuBar(menuBar);
+ QMenu *menuWindow = menuBar()->addMenu(tr("&Window"));
+ menuWindow->addAction(tr("Add new"), QKeySequence(Qt::CTRL | Qt::Key_N),
+ this, &MainWindow::onAddNew);
+ menuWindow->addAction(tr("Quit"), QKeySequence(Qt::CTRL | Qt::Key_Q),
+ qApp, QApplication::closeAllWindows);
onAddNew();
}
@@ -70,8 +23,8 @@ MainWindow::MainWindow()
void MainWindow::onAddNew()
{
if (!centralWidget())
- setCentralWidget(new Window(this));
+ setCentralWidget(new Window);
else
- QMessageBox::information(nullptr, tr("Cannot add new window"),
+ QMessageBox::information(this, tr("Cannot Add New Window"),
tr("Already occupied. Undock first."));
}
diff --git a/examples/opengl/hellogl2/mainwindow.h b/examples/opengl/hellogl2/mainwindow.h
index 625bffc86e..8b3c2508f6 100644
--- a/examples/opengl/hellogl2/mainwindow.h
+++ b/examples/opengl/hellogl2/mainwindow.h
@@ -1,52 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the examples of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:BSD$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** BSD License Usage
-** Alternatively, you may use this file under the terms of the BSD license
-** as follows:
-**
-** "Redistribution and use in source and binary forms, with or without
-** modification, are permitted provided that the following conditions are
-** met:
-** * Redistributions of source code must retain the above copyright
-** notice, this list of conditions and the following disclaimer.
-** * Redistributions in binary form must reproduce the above copyright
-** notice, this list of conditions and the following disclaimer in
-** the documentation and/or other materials provided with the
-** distribution.
-** * 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.
-**
-**
-** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
-** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
-** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
-** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
-** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
-** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
-** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
-** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
-** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
diff --git a/examples/opengl/hellogl2/window.cpp b/examples/opengl/hellogl2/window.cpp
index 5534f2edea..5a7ddf826f 100644
--- a/examples/opengl/hellogl2/window.cpp
+++ b/examples/opengl/hellogl2/window.cpp
@@ -1,67 +1,27 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the examples of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:BSD$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** BSD License Usage
-** Alternatively, you may use this file under the terms of the BSD license
-** as follows:
-**
-** "Redistribution and use in source and binary forms, with or without
-** modification, are permitted provided that the following conditions are
-** met:
-** * Redistributions of source code must retain the above copyright
-** notice, this list of conditions and the following disclaimer.
-** * Redistributions in binary form must reproduce the above copyright
-** notice, this list of conditions and the following disclaimer in
-** the documentation and/or other materials provided with the
-** distribution.
-** * 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.
-**
-**
-** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
-** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
-** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
-** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
-** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
-** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
-** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
-** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
-** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
-#include "glwidget.h"
#include "window.h"
-#include "mainwindow.h"
+#include "glwidget.h"
#include <QSlider>
#include <QVBoxLayout>
#include <QHBoxLayout>
#include <QKeyEvent>
#include <QPushButton>
-#include <QDesktopWidget>
#include <QApplication>
#include <QMessageBox>
+#include <QMainWindow>
-Window::Window(MainWindow *mw)
- : mainWindow(mw)
+static QMainWindow *findMainWindow()
+{
+ for (auto *w : QApplication::topLevelWidgets()) {
+ if (auto *mw = qobject_cast<QMainWindow *>(w))
+ return mw;
+ }
+ return nullptr;
+}
+
+Window::Window()
{
glWidget = new GLWidget;
@@ -76,22 +36,19 @@ Window::Window(MainWindow *mw)
connect(zSlider, &QSlider::valueChanged, glWidget, &GLWidget::setZRotation);
connect(glWidget, &GLWidget::zRotationChanged, zSlider, &QSlider::setValue);
- QVBoxLayout *mainLayout = new QVBoxLayout;
- QHBoxLayout *container = new QHBoxLayout;
+ QVBoxLayout *mainLayout = new QVBoxLayout(this);
+ QWidget *w = new QWidget;
+ QHBoxLayout *container = new QHBoxLayout(w);
container->addWidget(glWidget);
container->addWidget(xSlider);
container->addWidget(ySlider);
container->addWidget(zSlider);
- QWidget *w = new QWidget;
- w->setLayout(container);
mainLayout->addWidget(w);
dockBtn = new QPushButton(tr("Undock"), this);
connect(dockBtn, &QPushButton::clicked, this, &Window::dockUndock);
mainLayout->addWidget(dockBtn);
- setLayout(mainLayout);
-
xSlider->setValue(15 * 16);
ySlider->setValue(345 * 16);
zSlider->setValue(0 * 16);
@@ -112,7 +69,7 @@ QSlider *Window::createSlider()
void Window::keyPressEvent(QKeyEvent *e)
{
- if (e->key() == Qt::Key_Escape)
+ if (isWindow() && e->key() == Qt::Key_Escape)
close();
else
QWidget::keyPressEvent(e);
@@ -120,26 +77,37 @@ void Window::keyPressEvent(QKeyEvent *e)
void Window::dockUndock()
{
- if (parent()) {
- setParent(nullptr);
- setAttribute(Qt::WA_DeleteOnClose);
- move(QApplication::desktop()->width() / 2 - width() / 2,
- QApplication::desktop()->height() / 2 - height() / 2);
- dockBtn->setText(tr("Dock"));
- show();
- } else {
- if (!mainWindow->centralWidget()) {
- if (mainWindow->isVisible()) {
- setAttribute(Qt::WA_DeleteOnClose, false);
- dockBtn->setText(tr("Undock"));
- mainWindow->setCentralWidget(this);
- } else {
- QMessageBox::information(nullptr, tr("Cannot dock"),
- tr("Main window already closed"));
- }
- } else {
- QMessageBox::information(nullptr, tr("Cannot dock"),
- tr("Main window already occupied"));
- }
+ if (parent())
+ undock();
+ else
+ dock();
+}
+
+void Window::dock()
+{
+ auto *mainWindow = findMainWindow();
+ if (mainWindow == nullptr || !mainWindow->isVisible()) {
+ QMessageBox::information(this, tr("Cannot Dock"),
+ tr("Main window already closed"));
+ return;
}
+ if (mainWindow->centralWidget()) {
+ QMessageBox::information(this, tr("Cannot Dock"),
+ tr("Main window already occupied"));
+ return;
+ }
+ setAttribute(Qt::WA_DeleteOnClose, false);
+ dockBtn->setText(tr("Undock"));
+ mainWindow->setCentralWidget(this);
+}
+
+void Window::undock()
+{
+ setParent(nullptr);
+ setAttribute(Qt::WA_DeleteOnClose);
+ const auto geometry = screen()->availableGeometry();
+ move(geometry.x() + (geometry.width() - width()) / 2,
+ geometry.y() + (geometry.height() - height()) / 2);
+ dockBtn->setText(tr("Dock"));
+ show();
}
diff --git a/examples/opengl/hellogl2/window.h b/examples/opengl/hellogl2/window.h
index 5cec60ff06..edbd643ae2 100644
--- a/examples/opengl/hellogl2/window.h
+++ b/examples/opengl/hellogl2/window.h
@@ -1,72 +1,22 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the examples of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:BSD$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** BSD License Usage
-** Alternatively, you may use this file under the terms of the BSD license
-** as follows:
-**
-** "Redistribution and use in source and binary forms, with or without
-** modification, are permitted provided that the following conditions are
-** met:
-** * Redistributions of source code must retain the above copyright
-** notice, this list of conditions and the following disclaimer.
-** * Redistributions in binary form must reproduce the above copyright
-** notice, this list of conditions and the following disclaimer in
-** the documentation and/or other materials provided with the
-** distribution.
-** * 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.
-**
-**
-** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
-** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
-** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
-** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
-** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
-** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
-** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
-** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
-** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
#ifndef WINDOW_H
#define WINDOW_H
#include <QWidget>
-QT_BEGIN_NAMESPACE
-class QSlider;
-class QPushButton;
-QT_END_NAMESPACE
+QT_FORWARD_DECLARE_CLASS(QSlider)
+QT_FORWARD_DECLARE_CLASS(QPushButton)
class GLWidget;
-class MainWindow;
class Window : public QWidget
{
Q_OBJECT
public:
- Window(MainWindow *mw);
+ Window();
protected:
void keyPressEvent(QKeyEvent *event) override;
@@ -75,6 +25,8 @@ private slots:
void dockUndock();
private:
+ void dock();
+ void undock();
QSlider *createSlider();
GLWidget *glWidget;
@@ -82,7 +34,6 @@ private:
QSlider *ySlider;
QSlider *zSlider;
QPushButton *dockBtn;
- MainWindow *mainWindow;
};
#endif
diff --git a/examples/opengl/hellogles3/CMakeLists.txt b/examples/opengl/hellogles3/CMakeLists.txt
new file mode 100644
index 0000000000..07df173a47
--- /dev/null
+++ b/examples/opengl/hellogles3/CMakeLists.txt
@@ -0,0 +1,51 @@
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
+
+cmake_minimum_required(VERSION 3.16)
+project(hellogles3 LANGUAGES CXX)
+
+find_package(Qt6 REQUIRED COMPONENTS Core Gui OpenGL)
+
+qt_standard_project_setup()
+
+qt_add_executable(hellogles3
+ ../hellogl2/logo.cpp ../hellogl2/logo.h
+ glwindow.cpp glwindow.h
+ main.cpp
+)
+
+set_target_properties(hellogles3 PROPERTIES
+ WIN32_EXECUTABLE TRUE
+ MACOSX_BUNDLE TRUE
+)
+
+target_link_libraries(hellogles3 PRIVATE
+ Qt6::Core
+ Qt6::Gui
+ Qt6::OpenGL
+)
+
+# Resources:
+set(hellogles3_resource_files
+ "qtlogo.png"
+)
+
+qt_add_resources(hellogles3 "hellogles3"
+ PREFIX
+ "/"
+ FILES
+ ${hellogles3_resource_files}
+)
+
+install(TARGETS hellogles3
+ BUNDLE DESTINATION .
+ RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
+ LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
+)
+
+qt_generate_deploy_app_script(
+ TARGET hellogles3
+ OUTPUT_SCRIPT deploy_script
+ NO_UNSUPPORTED_PLATFORM_ERROR
+)
+install(SCRIPT ${deploy_script})
diff --git a/examples/opengl/hellogles3/doc/src/hellogles3.qdoc b/examples/opengl/hellogles3/doc/src/hellogles3.qdoc
deleted file mode 100644
index fbe071f143..0000000000
--- a/examples/opengl/hellogles3/doc/src/hellogles3.qdoc
+++ /dev/null
@@ -1,46 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2018 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the documentation of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:FDL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Free Documentation License Usage
-** Alternatively, this file may be used under the terms of the GNU Free
-** Documentation License version 1.3 as published by the Free Software
-** Foundation and appearing in the file included in the packaging of
-** this file. Please review the following information to ensure
-** the GNU Free Documentation License version 1.3 requirements
-** will be met: https://www.gnu.org/licenses/fdl-1.3.html.
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-/*!
- \example hellogles3
- \title Hello GLES3 Example
- \ingroup examples-widgets-opengl
-
- \brief The Hello GLES3 example demonstrates easy, cross-platform usage of
- OpenGL ES 3.0 functions via QOpenGLExtraFunctions in an application that
- works identically on desktop platforms with OpenGL 3.3 and mobile/embedded
- devices with OpenGL ES 3.0.
-
- The code is always the same, with the exception of two places:
- \list
- \li The OpenGL context creation has to have a sufficiently high version
- number for the features that are in use.
- \li The shader code's version directive is different.
- \endlist
-
- \image hellogles3-example.png
-*/
diff --git a/examples/opengl/hellogles3/glwindow.cpp b/examples/opengl/hellogles3/glwindow.cpp
index c644faa9a6..921230fb44 100644
--- a/examples/opengl/hellogles3/glwindow.cpp
+++ b/examples/opengl/hellogles3/glwindow.cpp
@@ -1,52 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the examples of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:BSD$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** BSD License Usage
-** Alternatively, you may use this file under the terms of the BSD license
-** as follows:
-**
-** "Redistribution and use in source and binary forms, with or without
-** modification, are permitted provided that the following conditions are
-** met:
-** * Redistributions of source code must retain the above copyright
-** notice, this list of conditions and the following disclaimer.
-** * Redistributions in binary form must reproduce the above copyright
-** notice, this list of conditions and the following disclaimer in
-** the documentation and/or other materials provided with the
-** distribution.
-** * 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.
-**
-**
-** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
-** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
-** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
-** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
-** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
-** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
-** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
-** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
-** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
#include "glwindow.h"
#include <QImage>
diff --git a/examples/opengl/hellogles3/glwindow.h b/examples/opengl/hellogles3/glwindow.h
index dfa0680714..54bc531af8 100644
--- a/examples/opengl/hellogles3/glwindow.h
+++ b/examples/opengl/hellogles3/glwindow.h
@@ -1,52 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the examples of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:BSD$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** BSD License Usage
-** Alternatively, you may use this file under the terms of the BSD license
-** as follows:
-**
-** "Redistribution and use in source and binary forms, with or without
-** modification, are permitted provided that the following conditions are
-** met:
-** * Redistributions of source code must retain the above copyright
-** notice, this list of conditions and the following disclaimer.
-** * Redistributions in binary form must reproduce the above copyright
-** notice, this list of conditions and the following disclaimer in
-** the documentation and/or other materials provided with the
-** distribution.
-** * 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.
-**
-**
-** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
-** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
-** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
-** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
-** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
-** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
-** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
-** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
-** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
#ifndef GLWIDGET_H
#define GLWIDGET_H
@@ -56,14 +9,10 @@
#include <QVector3D>
#include "../hellogl2/logo.h"
-QT_BEGIN_NAMESPACE
-
-class QOpenGLTexture;
-class QOpenGLShaderProgram;
-class QOpenGLBuffer;
-class QOpenGLVertexArrayObject;
-
-QT_END_NAMESPACE
+QT_FORWARD_DECLARE_CLASS(QOpenGLTexture)
+QT_FORWARD_DECLARE_CLASS(QOpenGLShaderProgram)
+QT_FORWARD_DECLARE_CLASS(QOpenGLBuffer)
+QT_FORWARD_DECLARE_CLASS(QOpenGLVertexArrayObject)
class GLWindow : public QOpenGLWindow
{
diff --git a/examples/opengl/hellogles3/main.cpp b/examples/opengl/hellogles3/main.cpp
index 9451b2882f..09f3d95041 100644
--- a/examples/opengl/hellogles3/main.cpp
+++ b/examples/opengl/hellogles3/main.cpp
@@ -1,52 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the examples of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:BSD$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** BSD License Usage
-** Alternatively, you may use this file under the terms of the BSD license
-** as follows:
-**
-** "Redistribution and use in source and binary forms, with or without
-** modification, are permitted provided that the following conditions are
-** met:
-** * Redistributions of source code must retain the above copyright
-** notice, this list of conditions and the following disclaimer.
-** * Redistributions in binary form must reproduce the above copyright
-** notice, this list of conditions and the following disclaimer in
-** the documentation and/or other materials provided with the
-** distribution.
-** * 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.
-**
-**
-** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
-** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
-** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
-** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
-** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
-** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
-** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
-** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
-** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
#include <QGuiApplication>
#include <QSurfaceFormat>
diff --git a/examples/opengl/hellowindow/hellowindow.cpp b/examples/opengl/hellowindow/hellowindow.cpp
deleted file mode 100644
index 1c1259de13..0000000000
--- a/examples/opengl/hellowindow/hellowindow.cpp
+++ /dev/null
@@ -1,375 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the examples of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:BSD$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** BSD License Usage
-** Alternatively, you may use this file under the terms of the BSD license
-** as follows:
-**
-** "Redistribution and use in source and binary forms, with or without
-** modification, are permitted provided that the following conditions are
-** met:
-** * Redistributions of source code must retain the above copyright
-** notice, this list of conditions and the following disclaimer.
-** * Redistributions in binary form must reproduce the above copyright
-** notice, this list of conditions and the following disclaimer in
-** the documentation and/or other materials provided with the
-** distribution.
-** * 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.
-**
-**
-** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
-** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
-** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
-** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
-** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
-** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
-** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
-** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
-** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include "hellowindow.h"
-
-#include <QOpenGLContext>
-#include <QOpenGLFunctions>
-#include <QRandomGenerator>
-#include <qmath.h>
-
-Renderer::Renderer(const QSurfaceFormat &format, Renderer *share, QScreen *screen)
- : m_initialized(false)
- , m_format(format)
- , m_currentWindow(0)
-{
- m_context = new QOpenGLContext(this);
- if (screen)
- m_context->setScreen(screen);
- m_context->setFormat(format);
- if (share)
- m_context->setShareContext(share->m_context);
- m_context->create();
-
- m_backgroundColor = QColor::fromRgbF(0.1f, 0.1f, 0.2f, 1.0f);
- m_backgroundColor.setRed(QRandomGenerator::global()->bounded(64));
- m_backgroundColor.setGreen(QRandomGenerator::global()->bounded(128));
- m_backgroundColor.setBlue(QRandomGenerator::global()->bounded(256));
-}
-
-HelloWindow::HelloWindow(const QSharedPointer<Renderer> &renderer, QScreen *screen)
- : m_colorIndex(0), m_renderer(renderer)
-{
- setSurfaceType(QWindow::OpenGLSurface);
- setFlags(Qt::Window | Qt::WindowSystemMenuHint | Qt::WindowTitleHint | Qt::WindowMinMaxButtonsHint | Qt::WindowCloseButtonHint);
-
- setGeometry(QRect(10, 10, 640, 480));
-
- setFormat(renderer->format());
- if (screen)
- setScreen(screen);
-
- create();
-
- updateColor();
-}
-
-void HelloWindow::exposeEvent(QExposeEvent *)
-{
- m_renderer->setAnimating(this, isExposed());
- if (isExposed())
- m_renderer->render();
-}
-
-bool HelloWindow::event(QEvent *ev)
-{
- if (ev->type() == QEvent::UpdateRequest) {
- m_renderer->render();
- requestUpdate();
- }
- return QWindow::event(ev);
-}
-
-void HelloWindow::mousePressEvent(QMouseEvent *)
-{
- updateColor();
-}
-
-QColor HelloWindow::color() const
-{
- QMutexLocker locker(&m_colorLock);
- return m_color;
-}
-
-void HelloWindow::updateColor()
-{
- QMutexLocker locker(&m_colorLock);
-
- QColor colors[] =
- {
- QColor(100, 255, 0),
- QColor(0, 100, 255)
- };
-
- m_color = colors[m_colorIndex];
- m_colorIndex = 1 - m_colorIndex;
-}
-
-void Renderer::setAnimating(HelloWindow *window, bool animating)
-{
- QMutexLocker locker(&m_windowLock);
- if (m_windows.contains(window) == animating)
- return;
-
- if (animating) {
- m_windows << window;
- if (m_windows.size() == 1)
- window->requestUpdate();
- } else {
- m_currentWindow = 0;
- m_windows.removeOne(window);
- }
-}
-
-void Renderer::render()
-{
- QMutexLocker locker(&m_windowLock);
-
- if (m_windows.isEmpty())
- return;
-
- HelloWindow *surface = m_windows.at(m_currentWindow);
- QColor color = surface->color();
-
- m_currentWindow = (m_currentWindow + 1) % m_windows.size();
-
- if (!m_context->makeCurrent(surface))
- return;
-
- QSize viewSize = surface->size();
-
- locker.unlock();
-
- if (!m_initialized) {
- initialize();
- m_initialized = true;
- }
-
- QOpenGLFunctions *f = m_context->functions();
- f->glViewport(0, 0, viewSize.width() * surface->devicePixelRatio(), viewSize.height() * surface->devicePixelRatio());
- f->glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
-
- f->glClearColor(m_backgroundColor.redF(), m_backgroundColor.greenF(), m_backgroundColor.blueF(), m_backgroundColor.alphaF());
- f->glFrontFace(GL_CW);
- f->glCullFace(GL_FRONT);
- f->glEnable(GL_CULL_FACE);
- f->glEnable(GL_DEPTH_TEST);
-
- m_program->bind();
- m_vbo.bind();
-
- m_program->enableAttributeArray(vertexAttr);
- m_program->enableAttributeArray(normalAttr);
- m_program->setAttributeBuffer(vertexAttr, GL_FLOAT, 0, 3);
- const int verticesSize = vertices.count() * 3 * sizeof(GLfloat);
- m_program->setAttributeBuffer(normalAttr, GL_FLOAT, verticesSize, 3);
-
- QMatrix4x4 modelview;
- modelview.rotate(m_fAngle, 0.0f, 1.0f, 0.0f);
- modelview.rotate(m_fAngle, 1.0f, 0.0f, 0.0f);
- modelview.rotate(m_fAngle, 0.0f, 0.0f, 1.0f);
- modelview.translate(0.0f, -0.2f, 0.0f);
-
- m_program->setUniformValue(matrixUniform, modelview);
- m_program->setUniformValue(colorUniform, color);
-
- m_context->functions()->glDrawArrays(GL_TRIANGLES, 0, vertices.size());
-
- m_context->swapBuffers(surface);
-
- m_fAngle += 1.0f;
-}
-
-Q_GLOBAL_STATIC(QMutex, initMutex)
-
-void Renderer::initialize()
-{
- // Threaded shader compilation can confuse some drivers. Avoid it.
- QMutexLocker lock(initMutex());
-
- QOpenGLShader *vshader = new QOpenGLShader(QOpenGLShader::Vertex, this);
- 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);
- fshader->compileSourceCode(
- "varying mediump vec4 color;"
- "void main(void)"
- "{"
- " gl_FragColor = color;"
- "}");
-
- m_program = new QOpenGLShaderProgram(this);
- m_program->addShader(vshader);
- m_program->addShader(fshader);
- m_program->link();
- m_program->bind();
-
- vertexAttr = m_program->attributeLocation("vertex");
- normalAttr = m_program->attributeLocation("normal");
- matrixUniform = m_program->uniformLocation("matrix");
- colorUniform = m_program->uniformLocation("sourceColor");
-
- m_fAngle = 0;
- createGeometry();
-
- m_vbo.create();
- m_vbo.bind();
- const int verticesSize = vertices.count() * 3 * sizeof(GLfloat);
- m_vbo.allocate(verticesSize * 2);
- m_vbo.write(0, vertices.constData(), verticesSize);
- m_vbo.write(verticesSize, normals.constData(), verticesSize);
-}
-
-void Renderer::createGeometry()
-{
- vertices.clear();
- normals.clear();
-
- qreal x1 = +0.06f;
- qreal y1 = -0.14f;
- qreal x2 = +0.14f;
- qreal y2 = -0.06f;
- qreal x3 = +0.08f;
- qreal y3 = +0.00f;
- qreal x4 = +0.30f;
- qreal y4 = +0.22f;
-
- quad(x1, y1, x2, y2, y2, x2, y1, x1);
- quad(x3, y3, x4, y4, y4, x4, y3, x3);
-
- extrude(x1, y1, x2, y2);
- extrude(x2, y2, y2, x2);
- extrude(y2, x2, y1, x1);
- extrude(y1, x1, x1, y1);
- extrude(x3, y3, x4, y4);
- extrude(x4, y4, y4, x4);
- extrude(y4, x4, y3, x3);
-
- const int NumSectors = 100;
- const qreal sectorAngle = 2 * qreal(M_PI) / NumSectors;
- for (int i = 0; i < NumSectors; ++i) {
- qreal angle = i * sectorAngle;
- qreal x5 = 0.30 * qSin(angle);
- qreal y5 = 0.30 * qCos(angle);
- qreal x6 = 0.20 * qSin(angle);
- qreal y6 = 0.20 * qCos(angle);
-
- angle += sectorAngle;
- qreal x7 = 0.20 * qSin(angle);
- qreal y7 = 0.20 * qCos(angle);
- qreal x8 = 0.30 * qSin(angle);
- qreal y8 = 0.30 * qCos(angle);
-
- quad(x5, y5, x6, y6, x7, y7, x8, y8);
-
- extrude(x6, y6, x7, y7);
- extrude(x8, y8, x5, y5);
- }
-
- for (int i = 0;i < vertices.size();i++)
- vertices[i] *= 2.0f;
-}
-
-void Renderer::quad(qreal x1, qreal y1, qreal x2, qreal y2, qreal x3, qreal y3, qreal x4, qreal y4)
-{
- vertices << QVector3D(x1, y1, -0.05f);
- vertices << QVector3D(x2, y2, -0.05f);
- vertices << QVector3D(x4, y4, -0.05f);
-
- vertices << QVector3D(x3, y3, -0.05f);
- vertices << QVector3D(x4, y4, -0.05f);
- vertices << QVector3D(x2, y2, -0.05f);
-
- QVector3D n = QVector3D::normal
- (QVector3D(x2 - x1, y2 - y1, 0.0f), QVector3D(x4 - x1, y4 - y1, 0.0f));
-
- normals << n;
- normals << n;
- normals << n;
-
- normals << n;
- normals << n;
- normals << n;
-
- vertices << QVector3D(x4, y4, 0.05f);
- vertices << QVector3D(x2, y2, 0.05f);
- vertices << QVector3D(x1, y1, 0.05f);
-
- vertices << QVector3D(x2, y2, 0.05f);
- vertices << QVector3D(x4, y4, 0.05f);
- vertices << QVector3D(x3, y3, 0.05f);
-
- n = QVector3D::normal
- (QVector3D(x2 - x4, y2 - y4, 0.0f), QVector3D(x1 - x4, y1 - y4, 0.0f));
-
- normals << n;
- normals << n;
- normals << n;
-
- normals << n;
- normals << n;
- normals << n;
-}
-
-void Renderer::extrude(qreal x1, qreal y1, qreal x2, qreal y2)
-{
- vertices << QVector3D(x1, y1, +0.05f);
- vertices << QVector3D(x2, y2, +0.05f);
- vertices << QVector3D(x1, y1, -0.05f);
-
- vertices << QVector3D(x2, y2, -0.05f);
- vertices << QVector3D(x1, y1, -0.05f);
- vertices << QVector3D(x2, y2, +0.05f);
-
- QVector3D n = QVector3D::normal
- (QVector3D(x2 - x1, y2 - y1, 0.0f), QVector3D(0.0f, 0.0f, -0.1f));
-
- normals << n;
- normals << n;
- normals << n;
-
- normals << n;
- normals << n;
- normals << n;
-}
diff --git a/examples/opengl/hellowindow/hellowindow.h b/examples/opengl/hellowindow/hellowindow.h
deleted file mode 100644
index e6d7970cfc..0000000000
--- a/examples/opengl/hellowindow/hellowindow.h
+++ /dev/null
@@ -1,125 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the examples of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:BSD$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** BSD License Usage
-** Alternatively, you may use this file under the terms of the BSD license
-** as follows:
-**
-** "Redistribution and use in source and binary forms, with or without
-** modification, are permitted provided that the following conditions are
-** met:
-** * Redistributions of source code must retain the above copyright
-** notice, this list of conditions and the following disclaimer.
-** * Redistributions in binary form must reproduce the above copyright
-** notice, this list of conditions and the following disclaimer in
-** the documentation and/or other materials provided with the
-** distribution.
-** * 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.
-**
-**
-** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
-** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
-** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
-** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
-** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
-** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
-** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
-** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
-** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include <QWindow>
-
-#include <QColor>
-#include <QMutex>
-#include <QOpenGLShaderProgram>
-#include <QOpenGLBuffer>
-#include <QSharedPointer>
-#include <QTimer>
-
-class HelloWindow;
-
-class Renderer : public QObject
-{
- Q_OBJECT
-
-public:
- explicit Renderer(const QSurfaceFormat &format, Renderer *share = 0, QScreen *screen = 0);
-
- QSurfaceFormat format() const { return m_format; }
-
- void setAnimating(HelloWindow *window, bool animating);
-
-public slots:
- void render();
-
-private:
- void initialize();
-
- void createGeometry();
- void createBubbles(int number);
- void quad(qreal x1, qreal y1, qreal x2, qreal y2, qreal x3, qreal y3, qreal x4, qreal y4);
- void extrude(qreal x1, qreal y1, qreal x2, qreal y2);
-
- qreal m_fAngle;
-
- QVector<QVector3D> vertices;
- QVector<QVector3D> normals;
- int vertexAttr;
- int normalAttr;
- int matrixUniform;
- int colorUniform;
-
- bool m_initialized;
- QSurfaceFormat m_format;
- QOpenGLContext *m_context;
- QOpenGLShaderProgram *m_program;
- QOpenGLBuffer m_vbo;
-
- QList<HelloWindow *> m_windows;
- int m_currentWindow;
-
- QMutex m_windowLock;
-
- QColor m_backgroundColor;
-};
-
-class HelloWindow : public QWindow
-{
-public:
- explicit HelloWindow(const QSharedPointer<Renderer> &renderer, QScreen *screen = 0);
-
- QColor color() const;
- void updateColor();
-
-protected:
- bool event(QEvent *ev) override;
- void exposeEvent(QExposeEvent *event) override;
- void mousePressEvent(QMouseEvent *) override;
-
-private:
- int m_colorIndex;
- QColor m_color;
- const QSharedPointer<Renderer> m_renderer;
- mutable QMutex m_colorLock;
-};
diff --git a/examples/opengl/hellowindow/hellowindow.pro b/examples/opengl/hellowindow/hellowindow.pro
deleted file mode 100644
index cc220fd344..0000000000
--- a/examples/opengl/hellowindow/hellowindow.pro
+++ /dev/null
@@ -1,9 +0,0 @@
-QT += gui-private core-private
-
-HEADERS += hellowindow.h
-SOURCES += hellowindow.cpp main.cpp
-
-# install
-target.path = $$[QT_INSTALL_EXAMPLES]/opengl/hellowindow
-INSTALLS += target
-
diff --git a/examples/opengl/hellowindow/main.cpp b/examples/opengl/hellowindow/main.cpp
deleted file mode 100644
index 7f0be39f5d..0000000000
--- a/examples/opengl/hellowindow/main.cpp
+++ /dev/null
@@ -1,172 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the examples of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:BSD$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** BSD License Usage
-** Alternatively, you may use this file under the terms of the BSD license
-** as follows:
-**
-** "Redistribution and use in source and binary forms, with or without
-** modification, are permitted provided that the following conditions are
-** met:
-** * Redistributions of source code must retain the above copyright
-** notice, this list of conditions and the following disclaimer.
-** * Redistributions in binary form must reproduce the above copyright
-** notice, this list of conditions and the following disclaimer in
-** the documentation and/or other materials provided with the
-** distribution.
-** * 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.
-**
-**
-** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
-** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
-** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
-** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
-** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
-** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
-** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
-** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
-** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include "hellowindow.h"
-
-#include <qpa/qplatformintegration.h>
-
-#include <QCommandLineParser>
-#include <QCommandLineOption>
-#include <QGuiApplication>
-#include <QScreen>
-#include <QThread>
-
-int main(int argc, char *argv[])
-{
- QGuiApplication app(argc, argv);
-
- QCoreApplication::setApplicationName("Qt HelloWindow GL Example");
- QCoreApplication::setOrganizationName("QtProject");
- QCoreApplication::setApplicationVersion(QT_VERSION_STR);
- QCommandLineParser parser;
- parser.setApplicationDescription(QCoreApplication::applicationName());
- parser.addHelpOption();
- parser.addVersionOption();
- QCommandLineOption multipleOption("multiple", "Create multiple windows");
- parser.addOption(multipleOption);
- QCommandLineOption multipleSampleOption("multisample", "Multisampling");
- parser.addOption(multipleSampleOption);
- QCommandLineOption multipleScreenOption("multiscreen", "Run on multiple screens");
- parser.addOption(multipleScreenOption);
- QCommandLineOption timeoutOption("timeout", "Close after 10s");
- parser.addOption(timeoutOption);
- parser.process(app);
-
- // Some platforms can only have one window per screen. Therefore we need to differentiate.
- const bool multipleWindows = parser.isSet(multipleOption);
- const bool multipleScreens = parser.isSet(multipleScreenOption);
-
- QScreen *screen = QGuiApplication::primaryScreen();
-
- QRect screenGeometry = screen->availableGeometry();
-
- QSurfaceFormat format;
- format.setDepthBufferSize(16);
- if (parser.isSet(multipleSampleOption))
- format.setSamples(4);
-
- QPoint center = QPoint(screenGeometry.center().x(), screenGeometry.top() + 80);
- QSize windowSize(400, 320);
- int delta = 40;
-
- QList<QWindow *> windows;
- QSharedPointer<Renderer> rendererA(new Renderer(format));
-
- HelloWindow *windowA = new HelloWindow(rendererA);
- windowA->setGeometry(QRect(center, windowSize).translated(-windowSize.width() - delta / 2, 0));
- windowA->setTitle(QStringLiteral("Thread A - Context A"));
- windowA->setVisible(true);
- windows.prepend(windowA);
-
- QList<QThread *> renderThreads;
- if (multipleWindows) {
- QSharedPointer<Renderer> rendererB(new Renderer(format, rendererA.data()));
-
- QThread *renderThread = new QThread;
- rendererB->moveToThread(renderThread);
- renderThreads << renderThread;
-
- HelloWindow *windowB = new HelloWindow(rendererA);
- windowB->setGeometry(QRect(center, windowSize).translated(delta / 2, 0));
- 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(QStringLiteral("Thread B - Context B"));
- windowC->setVisible(true);
- windows.prepend(windowC);
- }
- if (multipleScreens) {
- for (int i = 1; i < QGuiApplication::screens().size(); ++i) {
- QScreen *screen = QGuiApplication::screens().at(i);
- QSharedPointer<Renderer> renderer(new Renderer(format, rendererA.data(), screen));
-
- QThread *renderThread = new QThread;
- renderer->moveToThread(renderThread);
- renderThreads.prepend(renderThread);
-
- QRect screenGeometry = screen->availableGeometry();
- QPoint center = screenGeometry.center();
-
- QSize windowSize = screenGeometry.size() * 0.8;
-
- HelloWindow *window = new HelloWindow(renderer, screen);
- window->setGeometry(QRect(center, windowSize).translated(-windowSize.width() / 2, -windowSize.height() / 2));
-
- QChar id = QChar('B' + i);
- window->setTitle(QStringLiteral("Thread ") + id + QStringLiteral(" - Context ") + id);
- window->setVisible(true);
- windows.prepend(window);
- }
- }
-
- for (int i = 0; i < renderThreads.size(); ++i) {
- QObject::connect(qGuiApp, &QGuiApplication::lastWindowClosed, renderThreads.at(i), &QThread::quit);
- renderThreads.at(i)->start();
- }
-
- // Quit after 10 seconds. For platforms that do not have windows that are closeable.
- if (parser.isSet(timeoutOption))
- QTimer::singleShot(10000, qGuiApp, &QCoreApplication::quit);
-
- const int exitValue = app.exec();
-
- for (int i = 0; i < renderThreads.size(); ++i) {
- renderThreads.at(i)->quit(); // some platforms may not have windows to close so ensure quit()
- renderThreads.at(i)->wait();
- }
-
- qDeleteAll(windows);
- qDeleteAll(renderThreads);
-
- return exitValue;
-}
diff --git a/examples/opengl/legacy/README b/examples/opengl/legacy/README
deleted file mode 100644
index 8d6cbdef2a..0000000000
--- a/examples/opengl/legacy/README
+++ /dev/null
@@ -1,4 +0,0 @@
-This directory contains legacy examples that use the fixed pipeline
-and thus are not compatible with OpenGL ES 2.0+ and the core profile of
-OpenGL 3.0+. They also rely on the Qt OpenGL module (e.g. QGLWidget) which
-is not advisable in new application.
diff --git a/examples/opengl/legacy/framebufferobject2/cubelogo.png b/examples/opengl/legacy/framebufferobject2/cubelogo.png
deleted file mode 100644
index 2ccbede774..0000000000
--- a/examples/opengl/legacy/framebufferobject2/cubelogo.png
+++ /dev/null
Binary files differ
diff --git a/examples/opengl/legacy/framebufferobject2/framebufferobject2.pro b/examples/opengl/legacy/framebufferobject2/framebufferobject2.pro
deleted file mode 100644
index 3f2578bc1f..0000000000
--- a/examples/opengl/legacy/framebufferobject2/framebufferobject2.pro
+++ /dev/null
@@ -1,11 +0,0 @@
-HEADERS += glwidget.h
-SOURCES += glwidget.cpp main.cpp
-RESOURCES += framebufferobject2.qrc
-
-QT += opengl widgets
-
-# install
-target.path = $$[QT_INSTALL_EXAMPLES]/opengl/legacy/framebufferobject2
-INSTALLS += target
-
-qtConfig(opengles.|angle|dynamicgl): error("This example requires Qt to be configured with -opengl desktop")
diff --git a/examples/opengl/legacy/framebufferobject2/framebufferobject2.qrc b/examples/opengl/legacy/framebufferobject2/framebufferobject2.qrc
deleted file mode 100644
index 9fc1a56a1a..0000000000
--- a/examples/opengl/legacy/framebufferobject2/framebufferobject2.qrc
+++ /dev/null
@@ -1,5 +0,0 @@
-<!DOCTYPE RCC><RCC version="1.0">
-<qresource prefix="/res">
- <file>cubelogo.png</file>
-</qresource>
-</RCC>
diff --git a/examples/opengl/legacy/framebufferobject2/glwidget.cpp b/examples/opengl/legacy/framebufferobject2/glwidget.cpp
deleted file mode 100644
index f14d31aff6..0000000000
--- a/examples/opengl/legacy/framebufferobject2/glwidget.cpp
+++ /dev/null
@@ -1,257 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the examples of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:BSD$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** BSD License Usage
-** Alternatively, you may use this file under the terms of the BSD license
-** as follows:
-**
-** "Redistribution and use in source and binary forms, with or without
-** modification, are permitted provided that the following conditions are
-** met:
-** * Redistributions of source code must retain the above copyright
-** notice, this list of conditions and the following disclaimer.
-** * Redistributions in binary form must reproduce the above copyright
-** notice, this list of conditions and the following disclaimer in
-** the documentation and/or other materials provided with the
-** distribution.
-** * 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.
-**
-**
-** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
-** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
-** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
-** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
-** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
-** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
-** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
-** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
-** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include "glwidget.h"
-#include <QtGui/QImage>
-#include <qmath.h>
-
-static GLint cubeArray[][3] = {
- {0, 0, 0}, {0, 1, 0}, {1, 1, 0}, {1, 0, 0},
- {0, 0, 1}, {1, 0, 1}, {1, 1, 1}, {0, 1, 1},
- {0, 0, 0}, {1, 0, 0}, {1, 0, 1}, {0, 0, 1},
- {0, 1, 0}, {0, 1, 1}, {1, 1, 1}, {1, 1, 0},
- {0, 1, 0}, {0, 0, 0}, {0, 0, 1}, {0, 1, 1},
- {1, 0, 0}, {1, 1, 0}, {1, 1, 1}, {1, 0, 1}
-};
-
-static GLint cubeTextureArray[][2] = {
- {0, 0}, {1, 0}, {1, 1}, {0, 1},
- {0, 0}, {0, 1}, {1, 1}, {1, 0},
- {0, 0}, {1, 0}, {1, 1}, {0, 1},
- {1, 0}, {0, 0}, {0, 1}, {1, 1},
- {0, 0}, {1, 0}, {1, 1}, {0, 1},
- {1, 0}, {0, 0}, {0, 1}, {1, 1}
-};
-
-static GLint faceArray[][2] = {
- {1, -1}, {1, 1}, {-1, 1}, {-1, -1}
-};
-
-static GLubyte colorArray[][4] = {
- {102, 176, 54, 255},
- {81, 141, 41, 255},
- {62, 108, 32, 255},
- {45, 79, 23, 255}
-};
-
-GLWidget::GLWidget(QWidget *parent)
- : QGLWidget(QGLFormat(QGL::SampleBuffers), parent)
-{
- // create the framebuffer object - make sure to have a current
- // context before creating it
- makeCurrent();
- fbo = new QGLFramebufferObject(512, 512);
- timerId = startTimer(20);
- setWindowTitle(tr("OpenGL framebuffer objects 2"));
-}
-
-GLWidget::~GLWidget()
-{
- glDeleteLists(pbufferList, 1);
- delete fbo;
-}
-
-void GLWidget::initializeGL()
-{
- glMatrixMode(GL_MODELVIEW);
-
- glEnable(GL_CULL_FACE);
-
- glEnableClientState(GL_VERTEX_ARRAY);
- glEnableClientState(GL_TEXTURE_COORD_ARRAY);
- glVertexPointer(3, GL_INT, 0, cubeArray);
- glTexCoordPointer(2, GL_INT, 0, cubeTextureArray);
- glColorPointer(4, GL_UNSIGNED_BYTE, 0, colorArray);
-
- glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
- glEnable(GL_BLEND);
- glEnable(GL_TEXTURE_2D);
- glEnable(GL_DEPTH_TEST);
-
- glClearColor(1.0f, 1.0f, 1.0f, 1.0f);
- pbufferList = glGenLists(1);
- glNewList(pbufferList, GL_COMPILE);
- {
- glClear(GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT);
-
- // draw cube background
- glPushMatrix();
- glLoadIdentity();
- glTranslatef(0.5f, 0.5f, -2.0f);
- glDisable(GL_TEXTURE_2D);
- glEnableClientState(GL_COLOR_ARRAY);
- glVertexPointer(2, GL_INT, 0, faceArray);
- glDrawArrays(GL_QUADS, 0, 4);
- glVertexPointer(3, GL_INT, 0, cubeArray);
- glDisableClientState(GL_COLOR_ARRAY);
- glEnable(GL_TEXTURE_2D);
- glPopMatrix();
-
- // draw cube
- glTranslatef(0.5f, 0.5f, 0.5f);
- glRotatef(3.0f, 1.0f, 1.0f, 1.0f);
- glTranslatef(-0.5f, -0.5f, -0.5f);
- glColor4f(0.9f, 0.9f, 0.9f, 1.0f);
- glDrawArrays(GL_QUADS, 0, 24);
-
- glPushMatrix(); // this state is popped back in the paintGL() function
- }
- glEndList();
-
- for (int i = 0; i < 3; ++i) {
- yOffs[i] = 0.0f;
- xInc[i] = 0.005f;
- rot[i] = 0.0f;
- }
- xOffs[0]= 0.0f;
- xOffs[1]= 0.5f;
- xOffs[2]= 1.0f;
-
- cubeTexture = bindTexture(QImage(":res/cubelogo.png"));
-
- glPushMatrix(); // push to avoid stack underflow in the first paintGL() call
-}
-
-void GLWidget::resizeGL(int w, int h)
-{
- glViewport(0, 0, w, h);
- glMatrixMode(GL_PROJECTION);
- glLoadIdentity();
- float aspect = w/(float)(h ? h : 1);
- glFrustum(-aspect, aspect, -1, 1, 10, 100);
- glTranslatef(-0.5f, -0.5f, -0.5f);
- glTranslatef(0.0f, 0.0f, -15.0f);
-}
-
-void GLWidget::paintGL()
-{
- glPopMatrix(); // pop the matrix pushed in the pbuffer list
-
- // push the projection matrix and the entire GL state before
- // doing any rendering into our framebuffer object
- glPushAttrib(GL_ALL_ATTRIB_BITS);
- glMatrixMode(GL_PROJECTION);
- glPushMatrix();
-
- glViewport(0, 0, fbo->size().width(), fbo->size().height());
- glMatrixMode(GL_PROJECTION);
- glLoadIdentity();
- glOrtho(-1, 1, -1, 1, -99, 99);
- glTranslatef(-0.5f, -0.5f, 0.0f);
- glMatrixMode(GL_MODELVIEW);
-
- // render to the framebuffer object
- fbo->bind();
- glBindTexture(GL_TEXTURE_2D, cubeTexture);
- glCallList(pbufferList);
- fbo->release();
-
- // pop the projection matrix and GL state back for rendering
- // to the actual widget
- glPopAttrib();
- glMatrixMode(GL_PROJECTION);
- glPopMatrix();
-
- glBindTexture(GL_TEXTURE_2D, fbo->texture());
- glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
-
- // draw the background
- glMatrixMode(GL_MODELVIEW);
- glPushMatrix();
- glLoadIdentity();
- glMatrixMode(GL_PROJECTION);
- glPushMatrix();
- glLoadIdentity();
-
- glVertexPointer(2, GL_INT, 0, faceArray);
- glTranslatef(-1.2f, -0.8f, 0.0f);
- glScalef(0.2f, 0.2f, 0.2f);
- for (int y = 0; y < 5; ++y) {
- for (int x = 0; x < 5; ++x) {
- glTranslatef(2.0f, 0, 0);
- glColor4f(0.8f, 0.8f, 0.8f, 1.0f);
- glDrawArrays(GL_QUADS, 0, 4);
- }
- glTranslatef(-10.0f, 2.0f, 0);
- }
- glVertexPointer(3, GL_INT, 0, cubeArray);
-
- glPopMatrix();
- glMatrixMode(GL_MODELVIEW);
-
- // draw the bouncing cubes
- drawCube(0, 0.0f, 1.5f, 2.5f, 1.5f);
- drawCube(1, 1.0f, 2.0f, 2.5f, 2.0f);
- drawCube(2, 2.0f, 3.5f, 2.5f, 2.5f);
- glPopMatrix();
-}
-
-void GLWidget::drawCube(int i, GLfloat z, GLfloat rotation, GLfloat jmp, GLfloat amp)
-{
- glMatrixMode(GL_MODELVIEW);
- glLoadIdentity();
- glTranslatef(xOffs[i], yOffs[i], z);
- glTranslatef(0.5f, 0.5f, 0.5f);
- GLfloat scale = 0.75 + i*(0.25f/2);
- glScalef(scale, scale, scale);
- glRotatef(rot[i], 1.0f, 1.0f, 1.0f);
- glTranslatef(-0.5f, -0.5f, -0.5f);
-
- glColor4f(1.0f, 1.0f, 1.0f, 0.8f);
- glDrawArrays(GL_QUADS, 0, 24);
-
- if (xOffs[i] > 1.0f || xOffs[i] < -1.0f) {
- xInc[i] = -xInc[i];
- xOffs[i] = xOffs[i] > 1.0f ? 1.0f : -1.0f;
- }
- xOffs[i] += xInc[i];
- yOffs[i] = qAbs(cos((-GLfloat(M_PI) * jmp) * xOffs[i]) * amp) - 1;
- rot[i] += rotation;
-}
diff --git a/examples/opengl/legacy/framebufferobject2/glwidget.h b/examples/opengl/legacy/framebufferobject2/glwidget.h
deleted file mode 100644
index d3e4aa5af5..0000000000
--- a/examples/opengl/legacy/framebufferobject2/glwidget.h
+++ /dev/null
@@ -1,75 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the examples of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:BSD$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** BSD License Usage
-** Alternatively, you may use this file under the terms of the BSD license
-** as follows:
-**
-** "Redistribution and use in source and binary forms, with or without
-** modification, are permitted provided that the following conditions are
-** met:
-** * Redistributions of source code must retain the above copyright
-** notice, this list of conditions and the following disclaimer.
-** * Redistributions in binary form must reproduce the above copyright
-** notice, this list of conditions and the following disclaimer in
-** the documentation and/or other materials provided with the
-** distribution.
-** * 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.
-**
-**
-** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
-** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
-** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
-** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
-** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
-** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
-** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
-** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
-** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include <QtOpenGL>
-
-class GLWidget : public QGLWidget
-{
-public:
- GLWidget(QWidget *parent);
- ~GLWidget();
- void initializeGL() override;
- void resizeGL(int w, int h) override;
- void paintGL() override;
- void timerEvent(QTimerEvent *) override { update(); }
- void mousePressEvent(QMouseEvent *) override { killTimer(timerId); }
- void mouseReleaseEvent(QMouseEvent *) override { timerId = startTimer(20); }
-
- void drawCube(int i, GLfloat z, GLfloat ri, GLfloat jmp, GLfloat amp);
-
-private:
- GLfloat rot[3], xOffs[3], yOffs[3], xInc[3];
- GLuint pbufferList;
- GLuint cubeTexture;
- int timerId;
-
- QGLFramebufferObject *fbo;
-};
-
diff --git a/examples/opengl/legacy/framebufferobject2/main.cpp b/examples/opengl/legacy/framebufferobject2/main.cpp
deleted file mode 100644
index ae7447c2a5..0000000000
--- a/examples/opengl/legacy/framebufferobject2/main.cpp
+++ /dev/null
@@ -1,71 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the examples of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:BSD$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** BSD License Usage
-** Alternatively, you may use this file under the terms of the BSD license
-** as follows:
-**
-** "Redistribution and use in source and binary forms, with or without
-** modification, are permitted provided that the following conditions are
-** met:
-** * Redistributions of source code must retain the above copyright
-** notice, this list of conditions and the following disclaimer.
-** * Redistributions in binary form must reproduce the above copyright
-** notice, this list of conditions and the following disclaimer in
-** the documentation and/or other materials provided with the
-** distribution.
-** * 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.
-**
-**
-** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
-** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
-** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
-** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
-** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
-** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
-** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
-** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
-** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include <QtWidgets/QApplication>
-#include <QtWidgets/QMessageBox>
-#include "glwidget.h"
-
-int main(int argc, char **argv)
-{
- Q_INIT_RESOURCE(framebufferobject2);
-
- QApplication a(argc, argv);
- if (!QGLFormat::hasOpenGL() || !QGLFramebufferObject::hasOpenGLFramebufferObjects()) {
- QMessageBox::information(0, "OpenGL framebuffer objects 2",
- "This system does not support OpenGL/framebuffer objects.");
- return -1;
- }
-
- GLWidget widget(0);
- widget.resize(640, 480);
- widget.show();
- return a.exec();
-}
-
diff --git a/examples/opengl/legacy/grabber/glwidget.cpp b/examples/opengl/legacy/grabber/glwidget.cpp
deleted file mode 100644
index 6be4d30597..0000000000
--- a/examples/opengl/legacy/grabber/glwidget.cpp
+++ /dev/null
@@ -1,286 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the examples of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:BSD$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** BSD License Usage
-** Alternatively, you may use this file under the terms of the BSD license
-** as follows:
-**
-** "Redistribution and use in source and binary forms, with or without
-** modification, are permitted provided that the following conditions are
-** met:
-** * Redistributions of source code must retain the above copyright
-** notice, this list of conditions and the following disclaimer.
-** * Redistributions in binary form must reproduce the above copyright
-** notice, this list of conditions and the following disclaimer in
-** the documentation and/or other materials provided with the
-** distribution.
-** * 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.
-**
-**
-** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
-** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
-** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
-** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
-** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
-** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
-** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
-** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
-** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include "glwidget.h"
-
-#include <QMouseEvent>
-#include <QTimer>
-#include <qmath.h>
-
-GLWidget::GLWidget(QWidget *parent)
- : QGLWidget(parent)
-{
- gear1 = 0;
- gear2 = 0;
- gear3 = 0;
- xRot = 0;
- yRot = 0;
- zRot = 0;
- gear1Rot = 0;
-
- QTimer *timer = new QTimer(this);
- connect(timer, SIGNAL(timeout()), this, SLOT(advanceGears()));
- timer->start(20);
-}
-
-GLWidget::~GLWidget()
-{
- makeCurrent();
- glDeleteLists(gear1, 1);
- glDeleteLists(gear2, 1);
- glDeleteLists(gear3, 1);
-}
-
-void GLWidget::setXRotation(int angle)
-{
- normalizeAngle(&angle);
- if (angle != xRot) {
- xRot = angle;
- emit xRotationChanged(angle);
- updateGL();
- }
-}
-
-void GLWidget::setYRotation(int angle)
-{
- normalizeAngle(&angle);
- if (angle != yRot) {
- yRot = angle;
- emit yRotationChanged(angle);
- updateGL();
- }
-}
-
-void GLWidget::setZRotation(int angle)
-{
- normalizeAngle(&angle);
- if (angle != zRot) {
- zRot = angle;
- emit zRotationChanged(angle);
- updateGL();
- }
-}
-
-void GLWidget::initializeGL()
-{
- static const GLfloat lightPos[4] = { 5.0f, 5.0f, 10.0f, 1.0f };
- static const GLfloat reflectance1[4] = { 0.8f, 0.1f, 0.0f, 1.0f };
- static const GLfloat reflectance2[4] = { 0.0f, 0.8f, 0.2f, 1.0f };
- static const GLfloat reflectance3[4] = { 0.2f, 0.2f, 1.0f, 1.0f };
-
- glLightfv(GL_LIGHT0, GL_POSITION, lightPos);
- glEnable(GL_LIGHTING);
- glEnable(GL_LIGHT0);
- glEnable(GL_DEPTH_TEST);
-
- gear1 = makeGear(reflectance1, 1.0, 4.0, 1.0, 0.7, 20);
- gear2 = makeGear(reflectance2, 0.5, 2.0, 2.0, 0.7, 10);
- gear3 = makeGear(reflectance3, 1.3, 2.0, 0.5, 0.7, 10);
-
- glEnable(GL_NORMALIZE);
- glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
-}
-
-void GLWidget::paintGL()
-{
- glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
-
- glPushMatrix();
- glRotated(xRot / 16.0, 1.0, 0.0, 0.0);
- glRotated(yRot / 16.0, 0.0, 1.0, 0.0);
- glRotated(zRot / 16.0, 0.0, 0.0, 1.0);
-
- drawGear(gear1, -3.0, -2.0, 0.0, gear1Rot / 16.0);
- drawGear(gear2, +3.1, -2.0, 0.0, -2.0 * (gear1Rot / 16.0) - 9.0);
-
- glRotated(+90.0, 1.0, 0.0, 0.0);
- drawGear(gear3, -3.1, -1.8, -2.2, +2.0 * (gear1Rot / 16.0) - 2.0);
-
- glPopMatrix();
-}
-
-void GLWidget::resizeGL(int width, int height)
-{
- int side = qMin(width, height);
- glViewport((width - side) / 2, (height - side) / 2, side, side);
-
- glMatrixMode(GL_PROJECTION);
- glLoadIdentity();
- glFrustum(-1.0, +1.0, -1.0, 1.0, 5.0, 60.0);
- glMatrixMode(GL_MODELVIEW);
- glLoadIdentity();
- glTranslated(0.0, 0.0, -40.0);
-}
-
-void GLWidget::mousePressEvent(QMouseEvent *event)
-{
- lastPos = event->pos();
-}
-
-void GLWidget::mouseMoveEvent(QMouseEvent *event)
-{
- int dx = event->x() - lastPos.x();
- int dy = event->y() - lastPos.y();
-
- if (event->buttons() & Qt::LeftButton) {
- setXRotation(xRot + 8 * dy);
- setYRotation(yRot + 8 * dx);
- } else if (event->buttons() & Qt::RightButton) {
- setXRotation(xRot + 8 * dy);
- setZRotation(zRot + 8 * dx);
- }
- lastPos = event->pos();
-}
-
-void GLWidget::advanceGears()
-{
- gear1Rot += 2 * 16;
- updateGL();
-}
-
-GLuint GLWidget::makeGear(const GLfloat *reflectance, GLdouble innerRadius,
- GLdouble outerRadius, GLdouble thickness,
- GLdouble toothSize, GLint toothCount)
-{
- GLuint list = glGenLists(1);
- glNewList(list, GL_COMPILE);
- glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, reflectance);
-
- GLdouble r0 = innerRadius;
- GLdouble r1 = outerRadius - toothSize / 2.0;
- GLdouble r2 = outerRadius + toothSize / 2.0;
- GLdouble toothAngle = 2 * M_PI / toothCount;
- GLdouble delta = toothAngle / 4.0;
- GLdouble z = thickness / 2.0;
-
- glShadeModel(GL_FLAT);
-
- for (int i = 0; i < 2; ++i) {
- GLdouble sign = (i == 0) ? +1.0 : -1.0;
-
- glNormal3d(0.0, 0.0, sign);
-
- glBegin(GL_QUAD_STRIP);
- for (int j = 0; j <= toothCount; ++j) {
- GLdouble angle = j * toothAngle;
- glVertex3d(r0 * cos(angle), r0 * sin(angle), sign * z);
- glVertex3d(r1 * cos(angle), r1 * sin(angle), sign * z);
- glVertex3d(r0 * cos(angle), r0 * sin(angle), sign * z);
- glVertex3d(r1 * cos(angle + 3 * delta), r1 * sin(angle + 3 * delta), sign * z);
- }
- glEnd();
-
- glBegin(GL_QUADS);
- for (int j = 0; j < toothCount; ++j) {
- GLdouble angle = j * toothAngle;
- glVertex3d(r1 * cos(angle), r1 * sin(angle), sign * z);
- glVertex3d(r2 * cos(angle + delta), r2 * sin(angle + delta), sign * z);
- glVertex3d(r2 * cos(angle + 2 * delta), r2 * sin(angle + 2 * delta), sign * z);
- glVertex3d(r1 * cos(angle + 3 * delta), r1 * sin(angle + 3 * delta), sign * z);
- }
- glEnd();
- }
-
- glBegin(GL_QUAD_STRIP);
- for (int i = 0; i < toothCount; ++i) {
- for (int j = 0; j < 2; ++j) {
- GLdouble angle = (i + j / 2.0) * toothAngle;
- GLdouble s1 = r1;
- GLdouble s2 = r2;
- if (j == 1)
- qSwap(s1, s2);
-
- glNormal3d(cos(angle), sin(angle), 0.0);
- glVertex3d(s1 * cos(angle), s1 * sin(angle), +z);
- glVertex3d(s1 * cos(angle), s1 * sin(angle), -z);
-
- glNormal3d(s2 * sin(angle + delta) - s1 * sin(angle),
- s1 * cos(angle) - s2 * cos(angle + delta), 0.0);
- glVertex3d(s2 * cos(angle + delta), s2 * sin(angle + delta), +z);
- glVertex3d(s2 * cos(angle + delta), s2 * sin(angle + delta), -z);
- }
- }
- glVertex3d(r1, 0.0, +z);
- glVertex3d(r1, 0.0, -z);
- glEnd();
-
- glShadeModel(GL_SMOOTH);
-
- glBegin(GL_QUAD_STRIP);
- for (int i = 0; i <= toothCount; ++i) {
- GLdouble angle = i * toothAngle;
- glNormal3d(-cos(angle), -sin(angle), 0.0);
- glVertex3d(r0 * cos(angle), r0 * sin(angle), +z);
- glVertex3d(r0 * cos(angle), r0 * sin(angle), -z);
- }
- glEnd();
-
- glEndList();
-
- return list;
-}
-
-void GLWidget::drawGear(GLuint gear, GLdouble dx, GLdouble dy, GLdouble dz,
- GLdouble angle)
-{
- glPushMatrix();
- glTranslated(dx, dy, dz);
- glRotated(angle, 0.0, 0.0, 1.0);
- glCallList(gear);
- glPopMatrix();
-}
-
-void GLWidget::normalizeAngle(int *angle)
-{
- while (*angle < 0)
- *angle += 360 * 16;
- while (*angle > 360 * 16)
- *angle -= 360 * 16;
-}
diff --git a/examples/opengl/legacy/grabber/glwidget.h b/examples/opengl/legacy/grabber/glwidget.h
deleted file mode 100644
index 67020b0ada..0000000000
--- a/examples/opengl/legacy/grabber/glwidget.h
+++ /dev/null
@@ -1,107 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the examples of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:BSD$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** BSD License Usage
-** Alternatively, you may use this file under the terms of the BSD license
-** as follows:
-**
-** "Redistribution and use in source and binary forms, with or without
-** modification, are permitted provided that the following conditions are
-** met:
-** * Redistributions of source code must retain the above copyright
-** notice, this list of conditions and the following disclaimer.
-** * Redistributions in binary form must reproduce the above copyright
-** notice, this list of conditions and the following disclaimer in
-** the documentation and/or other materials provided with the
-** distribution.
-** * 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.
-**
-**
-** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
-** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
-** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
-** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
-** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
-** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
-** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
-** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
-** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef GLWIDGET_H
-#define GLWIDGET_H
-
-#include <QGLWidget>
-
-class GLWidget : public QGLWidget
-{
- Q_OBJECT
-
-public:
- GLWidget(QWidget *parent = 0);
- ~GLWidget();
-
- int xRotation() const { return xRot; }
- int yRotation() const { return yRot; }
- int zRotation() const { return zRot; }
-
-public slots:
- void setXRotation(int angle);
- void setYRotation(int angle);
- void setZRotation(int angle);
-
-signals:
- void xRotationChanged(int angle);
- void yRotationChanged(int angle);
- void zRotationChanged(int angle);
-
-protected:
- void initializeGL() override;
- void paintGL() override;
- void resizeGL(int width, int height) override;
- void mousePressEvent(QMouseEvent *event) override;
- void mouseMoveEvent(QMouseEvent *event) override;
-
-private slots:
- void advanceGears();
-
-private:
- GLuint makeGear(const GLfloat *reflectance, GLdouble innerRadius,
- GLdouble outerRadius, GLdouble thickness,
- GLdouble toothSize, GLint toothCount);
- void drawGear(GLuint gear, GLdouble dx, GLdouble dy, GLdouble dz,
- GLdouble angle);
- void normalizeAngle(int *angle);
-
- GLuint gear1;
- GLuint gear2;
- GLuint gear3;
- int xRot;
- int yRot;
- int zRot;
- int gear1Rot;
-
- QPoint lastPos;
-};
-
-#endif // GLWIDGET_H
diff --git a/examples/opengl/legacy/grabber/grabber.pro b/examples/opengl/legacy/grabber/grabber.pro
deleted file mode 100644
index 88c03f1c5e..0000000000
--- a/examples/opengl/legacy/grabber/grabber.pro
+++ /dev/null
@@ -1,12 +0,0 @@
-HEADERS = glwidget.h \
- mainwindow.h
-SOURCES = glwidget.cpp \
- main.cpp \
- mainwindow.cpp
-QT += opengl widgets
-
-# install
-target.path = $$[QT_INSTALL_EXAMPLES]/opengl/legacy/grabber
-INSTALLS += target
-
-qtConfig(opengles.|angle|dynamicgl): error("This example requires Qt to be configured with -opengl desktop")
diff --git a/examples/opengl/legacy/grabber/main.cpp b/examples/opengl/legacy/grabber/main.cpp
deleted file mode 100644
index e02118b078..0000000000
--- a/examples/opengl/legacy/grabber/main.cpp
+++ /dev/null
@@ -1,61 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the examples of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:BSD$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** BSD License Usage
-** Alternatively, you may use this file under the terms of the BSD license
-** as follows:
-**
-** "Redistribution and use in source and binary forms, with or without
-** modification, are permitted provided that the following conditions are
-** met:
-** * Redistributions of source code must retain the above copyright
-** notice, this list of conditions and the following disclaimer.
-** * Redistributions in binary form must reproduce the above copyright
-** notice, this list of conditions and the following disclaimer in
-** the documentation and/or other materials provided with the
-** distribution.
-** * 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.
-**
-**
-** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
-** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
-** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
-** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
-** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
-** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
-** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
-** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
-** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include "mainwindow.h"
-
-#include <QApplication>
-
-int main(int argc, char *argv[])
-{
- QApplication app(argc, argv);
- MainWindow window;
- window.show();
- return app.exec();
-}
diff --git a/examples/opengl/legacy/grabber/mainwindow.cpp b/examples/opengl/legacy/grabber/mainwindow.cpp
deleted file mode 100644
index 6ea6a28051..0000000000
--- a/examples/opengl/legacy/grabber/mainwindow.cpp
+++ /dev/null
@@ -1,216 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the examples of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:BSD$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** BSD License Usage
-** Alternatively, you may use this file under the terms of the BSD license
-** as follows:
-**
-** "Redistribution and use in source and binary forms, with or without
-** modification, are permitted provided that the following conditions are
-** met:
-** * Redistributions of source code must retain the above copyright
-** notice, this list of conditions and the following disclaimer.
-** * Redistributions in binary form must reproduce the above copyright
-** notice, this list of conditions and the following disclaimer in
-** the documentation and/or other materials provided with the
-** distribution.
-** * 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.
-**
-**
-** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
-** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
-** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
-** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
-** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
-** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
-** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
-** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
-** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include "glwidget.h"
-#include "mainwindow.h"
-
-#include <QtWidgets>
-
-MainWindow::MainWindow()
-{
- centralWidget = new QWidget;
- setCentralWidget(centralWidget);
-
- glWidget = new GLWidget;
- pixmapLabel = new QLabel;
-
- glWidgetArea = new QScrollArea;
- glWidgetArea->setWidget(glWidget);
- glWidgetArea->setWidgetResizable(true);
- glWidgetArea->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
- glWidgetArea->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
- glWidgetArea->setSizePolicy(QSizePolicy::Ignored, QSizePolicy::Ignored);
- glWidgetArea->setMinimumSize(50, 50);
-
- pixmapLabelArea = new QScrollArea;
- pixmapLabelArea->setWidget(pixmapLabel);
- pixmapLabelArea->setSizePolicy(QSizePolicy::Ignored, QSizePolicy::Ignored);
- pixmapLabelArea->setMinimumSize(50, 50);
-
- xSlider = createSlider(SIGNAL(xRotationChanged(int)),
- SLOT(setXRotation(int)));
- ySlider = createSlider(SIGNAL(yRotationChanged(int)),
- SLOT(setYRotation(int)));
- zSlider = createSlider(SIGNAL(zRotationChanged(int)),
- SLOT(setZRotation(int)));
-
- createActions();
- createMenus();
-
- QGridLayout *centralLayout = new QGridLayout;
- centralLayout->addWidget(glWidgetArea, 0, 0);
- centralLayout->addWidget(pixmapLabelArea, 0, 1);
- centralLayout->addWidget(xSlider, 1, 0, 1, 2);
- centralLayout->addWidget(ySlider, 2, 0, 1, 2);
- centralLayout->addWidget(zSlider, 3, 0, 1, 2);
- centralWidget->setLayout(centralLayout);
-
- xSlider->setValue(15 * 16);
- ySlider->setValue(345 * 16);
- zSlider->setValue(0 * 16);
-
- setWindowTitle(tr("Grabber"));
- resize(400, 300);
-}
-
-void MainWindow::renderIntoPixmap()
-{
- QSize size = getSize();
- if (size.isValid()) {
- QPixmap pixmap = glWidget->renderPixmap(size.width(), size.height());
- setPixmap(pixmap);
- }
-}
-
-void MainWindow::grabFrameBuffer()
-{
- QImage image = glWidget->grabFrameBuffer();
- setPixmap(QPixmap::fromImage(image));
-}
-
-void MainWindow::clearPixmap()
-{
- setPixmap(QPixmap());
-}
-
-void MainWindow::about()
-{
- QMessageBox::about(this, tr("About Grabber"),
- tr("The <b>Grabber</b> example demonstrates two approaches for "
- "rendering OpenGL into a Qt pixmap."));
-}
-
-void MainWindow::createActions()
-{
- renderIntoPixmapAct = new QAction(tr("&Render into Pixmap..."), this);
- renderIntoPixmapAct->setShortcut(tr("Ctrl+R"));
- connect(renderIntoPixmapAct, SIGNAL(triggered()),
- this, SLOT(renderIntoPixmap()));
-
- grabFrameBufferAct = new QAction(tr("&Grab Frame Buffer"), this);
- grabFrameBufferAct->setShortcut(tr("Ctrl+G"));
- connect(grabFrameBufferAct, SIGNAL(triggered()),
- this, SLOT(grabFrameBuffer()));
-
- clearPixmapAct = new QAction(tr("&Clear Pixmap"), this);
- clearPixmapAct->setShortcut(tr("Ctrl+L"));
- connect(clearPixmapAct, SIGNAL(triggered()), this, SLOT(clearPixmap()));
-
- exitAct = new QAction(tr("E&xit"), this);
- exitAct->setShortcuts(QKeySequence::Quit);
- connect(exitAct, SIGNAL(triggered()), this, SLOT(close()));
-
- aboutAct = new QAction(tr("&About"), this);
- connect(aboutAct, SIGNAL(triggered()), this, SLOT(about()));
-
- aboutQtAct = new QAction(tr("About &Qt"), this);
- connect(aboutQtAct, SIGNAL(triggered()), qApp, SLOT(aboutQt()));
-}
-
-void MainWindow::createMenus()
-{
- fileMenu = menuBar()->addMenu(tr("&File"));
- fileMenu->addAction(renderIntoPixmapAct);
- fileMenu->addAction(grabFrameBufferAct);
- fileMenu->addAction(clearPixmapAct);
- fileMenu->addSeparator();
- fileMenu->addAction(exitAct);
-
- helpMenu = menuBar()->addMenu(tr("&Help"));
- helpMenu->addAction(aboutAct);
- helpMenu->addAction(aboutQtAct);
-}
-
-QSlider *MainWindow::createSlider(const char *changedSignal,
- const char *setterSlot)
-{
- QSlider *slider = new QSlider(Qt::Horizontal);
- slider->setRange(0, 360 * 16);
- slider->setSingleStep(16);
- slider->setPageStep(15 * 16);
- slider->setTickInterval(15 * 16);
- slider->setTickPosition(QSlider::TicksRight);
- connect(slider, SIGNAL(valueChanged(int)), glWidget, setterSlot);
- connect(glWidget, changedSignal, slider, SLOT(setValue(int)));
- return slider;
-}
-
-void MainWindow::setPixmap(const QPixmap &pixmap)
-{
- pixmapLabel->setPixmap(pixmap);
- QSize size = pixmap.size() / pixmap.devicePixelRatio();
- if (size - QSize(1, 0) == pixmapLabelArea->maximumViewportSize())
- size -= QSize(1, 0);
- pixmapLabel->resize(size);
-}
-
-QSize MainWindow::getSize()
-{
- bool ok;
- QString text = QInputDialog::getText(this, tr("Grabber"),
- tr("Enter pixmap size:"),
- QLineEdit::Normal,
- tr("%1 x %2").arg(glWidget->width())
- .arg(glWidget->height()),
- &ok);
- if (!ok)
- return QSize();
-
- QRegularExpression regExp(tr("^([0-9]+) *x *([0-9]+)$"));
- QRegularExpressionMatch match = regExp.match(text);
- if (match.hasMatch()) {
- int width = match.captured(1).toInt();
- int height = match.captured(2).toInt();
- if (width > 0 && width < 2048 && height > 0 && height < 2048)
- return QSize(width, height);
- }
-
- return glWidget->size();
-}
diff --git a/examples/opengl/legacy/grabber/mainwindow.h b/examples/opengl/legacy/grabber/mainwindow.h
deleted file mode 100644
index 2d699784dd..0000000000
--- a/examples/opengl/legacy/grabber/mainwindow.h
+++ /dev/null
@@ -1,104 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the examples of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:BSD$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** BSD License Usage
-** Alternatively, you may use this file under the terms of the BSD license
-** as follows:
-**
-** "Redistribution and use in source and binary forms, with or without
-** modification, are permitted provided that the following conditions are
-** met:
-** * Redistributions of source code must retain the above copyright
-** notice, this list of conditions and the following disclaimer.
-** * Redistributions in binary form must reproduce the above copyright
-** notice, this list of conditions and the following disclaimer in
-** the documentation and/or other materials provided with the
-** distribution.
-** * 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.
-**
-**
-** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
-** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
-** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
-** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
-** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
-** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
-** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
-** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
-** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef MAINWINDOW_H
-#define MAINWINDOW_H
-
-#include <QMainWindow>
-
-QT_BEGIN_NAMESPACE
-class QLabel;
-class QMenu;
-class QScrollArea;
-class QSlider;
-QT_END_NAMESPACE
-
-class GLWidget;
-
-class MainWindow : public QMainWindow
-{
- Q_OBJECT
-
-public:
- MainWindow();
-
-private slots:
- void renderIntoPixmap();
- void grabFrameBuffer();
- void clearPixmap();
- void about();
-
-private:
- void createActions();
- void createMenus();
- QSlider *createSlider(const char *changedSignal, const char *setterSlot);
- void setPixmap(const QPixmap &pixmap);
- QSize getSize();
-
- QWidget *centralWidget;
- QScrollArea *glWidgetArea;
- QScrollArea *pixmapLabelArea;
- GLWidget *glWidget;
- QLabel *pixmapLabel;
- QSlider *xSlider;
- QSlider *ySlider;
- QSlider *zSlider;
-
- QMenu *fileMenu;
- QMenu *helpMenu;
- QAction *grabFrameBufferAct;
- QAction *renderIntoPixmapAct;
- QAction *clearPixmapAct;
- QAction *exitAct;
- QAction *aboutAct;
- QAction *aboutQtAct;
-};
-
-#endif // MAINWINDOW_H
diff --git a/examples/opengl/legacy/hellogl/glwidget.cpp b/examples/opengl/legacy/hellogl/glwidget.cpp
deleted file mode 100644
index 059a9bb96d..0000000000
--- a/examples/opengl/legacy/hellogl/glwidget.cpp
+++ /dev/null
@@ -1,207 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the examples of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:BSD$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** BSD License Usage
-** Alternatively, you may use this file under the terms of the BSD license
-** as follows:
-**
-** "Redistribution and use in source and binary forms, with or without
-** modification, are permitted provided that the following conditions are
-** met:
-** * Redistributions of source code must retain the above copyright
-** notice, this list of conditions and the following disclaimer.
-** * Redistributions in binary form must reproduce the above copyright
-** notice, this list of conditions and the following disclaimer in
-** the documentation and/or other materials provided with the
-** distribution.
-** * 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.
-**
-**
-** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
-** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
-** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
-** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
-** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
-** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
-** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
-** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
-** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include <QtWidgets>
-#include <QtOpenGL>
-
-#include <math.h>
-
-#include "glwidget.h"
-#include "qtlogo.h"
-
-#ifndef GL_MULTISAMPLE
-#define GL_MULTISAMPLE 0x809D
-#endif
-
-//! [0]
-GLWidget::GLWidget(QWidget *parent)
- : QGLWidget(QGLFormat(QGL::SampleBuffers), parent)
-{
- logo = 0;
- xRot = 0;
- yRot = 0;
- zRot = 0;
-
- qtGreen = QColor::fromCmykF(0.40, 0.0, 1.0, 0.0);
- qtPurple = QColor::fromCmykF(0.39, 0.39, 0.0, 0.0);
-}
-//! [0]
-
-//! [1]
-GLWidget::~GLWidget()
-{
-}
-//! [1]
-
-//! [2]
-QSize GLWidget::minimumSizeHint() const
-{
- return QSize(50, 50);
-}
-//! [2]
-
-//! [3]
-QSize GLWidget::sizeHint() const
-//! [3] //! [4]
-{
- return QSize(400, 400);
-}
-//! [4]
-
-static void qNormalizeAngle(int &angle)
-{
- while (angle < 0)
- angle += 360 * 16;
- while (angle > 360 * 16)
- angle -= 360 * 16;
-}
-
-//! [5]
-void GLWidget::setXRotation(int angle)
-{
- qNormalizeAngle(angle);
- if (angle != xRot) {
- xRot = angle;
- emit xRotationChanged(angle);
- update();
- }
-}
-//! [5]
-
-void GLWidget::setYRotation(int angle)
-{
- qNormalizeAngle(angle);
- if (angle != yRot) {
- yRot = angle;
- emit yRotationChanged(angle);
- update();
- }
-}
-
-void GLWidget::setZRotation(int angle)
-{
- qNormalizeAngle(angle);
- if (angle != zRot) {
- zRot = angle;
- emit zRotationChanged(angle);
- update();
- }
-}
-
-//! [6]
-void GLWidget::initializeGL()
-{
- initializeOpenGLFunctions();
-
- qglClearColor(qtPurple.darker());
-
- logo = new QtLogo(this, 64);
- logo->setColor(qtGreen.darker());
-
- glEnable(GL_DEPTH_TEST);
- glEnable(GL_CULL_FACE);
- glShadeModel(GL_SMOOTH);
- glEnable(GL_LIGHTING);
- glEnable(GL_LIGHT0);
- glEnable(GL_MULTISAMPLE);
- static GLfloat lightPosition[4] = { 0.5, 5.0, 7.0, 1.0 };
- glLightfv(GL_LIGHT0, GL_POSITION, lightPosition);
-}
-//! [6]
-
-//! [7]
-void GLWidget::paintGL()
-{
- glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
- glLoadIdentity();
- glTranslatef(0.0, 0.0, -10.0);
- glRotatef(xRot / 16.0, 1.0, 0.0, 0.0);
- glRotatef(yRot / 16.0, 0.0, 1.0, 0.0);
- glRotatef(zRot / 16.0, 0.0, 0.0, 1.0);
- logo->draw(static_cast<QOpenGLFunctions_1_1 *>(this));
-}
-//! [7]
-
-//! [8]
-void GLWidget::resizeGL(int width, int height)
-{
- int side = qMin(width, height);
- glViewport((width - side) / 2, (height - side) / 2, side, side);
-
- glMatrixMode(GL_PROJECTION);
- glLoadIdentity();
- glOrtho(-0.5, +0.5, -0.5, +0.5, 4.0, 15.0);
- glMatrixMode(GL_MODELVIEW);
-}
-//! [8]
-
-//! [9]
-void GLWidget::mousePressEvent(QMouseEvent *event)
-{
- lastPos = event->pos();
-}
-//! [9]
-
-//! [10]
-void GLWidget::mouseMoveEvent(QMouseEvent *event)
-{
- int dx = event->x() - lastPos.x();
- int dy = event->y() - lastPos.y();
-
- if (event->buttons() & Qt::LeftButton) {
- setXRotation(xRot + 8 * dy);
- setYRotation(yRot + 8 * dx);
- } else if (event->buttons() & Qt::RightButton) {
- setXRotation(xRot + 8 * dy);
- setZRotation(zRot + 8 * dx);
- }
- lastPos = event->pos();
-}
-//! [10]
diff --git a/examples/opengl/legacy/hellogl/glwidget.h b/examples/opengl/legacy/hellogl/glwidget.h
deleted file mode 100644
index 8154d7405c..0000000000
--- a/examples/opengl/legacy/hellogl/glwidget.h
+++ /dev/null
@@ -1,105 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the examples of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:BSD$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** BSD License Usage
-** Alternatively, you may use this file under the terms of the BSD license
-** as follows:
-**
-** "Redistribution and use in source and binary forms, with or without
-** modification, are permitted provided that the following conditions are
-** met:
-** * Redistributions of source code must retain the above copyright
-** notice, this list of conditions and the following disclaimer.
-** * Redistributions in binary form must reproduce the above copyright
-** notice, this list of conditions and the following disclaimer in
-** the documentation and/or other materials provided with the
-** distribution.
-** * 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.
-**
-**
-** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
-** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
-** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
-** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
-** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
-** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
-** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
-** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
-** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef GLWIDGET_H
-#define GLWIDGET_H
-
-#include <QGLWidget>
-#include <QOpenGLFunctions_1_1>
-
-class QtLogo;
-
-//! [0]
-class GLWidget : public QGLWidget, public QOpenGLFunctions_1_1
-{
- Q_OBJECT
-
-public:
- GLWidget(QWidget *parent = 0);
- ~GLWidget();
-
- QSize minimumSizeHint() const override;
- QSize sizeHint() const override;
-//! [0]
-
-//! [1]
-public slots:
- void setXRotation(int angle);
- void setYRotation(int angle);
- void setZRotation(int angle);
-
-signals:
- void xRotationChanged(int angle);
- void yRotationChanged(int angle);
- void zRotationChanged(int angle);
-//! [1]
-
-//! [2]
-protected:
- void initializeGL() override;
- void paintGL() override;
- void resizeGL(int width, int height) override;
- void mousePressEvent(QMouseEvent *event) override;
- void mouseMoveEvent(QMouseEvent *event) override;
-//! [2]
-
-//! [3]
-private:
- QtLogo *logo;
- int xRot;
- int yRot;
- int zRot;
- QPoint lastPos;
- QColor qtGreen;
- QColor qtPurple;
-};
-//! [3]
-
-#endif
diff --git a/examples/opengl/legacy/hellogl/hellogl.pro b/examples/opengl/legacy/hellogl/hellogl.pro
deleted file mode 100644
index c6e926c245..0000000000
--- a/examples/opengl/legacy/hellogl/hellogl.pro
+++ /dev/null
@@ -1,17 +0,0 @@
-VPATH += ../shared
-INCLUDEPATH += ../shared
-
-HEADERS = glwidget.h \
- window.h \
- qtlogo.h
-SOURCES = glwidget.cpp \
- main.cpp \
- window.cpp \
- qtlogo.cpp
-QT += opengl widgets
-
-# install
-target.path = $$[QT_INSTALL_EXAMPLES]/opengl/legacy/hellogl
-INSTALLS += target
-
-qtConfig(opengles.|angle): error("This example requires Qt to be configured with -opengl desktop")
diff --git a/examples/opengl/legacy/hellogl/main.cpp b/examples/opengl/legacy/hellogl/main.cpp
deleted file mode 100644
index 13581c8fb2..0000000000
--- a/examples/opengl/legacy/hellogl/main.cpp
+++ /dev/null
@@ -1,69 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the examples of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:BSD$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** BSD License Usage
-** Alternatively, you may use this file under the terms of the BSD license
-** as follows:
-**
-** "Redistribution and use in source and binary forms, with or without
-** modification, are permitted provided that the following conditions are
-** met:
-** * Redistributions of source code must retain the above copyright
-** notice, this list of conditions and the following disclaimer.
-** * Redistributions in binary form must reproduce the above copyright
-** notice, this list of conditions and the following disclaimer in
-** the documentation and/or other materials provided with the
-** distribution.
-** * 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.
-**
-**
-** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
-** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
-** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
-** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
-** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
-** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
-** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
-** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
-** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include <QApplication>
-#include <QDesktopWidget>
-
-#include "window.h"
-
-int main(int argc, char *argv[])
-{
- QApplication app(argc, argv);
- Window window;
- window.resize(window.sizeHint());
- int desktopArea = QApplication::desktop()->width() *
- QApplication::desktop()->height();
- int widgetArea = window.width() * window.height();
- if (((float)widgetArea / (float)desktopArea) < 0.75f)
- window.show();
- else
- window.showMaximized();
- return app.exec();
-}
diff --git a/examples/opengl/legacy/hellogl/window.cpp b/examples/opengl/legacy/hellogl/window.cpp
deleted file mode 100644
index 58863909e0..0000000000
--- a/examples/opengl/legacy/hellogl/window.cpp
+++ /dev/null
@@ -1,107 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the examples of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:BSD$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** BSD License Usage
-** Alternatively, you may use this file under the terms of the BSD license
-** as follows:
-**
-** "Redistribution and use in source and binary forms, with or without
-** modification, are permitted provided that the following conditions are
-** met:
-** * Redistributions of source code must retain the above copyright
-** notice, this list of conditions and the following disclaimer.
-** * Redistributions in binary form must reproduce the above copyright
-** notice, this list of conditions and the following disclaimer in
-** the documentation and/or other materials provided with the
-** distribution.
-** * 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.
-**
-**
-** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
-** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
-** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
-** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
-** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
-** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
-** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
-** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
-** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include <QtWidgets>
-
-#include "glwidget.h"
-#include "window.h"
-
-//! [0]
-Window::Window()
-{
- glWidget = new GLWidget;
-
- xSlider = createSlider();
- ySlider = createSlider();
- zSlider = createSlider();
-
- connect(xSlider, SIGNAL(valueChanged(int)), glWidget, SLOT(setXRotation(int)));
- connect(glWidget, SIGNAL(xRotationChanged(int)), xSlider, SLOT(setValue(int)));
- connect(ySlider, SIGNAL(valueChanged(int)), glWidget, SLOT(setYRotation(int)));
- connect(glWidget, SIGNAL(yRotationChanged(int)), ySlider, SLOT(setValue(int)));
- connect(zSlider, SIGNAL(valueChanged(int)), glWidget, SLOT(setZRotation(int)));
- connect(glWidget, SIGNAL(zRotationChanged(int)), zSlider, SLOT(setValue(int)));
-//! [0]
-
-//! [1]
- QHBoxLayout *mainLayout = new QHBoxLayout;
- mainLayout->addWidget(glWidget);
- mainLayout->addWidget(xSlider);
- mainLayout->addWidget(ySlider);
- mainLayout->addWidget(zSlider);
- setLayout(mainLayout);
-
- xSlider->setValue(15 * 16);
- ySlider->setValue(345 * 16);
- zSlider->setValue(0 * 16);
- setWindowTitle(tr("Hello GL"));
-}
-//! [1]
-
-//! [2]
-QSlider *Window::createSlider()
-{
- QSlider *slider = new QSlider(Qt::Vertical);
- slider->setRange(0, 360 * 16);
- slider->setSingleStep(16);
- slider->setPageStep(15 * 16);
- slider->setTickInterval(15 * 16);
- slider->setTickPosition(QSlider::TicksRight);
- return slider;
-}
-//! [2]
-
-void Window::keyPressEvent(QKeyEvent *e)
-{
- if (e->key() == Qt::Key_Escape)
- close();
- else
- QWidget::keyPressEvent(e);
-}
diff --git a/examples/opengl/legacy/hellogl/window.h b/examples/opengl/legacy/hellogl/window.h
deleted file mode 100644
index 04e83694a4..0000000000
--- a/examples/opengl/legacy/hellogl/window.h
+++ /dev/null
@@ -1,82 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the examples of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:BSD$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** BSD License Usage
-** Alternatively, you may use this file under the terms of the BSD license
-** as follows:
-**
-** "Redistribution and use in source and binary forms, with or without
-** modification, are permitted provided that the following conditions are
-** met:
-** * Redistributions of source code must retain the above copyright
-** notice, this list of conditions and the following disclaimer.
-** * Redistributions in binary form must reproduce the above copyright
-** notice, this list of conditions and the following disclaimer in
-** the documentation and/or other materials provided with the
-** distribution.
-** * 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.
-**
-**
-** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
-** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
-** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
-** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
-** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
-** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
-** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
-** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
-** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef WINDOW_H
-#define WINDOW_H
-
-#include <QWidget>
-
-QT_BEGIN_NAMESPACE
-class QSlider;
-QT_END_NAMESPACE
-//! [0]
-class GLWidget;
-
-class Window : public QWidget
-{
- Q_OBJECT
-
-public:
- Window();
-
-protected:
- void keyPressEvent(QKeyEvent *event) override;
-
-private:
- QSlider *createSlider();
-
- GLWidget *glWidget;
- QSlider *xSlider;
- QSlider *ySlider;
- QSlider *zSlider;
-};
-//! [0]
-
-#endif
diff --git a/examples/opengl/legacy/legacy.pro b/examples/opengl/legacy/legacy.pro
deleted file mode 100644
index 1398332c11..0000000000
--- a/examples/opengl/legacy/legacy.pro
+++ /dev/null
@@ -1,16 +0,0 @@
-requires(qtHaveModule(opengl))
-
-TEMPLATE = subdirs
-
-!qtConfig(dynamicgl):!qtConfig(opengles2) {
- # legacy desktop-only examples, no dynamic GL support
- SUBDIRS = \
- grabber \
- hellogl \
- overpainting \
- pbuffers \
- framebufferobject2 \
- samplebuffers
-}
-
-EXAMPLE_FILES = shared
diff --git a/examples/opengl/legacy/overpainting/bubble.cpp b/examples/opengl/legacy/overpainting/bubble.cpp
deleted file mode 100644
index 352e359cf9..0000000000
--- a/examples/opengl/legacy/overpainting/bubble.cpp
+++ /dev/null
@@ -1,122 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the examples of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:BSD$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** BSD License Usage
-** Alternatively, you may use this file under the terms of the BSD license
-** as follows:
-**
-** "Redistribution and use in source and binary forms, with or without
-** modification, are permitted provided that the following conditions are
-** met:
-** * Redistributions of source code must retain the above copyright
-** notice, this list of conditions and the following disclaimer.
-** * Redistributions in binary form must reproduce the above copyright
-** notice, this list of conditions and the following disclaimer in
-** the documentation and/or other materials provided with the
-** distribution.
-** * 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.
-**
-**
-** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
-** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
-** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
-** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
-** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
-** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
-** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
-** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
-** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include "bubble.h"
-
-#include <QRandomGenerator>
-
-Bubble::Bubble(const QPointF &position, qreal radius, const QPointF &velocity)
- : position(position), vel(velocity), radius(radius)
-{
- innerColor = randomColor();
- outerColor = randomColor();
- updateBrush();
-}
-
-void Bubble::updateBrush()
-{
- QRadialGradient gradient(QPointF(radius, radius), radius,
- QPointF(radius*0.5, radius*0.5));
-
- gradient.setColorAt(0, QColor(255, 255, 255, 255));
- gradient.setColorAt(0.25, innerColor);
- gradient.setColorAt(1, outerColor);
- brush = QBrush(gradient);
-}
-
-void Bubble::drawBubble(QPainter *painter)
-{
- painter->save();
- painter->translate(position.x() - radius, position.y() - radius);
- painter->setBrush(brush);
- painter->drawEllipse(0, 0, int(2*radius), int(2*radius));
- painter->restore();
-}
-
-QColor Bubble::randomColor()
-{
- int red = int(205 + QRandomGenerator::global()->bounded(50));
- int green = int(205 + QRandomGenerator::global()->bounded(50));
- int blue = int(205 + QRandomGenerator::global()->bounded(50));
- int alpha = int(91 + QRandomGenerator::global()->bounded(100));
-
- return QColor(red, green, blue, alpha);
-}
-
-void Bubble::move(const QRect &bbox)
-{
- position += vel;
- qreal leftOverflow = position.x() - radius - bbox.left();
- qreal rightOverflow = position.x() + radius - bbox.right();
- qreal topOverflow = position.y() - radius - bbox.top();
- qreal bottomOverflow = position.y() + radius - bbox.bottom();
-
- if (leftOverflow < 0.0) {
- position.setX(position.x() - 2 * leftOverflow);
- vel.setX(-vel.x());
- } else if (rightOverflow > 0.0) {
- position.setX(position.x() - 2 * rightOverflow);
- vel.setX(-vel.x());
- }
-
- if (topOverflow < 0.0) {
- position.setY(position.y() - 2 * topOverflow);
- vel.setY(-vel.y());
- } else if (bottomOverflow > 0.0) {
- position.setY(position.y() - 2 * bottomOverflow);
- vel.setY(-vel.y());
- }
-}
-
-QRectF Bubble::rect()
-{
- return QRectF(position.x() - radius, position.y() - radius,
- 2 * radius, 2 * radius);
-}
diff --git a/examples/opengl/legacy/overpainting/bubble.h b/examples/opengl/legacy/overpainting/bubble.h
deleted file mode 100644
index bd63e0437f..0000000000
--- a/examples/opengl/legacy/overpainting/bubble.h
+++ /dev/null
@@ -1,77 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the examples of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:BSD$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** BSD License Usage
-** Alternatively, you may use this file under the terms of the BSD license
-** as follows:
-**
-** "Redistribution and use in source and binary forms, with or without
-** modification, are permitted provided that the following conditions are
-** met:
-** * Redistributions of source code must retain the above copyright
-** notice, this list of conditions and the following disclaimer.
-** * Redistributions in binary form must reproduce the above copyright
-** notice, this list of conditions and the following disclaimer in
-** the documentation and/or other materials provided with the
-** distribution.
-** * 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.
-**
-**
-** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
-** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
-** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
-** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
-** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
-** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
-** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
-** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
-** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef BUBBLE_H
-#define BUBBLE_H
-
-#include <QPainter>
-
-class Bubble
-{
-public:
- Bubble(const QPointF &position, qreal radius, const QPointF &velocity);
-
- void drawBubble(QPainter *painter);
- void updateBrush();
- void move(const QRect &bbox);
- QRectF rect();
-
-private:
- QColor randomColor();
-
- QBrush brush;
- QPointF position;
- QPointF vel;
- qreal radius;
- QColor innerColor;
- QColor outerColor;
-};
-
-#endif // BUBBLE_H
diff --git a/examples/opengl/legacy/overpainting/glwidget.cpp b/examples/opengl/legacy/overpainting/glwidget.cpp
deleted file mode 100644
index c4558ce785..0000000000
--- a/examples/opengl/legacy/overpainting/glwidget.cpp
+++ /dev/null
@@ -1,293 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the examples of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:BSD$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** BSD License Usage
-** Alternatively, you may use this file under the terms of the BSD license
-** as follows:
-**
-** "Redistribution and use in source and binary forms, with or without
-** modification, are permitted provided that the following conditions are
-** met:
-** * Redistributions of source code must retain the above copyright
-** notice, this list of conditions and the following disclaimer.
-** * Redistributions in binary form must reproduce the above copyright
-** notice, this list of conditions and the following disclaimer in
-** the documentation and/or other materials provided with the
-** distribution.
-** * 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.
-**
-**
-** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
-** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
-** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
-** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
-** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
-** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
-** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
-** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
-** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include "bubble.h"
-#include "qtlogo.h"
-#include "glwidget.h"
-
-#include <QMouseEvent>
-#include <QRandomGenerator>
-#include <QTime>
-
-#include <math.h>
-#include <stdlib.h>
-
-#ifndef GL_MULTISAMPLE
-#define GL_MULTISAMPLE 0x809D
-#endif
-
-//! [0]
-GLWidget::GLWidget(QWidget *parent)
- : QGLWidget(QGLFormat(QGL::SampleBuffers), parent)
-{
- QTime midnight(0, 0, 0);
-
- logo = 0;
- xRot = 0;
- yRot = 0;
- zRot = 0;
-
- qtGreen = QColor::fromCmykF(0.40, 0.0, 1.0, 0.0);
- qtPurple = QColor::fromCmykF(0.39, 0.39, 0.0, 0.0);
-
- animationTimer.setSingleShot(false);
- connect(&animationTimer, SIGNAL(timeout()), this, SLOT(animate()));
- animationTimer.start(25);
-
- setAutoFillBackground(false);
- setMinimumSize(200, 200);
- setWindowTitle(tr("Overpainting a Scene"));
-}
-//! [0]
-
-//! [1]
-GLWidget::~GLWidget()
-{
-}
-//! [1]
-
-static void qNormalizeAngle(int &angle)
-{
- while (angle < 0)
- angle += 360 * 16;
- while (angle > 360 * 16)
- angle -= 360 * 16;
-}
-
-void GLWidget::setXRotation(int angle)
-{
- qNormalizeAngle(angle);
- if (angle != xRot)
- xRot = angle;
-}
-
-void GLWidget::setYRotation(int angle)
-{
- qNormalizeAngle(angle);
- if (angle != yRot)
- yRot = angle;
-}
-
-void GLWidget::setZRotation(int angle)
-{
- qNormalizeAngle(angle);
- if (angle != zRot)
- zRot = angle;
-}
-
-//! [2]
-void GLWidget::initializeGL()
-{
- initializeOpenGLFunctions();
-
- glEnable(GL_MULTISAMPLE);
-
- logo = new QtLogo(this);
- logo->setColor(qtGreen.darker());
-}
-//! [2]
-
-void GLWidget::mousePressEvent(QMouseEvent *event)
-{
- lastPos = event->pos();
-}
-
-void GLWidget::mouseMoveEvent(QMouseEvent *event)
-{
- int dx = event->x() - lastPos.x();
- int dy = event->y() - lastPos.y();
-
- if (event->buttons() & Qt::LeftButton) {
- setXRotation(xRot + 8 * dy);
- setYRotation(yRot + 8 * dx);
- } else if (event->buttons() & Qt::RightButton) {
- setXRotation(xRot + 8 * dy);
- setZRotation(zRot + 8 * dx);
- }
- lastPos = event->pos();
-}
-
-void GLWidget::paintEvent(QPaintEvent *event)
-{
- makeCurrent();
-//! [4]
- glMatrixMode(GL_MODELVIEW);
- glPushMatrix();
-//! [4]
-
-//! [6]
- qglClearColor(qtPurple.darker());
- glShadeModel(GL_SMOOTH);
- glEnable(GL_DEPTH_TEST);
- glEnable(GL_CULL_FACE);
- glEnable(GL_LIGHTING);
- glEnable(GL_LIGHT0);
- glEnable(GL_MULTISAMPLE);
- static GLfloat lightPosition[4] = { 0.5, 5.0, 7.0, 1.0 };
- glLightfv(GL_LIGHT0, GL_POSITION, lightPosition);
-
- qreal pixelRatio = devicePixelRatio();
- setupViewport(width() * pixelRatio, height() * pixelRatio);
-//! [6]
-
-//! [7]
- glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
- glLoadIdentity();
- glTranslatef(0.0, 0.0, -10.0);
- glRotatef(xRot / 16.0, 1.0, 0.0, 0.0);
- glRotatef(yRot / 16.0, 0.0, 1.0, 0.0);
- glRotatef(zRot / 16.0, 0.0, 0.0, 1.0);
-
- logo->draw(static_cast<QOpenGLFunctions_1_1 *>(this));
-//! [7]
-
-//! [8]
- glShadeModel(GL_FLAT);
- glDisable(GL_CULL_FACE);
- glDisable(GL_DEPTH_TEST);
- glDisable(GL_LIGHTING);
-
- glMatrixMode(GL_MODELVIEW);
- glPopMatrix();
-//! [8]
-
-//! [10]
- QPainter painter(this);
- painter.setRenderHint(QPainter::Antialiasing);
- for (Bubble *bubble : qAsConst(bubbles)) {
- if (bubble->rect().intersects(event->rect()))
- bubble->drawBubble(&painter);
- }
- drawInstructions(&painter);
- painter.end();
-}
-//! [10]
-
-//! [11]
-void GLWidget::resizeGL(int width, int height)
-{
- qreal pixelRatio = devicePixelRatio();
- setupViewport(width*pixelRatio, height*pixelRatio);
-}
-//! [11]
-
-//! [12]
-void GLWidget::showEvent(QShowEvent *event)
-{
- Q_UNUSED(event);
- createBubbles(20 - bubbles.count());
-}
-//! [12]
-
-QSize GLWidget::sizeHint() const
-{
- return QSize(400, 400);
-}
-
-void GLWidget::createBubbles(int number)
-{
- for (int i = 0; i < number; ++i) {
- QPointF position(width()*(0.1 + QRandomGenerator::global()->bounded(0.8)),
- height()*(0.1 + QRandomGenerator::global()->bounded(0.8)));
- qreal radius = qMin(width(), height())*(0.0125 + QRandomGenerator::global()->bounded(0.0875));
- QPointF velocity(width()*0.0125*(-0.5 + QRandomGenerator::global()->bounded(1.0)),
- height()*0.0125*(-0.5 + QRandomGenerator::global()->bounded(1.0)));
-
- bubbles.append(new Bubble(position, radius, velocity));
- }
-}
-
-//! [13]
-void GLWidget::animate()
-{
- for (Bubble *bubble : qAsConst(bubbles))
- bubble->move(rect());
- update();
-}
-//! [13]
-
-//! [14]
-void GLWidget::setupViewport(int width, int height)
-{
- int side = qMin(width, height);
- glViewport((width - side) / 2, (height - side) / 2, side, side);
-
- glMatrixMode(GL_PROJECTION);
- glLoadIdentity();
-#ifdef QT_OPENGL_ES
- glOrthof(-0.5, +0.5, -0.5, 0.5, 4.0, 15.0);
-#else
- glOrtho(-0.5, +0.5, -0.5, 0.5, 4.0, 15.0);
-#endif
- glMatrixMode(GL_MODELVIEW);
-}
-//! [14]
-
-//! [15]
-void GLWidget::drawInstructions(QPainter *painter)
-{
- QString text = tr("Click and drag with the left mouse button "
- "to rotate the Qt logo.");
- QFontMetrics metrics = QFontMetrics(font());
- int border = qMax(4, metrics.leading());
-
- QRect rect = metrics.boundingRect(0, 0, width() - 2*border, int(height()*0.125),
- Qt::AlignCenter | Qt::TextWordWrap, text);
- painter->setRenderHint(QPainter::TextAntialiasing);
- painter->fillRect(QRect(0, 0, width(), rect.height() + 2*border),
- QColor(0, 0, 0, 127));
- painter->setPen(Qt::white);
- painter->fillRect(QRect(0, 0, width(), rect.height() + 2*border),
- QColor(0, 0, 0, 127));
- painter->drawText((width() - rect.width())/2, border,
- rect.width(), rect.height(),
- Qt::AlignCenter | Qt::TextWordWrap, text);
-}
-//! [15]
diff --git a/examples/opengl/legacy/overpainting/glwidget.h b/examples/opengl/legacy/overpainting/glwidget.h
deleted file mode 100644
index e5ea539f6d..0000000000
--- a/examples/opengl/legacy/overpainting/glwidget.h
+++ /dev/null
@@ -1,114 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the examples of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:BSD$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** BSD License Usage
-** Alternatively, you may use this file under the terms of the BSD license
-** as follows:
-**
-** "Redistribution and use in source and binary forms, with or without
-** modification, are permitted provided that the following conditions are
-** met:
-** * Redistributions of source code must retain the above copyright
-** notice, this list of conditions and the following disclaimer.
-** * Redistributions in binary form must reproduce the above copyright
-** notice, this list of conditions and the following disclaimer in
-** the documentation and/or other materials provided with the
-** distribution.
-** * 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.
-**
-**
-** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
-** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
-** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
-** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
-** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
-** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
-** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
-** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
-** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef GLWIDGET_H
-#define GLWIDGET_H
-
-#include <QGLWidget>
-#include <QOpenGLFunctions_1_1>
-#include <QTimer>
-
-class Bubble;
-class QtLogo;
-
-//! [0]
-class GLWidget : public QGLWidget, public QOpenGLFunctions_1_1
-{
- Q_OBJECT
-
-public:
- GLWidget(QWidget *parent = 0);
- ~GLWidget();
-//! [0]
-
- QSize sizeHint() const override;
- int xRotation() const { return xRot; }
- int yRotation() const { return yRot; }
- int zRotation() const { return zRot; }
-
-public slots:
- void setXRotation(int angle);
- void setYRotation(int angle);
- void setZRotation(int angle);
-
-//! [1]
-protected:
- void initializeGL() override;
- void paintEvent(QPaintEvent *event) override;
- void resizeGL(int width, int height) override;
- void mousePressEvent(QMouseEvent *event) override;
- void mouseMoveEvent(QMouseEvent *event) override;
- void showEvent(QShowEvent *event) override;
-
-private slots:
- void animate();
-
-private:
- void createBubbles(int number);
- void drawInstructions(QPainter *painter);
-//! [1]
- void setupViewport(int width, int height);
-
- QColor qtGreen;
- QColor qtPurple;
-
- GLuint object;
- int xRot;
- int yRot;
- int zRot;
- QPoint lastPos;
-//! [4]
- QtLogo *logo;
- QList<Bubble*> bubbles;
- QTimer animationTimer;
-//! [4]
-};
-
-#endif // GLWIDGET_H
diff --git a/examples/opengl/legacy/overpainting/main.cpp b/examples/opengl/legacy/overpainting/main.cpp
deleted file mode 100644
index c5f0f2e3f7..0000000000
--- a/examples/opengl/legacy/overpainting/main.cpp
+++ /dev/null
@@ -1,61 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the examples of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:BSD$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** BSD License Usage
-** Alternatively, you may use this file under the terms of the BSD license
-** as follows:
-**
-** "Redistribution and use in source and binary forms, with or without
-** modification, are permitted provided that the following conditions are
-** met:
-** * Redistributions of source code must retain the above copyright
-** notice, this list of conditions and the following disclaimer.
-** * Redistributions in binary form must reproduce the above copyright
-** notice, this list of conditions and the following disclaimer in
-** the documentation and/or other materials provided with the
-** distribution.
-** * 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.
-**
-**
-** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
-** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
-** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
-** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
-** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
-** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
-** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
-** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
-** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include "glwidget.h"
-
-#include <QApplication>
-
-int main(int argc, char *argv[])
-{
- QApplication app(argc, argv);
- GLWidget window;
- window.show();
- return app.exec();
-}
diff --git a/examples/opengl/legacy/overpainting/overpainting.pro b/examples/opengl/legacy/overpainting/overpainting.pro
deleted file mode 100644
index 17213a6079..0000000000
--- a/examples/opengl/legacy/overpainting/overpainting.pro
+++ /dev/null
@@ -1,19 +0,0 @@
-QT += opengl widgets
-
-VPATH += ../shared
-INCLUDEPATH += ../shared
-
-HEADERS = bubble.h \
- glwidget.h \
- qtlogo.h
-
-SOURCES = bubble.cpp \
- glwidget.cpp \
- main.cpp \
- qtlogo.cpp
-
-# install
-target.path = $$[QT_INSTALL_EXAMPLES]/opengl/legacy/overpainting
-INSTALLS += target
-
-qtConfig(opengles.|angle): error("This example requires Qt to be configured with -opengl desktop")
diff --git a/examples/opengl/legacy/pbuffers/cube.cpp b/examples/opengl/legacy/pbuffers/cube.cpp
deleted file mode 100644
index f598741ec3..0000000000
--- a/examples/opengl/legacy/pbuffers/cube.cpp
+++ /dev/null
@@ -1,338 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the examples of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:BSD$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** BSD License Usage
-** Alternatively, you may use this file under the terms of the BSD license
-** as follows:
-**
-** "Redistribution and use in source and binary forms, with or without
-** modification, are permitted provided that the following conditions are
-** met:
-** * Redistributions of source code must retain the above copyright
-** notice, this list of conditions and the following disclaimer.
-** * Redistributions in binary form must reproduce the above copyright
-** notice, this list of conditions and the following disclaimer in
-** the documentation and/or other materials provided with the
-** distribution.
-** * 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.
-**
-**
-** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
-** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
-** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
-** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
-** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
-** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
-** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
-** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
-** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include "cube.h"
-#include "glwidget.h"
-
-#include <QtGui/QImage>
-#include <QtCore/QPropertyAnimation>
-
-static const qreal speeds[] = { 3.8f, 4.4f, 5.6f };
-static const qreal amplitudes[] = { 2.0f, 2.5f, 3.0f };
-
-static inline void qSetColor(float colorVec[], QColor c)
-{
- colorVec[0] = c.redF();
- colorVec[1] = c.greenF();
- colorVec[2] = c.blueF();
- colorVec[3] = c.alphaF();
-}
-
-int Geometry::append(const QVector3D &a, const QVector3D &n, const QVector2D &t)
-{
- int v = vertices.count();
- vertices.append(a);
- normals.append(n);
- texCoords.append(t);
- faces.append(v);
- colors.append(QVector4D(0.6f, 0.6f, 0.6f, 1.0f));
- return v;
-}
-
-void Geometry::addQuad(const QVector3D &a, const QVector3D &b,
- const QVector3D &c, const QVector3D &d,
- const QVector<QVector2D> &tex)
-{
- QVector3D norm = QVector3D::normal(a, b, c);
- // append first triangle
- int aref = append(a, norm, tex[0]);
- append(b, norm, tex[1]);
- int cref = append(c, norm, tex[2]);
- // append second triangle
- faces.append(aref);
- faces.append(cref);
- append(d, norm, tex[3]);
-}
-
-void Geometry::loadArrays() const
-{
- glEnableClientState(GL_VERTEX_ARRAY);
- glEnableClientState(GL_NORMAL_ARRAY);
- glEnableClientState(GL_TEXTURE_COORD_ARRAY);
- glEnableClientState(GL_COLOR_ARRAY);
- glVertexPointer(3, GL_FLOAT, 0, vertices.constData());
- glNormalPointer(GL_FLOAT, 0, normals.constData());
- glTexCoordPointer(2, GL_FLOAT, 0, texCoords.constData());
- glColorPointer(4, GL_FLOAT, 0, colors.constData());
-}
-
-void Geometry::setColors(int start, GLfloat colorArray[4][4])
-{
- int off = faces[start];
- for (int i = 0; i < 4; ++i)
- colors[i + off] = QVector4D(colorArray[i][0],
- colorArray[i][1],
- colorArray[i][2],
- colorArray[i][3]);
-}
-
-Tile::Tile(const QVector3D &loc)
- : location(loc)
- , start(0)
- , count(0)
- , useFlatColor(false)
- , geom(0)
-{
- qSetColor(faceColor, QColor(Qt::darkGray));
-}
-
-void Tile::setColors(GLfloat colorArray[4][4])
-{
- useFlatColor = true;
- geom->setColors(start, colorArray);
-}
-
-void Tile::draw() const
-{
- QMatrix4x4 mat;
- mat.translate(location);
- mat.rotate(orientation);
- glMatrixMode(GL_MODELVIEW);
- glPushMatrix();
- glMultMatrixf(mat.constData());
- glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, faceColor);
- glDrawElements(GL_TRIANGLES, count, GL_UNSIGNED_SHORT, geom->indices() + start);
- glPopMatrix();
-}
-
-TileBuilder::TileBuilder(Geometry *g, qreal depth, qreal size)
- : verts(4)
- , tex(4)
- , start(g->count())
- , count(0)
- , geom(g)
-{
- // front face - make a square with bottom-left at origin
- verts[br].setX(size);
- verts[tr].setX(size);
- verts[tr].setY(size);
- verts[tl].setY(size);
-
- // these vert numbers are good for the tex-coords
- for (int i = 0; i < 4; ++i)
- tex[i] = verts[i].toVector2D();
-
- // now move verts half cube width across so cube is centered on origin
- for (int i = 0; i < 4; ++i)
- verts[i] -= QVector3D(size / 2.0f, size / 2.0f, -depth);
-
- // add the front face
- g->addQuad(verts[bl], verts[br], verts[tr], verts[tl], tex);
-
- count = g->count() - start;
-}
-
-void TileBuilder::initialize(Tile *tile) const
-{
- tile->start = start;
- tile->count = count;
- tile->geom = geom;
- qSetColor(tile->faceColor, color);
-}
-
-Tile *TileBuilder::newTile(const QVector3D &loc) const
-{
- Tile *tile = new Tile(loc);
- initialize(tile);
- return tile;
-}
-
-Cube::Cube(const QVector3D &loc)
- : Tile(loc)
- , rot(0.0f)
- , r(0)
- , animGroup(0)
-{
-}
-
-Cube::~Cube()
-{
-}
-
-void Cube::setAltitude(qreal a)
-{
- if (location.y() != a)
- {
- location.setY(a);
- emit changed();
- }
-}
-
-void Cube::setRange(qreal r)
-{
- if (location.x() != r)
- {
- location.setX(r);
- emit changed();
- }
-}
-
-void Cube::setRotation(qreal r)
-{
- if (r != rot)
- {
- orientation = QQuaternion::fromAxisAndAngle(QVector3D(1.0f, 1.0f, 1.0f), r);
- emit changed();
- }
-}
-
-void Cube::removeBounce()
-{
- delete animGroup;
- animGroup = 0;
- delete r;
- r = 0;
-}
-
-void Cube::startAnimation()
-{
- if (r)
- {
- r->start();
- r->setCurrentTime(startx);
- }
- if (animGroup)
- animGroup->start();
- if (rtn)
- rtn->start();
-}
-
-void Cube::setAnimationPaused(bool paused)
-{
- if (paused)
- {
- if (r)
- r->pause();
- if (animGroup)
- animGroup->pause();
- if (rtn)
- rtn->pause();
- }
- else
- {
- if (r)
- r->resume();
- if (animGroup)
- animGroup->resume();
- if (rtn)
- rtn->resume();
- }
-}
-
-CubeBuilder::CubeBuilder(Geometry *g, qreal depth, qreal size)
- : TileBuilder(g, depth)
- , ix(0)
-{
- for (int i = 0; i < 4; ++i)
- verts[i].setZ(size / 2.0f);
- // back face - "extrude" verts down
- QVector<QVector3D> back(verts);
- for (int i = 0; i < 4; ++i)
- back[i].setZ(-size / 2.0f);
-
- // add the back face
- g->addQuad(back[br], back[bl], back[tl], back[tr], tex);
-
- // add the sides
- g->addQuad(back[bl], back[br], verts[br], verts[bl], tex);
- g->addQuad(back[br], back[tr], verts[tr], verts[br], tex);
- g->addQuad(back[tr], back[tl], verts[tl], verts[tr], tex);
- g->addQuad(back[tl], back[bl], verts[bl], verts[tl], tex);
-
- count = g->count() - start;
-}
-
-Cube *CubeBuilder::newCube(const QVector3D &loc) const
-{
- Cube *c = new Cube(loc);
- initialize(c);
- qreal d = 4000.0f;
- qreal d3 = d / 3.0f;
- // Animate movement from left to right
- c->r = new QPropertyAnimation(c, "range");
- c->r->setStartValue(-1.3f);
- c->r->setEndValue(1.3f);
- c->startx = ix * d3 * 3.0f;
- c->r->setDuration(d * 4.0f);
- c->r->setLoopCount(-1);
- c->r->setEasingCurve(QEasingCurve(QEasingCurve::CosineCurve));
-
- c->animGroup = new QSequentialAnimationGroup(c);
-
- // Animate movement from bottom to top
- QPropertyAnimation *a_up = new QPropertyAnimation(c, "altitude", c->animGroup);
- a_up->setEndValue(loc.y());
- a_up->setStartValue(loc.y() + amplitudes[ix]);
- a_up->setDuration(d / speeds[ix]);
- a_up->setLoopCount(1);
- a_up->setEasingCurve(QEasingCurve(QEasingCurve::InQuad));
-
- // Animate movement from top to bottom
- QPropertyAnimation *a_down = new QPropertyAnimation(c, "altitude", c->animGroup);
- a_down->setEndValue(loc.y() + amplitudes[ix]);
- a_down->setStartValue(loc.y());
- a_down->setDuration(d / speeds[ix]);
- a_down->setLoopCount(1);
- a_down->setEasingCurve(QEasingCurve(QEasingCurve::OutQuad));
-
- c->animGroup->addAnimation(a_up);
- c->animGroup->addAnimation(a_down);
- c->animGroup->setLoopCount(-1);
-
- // Animate rotation
- c->rtn = new QPropertyAnimation(c, "rotation");
- c->rtn->setStartValue(c->rot);
- c->rtn->setEndValue(359.0f);
- c->rtn->setDuration(d * 2.0f);
- c->rtn->setLoopCount(-1);
- c->rtn->setDuration(d / 2);
- ix = (ix + 1) % 3;
- return c;
-}
diff --git a/examples/opengl/legacy/pbuffers/cube.h b/examples/opengl/legacy/pbuffers/cube.h
deleted file mode 100644
index 17cac2decd..0000000000
--- a/examples/opengl/legacy/pbuffers/cube.h
+++ /dev/null
@@ -1,159 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the examples of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:BSD$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** BSD License Usage
-** Alternatively, you may use this file under the terms of the BSD license
-** as follows:
-**
-** "Redistribution and use in source and binary forms, with or without
-** modification, are permitted provided that the following conditions are
-** met:
-** * Redistributions of source code must retain the above copyright
-** notice, this list of conditions and the following disclaimer.
-** * Redistributions in binary form must reproduce the above copyright
-** notice, this list of conditions and the following disclaimer in
-** the documentation and/or other materials provided with the
-** distribution.
-** * 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.
-**
-**
-** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
-** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
-** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
-** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
-** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
-** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
-** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
-** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
-** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef CUBE_H
-#define CUBE_H
-
-#include <QtOpenGL/qgl.h>
-#include <QtCore/qvector.h>
-#include <QtCore/qsequentialanimationgroup.h>
-#include <QtGui/qmatrix4x4.h>
-#include <QtGui/qvector3d.h>
-#include <QtGui/qvector2d.h>
-
-QT_BEGIN_NAMESPACE
-class QPropertyAnimation;
-QT_END_NAMESPACE
-
-class Geometry
-{
-public:
- void loadArrays() const;
- void addQuad(const QVector3D &a, const QVector3D &b,
- const QVector3D &c, const QVector3D &d,
- const QVector<QVector2D> &tex);
- void setColors(int start, GLfloat colors[4][4]);
- const GLushort *indices() const { return faces.constData(); }
- int count() const { return faces.count(); }
-private:
- QVector<GLushort> faces;
- QVector<QVector3D> vertices;
- QVector<QVector3D> normals;
- QVector<QVector2D> texCoords;
- QVector<QVector4D> colors;
- int append(const QVector3D &a, const QVector3D &n, const QVector2D &t);
- void addTri(const QVector3D &a, const QVector3D &b, const QVector3D &c, const QVector3D &n);
- friend class Tile;
-};
-
-class Tile
-{
-public:
- void draw() const;
- void setColors(GLfloat[4][4]);
-protected:
- Tile(const QVector3D &loc = QVector3D());
- QVector3D location;
- QQuaternion orientation;
-private:
- int start;
- int count;
- bool useFlatColor;
- GLfloat faceColor[4];
- Geometry *geom;
- friend class TileBuilder;
-};
-
-class TileBuilder
-{
-public:
- enum { bl, br, tr, tl };
- explicit TileBuilder(Geometry *, qreal depth = 0.0f, qreal size = 1.0f);
- Tile *newTile(const QVector3D &loc = QVector3D()) const;
- void setColor(QColor c) { color = c; }
-protected:
- void initialize(Tile *) const;
- QVector<QVector3D> verts;
- QVector<QVector2D> tex;
- int start;
- int count;
- Geometry *geom;
- QColor color;
-};
-
-class Cube : public QObject, public Tile
-{
- Q_OBJECT
- Q_PROPERTY(qreal range READ range WRITE setRange)
- Q_PROPERTY(qreal altitude READ altitude WRITE setAltitude)
- Q_PROPERTY(qreal rotation READ rotation WRITE setRotation)
-public:
- Cube(const QVector3D &loc = QVector3D());
- ~Cube();
- qreal range() { return location.x(); }
- void setRange(qreal r);
- qreal altitude() { return location.y(); }
- void setAltitude(qreal a);
- qreal rotation() { return rot; }
- void setRotation(qreal r);
- void removeBounce();
- void startAnimation();
- void setAnimationPaused(bool paused);
-signals:
- void changed();
-private:
- qreal rot;
- QPropertyAnimation *r;
- QPropertyAnimation *rtn;
- QSequentialAnimationGroup *animGroup;
- qreal startx;
- friend class CubeBuilder;
-};
-
-class CubeBuilder : public TileBuilder
-{
-public:
- explicit CubeBuilder(Geometry *, qreal depth = 0.0f, qreal size = 1.0f);
- Cube *newCube(const QVector3D &loc = QVector3D()) const;
-private:
- mutable int ix;
-};
-
-#endif // CUBE_H
diff --git a/examples/opengl/legacy/pbuffers/cubelogo.png b/examples/opengl/legacy/pbuffers/cubelogo.png
deleted file mode 100644
index 2ccbede774..0000000000
--- a/examples/opengl/legacy/pbuffers/cubelogo.png
+++ /dev/null
Binary files differ
diff --git a/examples/opengl/legacy/pbuffers/glwidget.cpp b/examples/opengl/legacy/pbuffers/glwidget.cpp
deleted file mode 100644
index 5763436d5e..0000000000
--- a/examples/opengl/legacy/pbuffers/glwidget.cpp
+++ /dev/null
@@ -1,256 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the examples of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:BSD$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** BSD License Usage
-** Alternatively, you may use this file under the terms of the BSD license
-** as follows:
-**
-** "Redistribution and use in source and binary forms, with or without
-** modification, are permitted provided that the following conditions are
-** met:
-** * Redistributions of source code must retain the above copyright
-** notice, this list of conditions and the following disclaimer.
-** * Redistributions in binary form must reproduce the above copyright
-** notice, this list of conditions and the following disclaimer in
-** the documentation and/or other materials provided with the
-** distribution.
-** * 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.
-**
-**
-** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
-** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
-** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
-** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
-** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
-** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
-** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
-** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
-** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include "glwidget.h"
-#include <math.h>
-
-#include "cube.h"
-
-#include <QGLPixelBuffer>
-
-#ifndef GL_MULTISAMPLE
-#define GL_MULTISAMPLE 0x809D
-#endif
-
-static GLfloat colorArray[][4] = {
- {0.243f, 0.423f, 0.125f, 1.0f},
- {0.176f, 0.31f, 0.09f, 1.0f},
- {0.4f, 0.69f, 0.212f, 1.0f},
- {0.317f, 0.553f, 0.161f, 1.0f}
-};
-
-GLWidget::GLWidget(QWidget *parent)
- : QGLWidget(QGLFormat(QGL::SampleBuffers), parent)
- , geom(0)
- , cube(0)
-{
- // create the pbuffer
- QGLFormat pbufferFormat = format();
- pbufferFormat.setSampleBuffers(false);
- pbuffer = new QGLPixelBuffer(QSize(512, 512), pbufferFormat, this);
- setWindowTitle(tr("OpenGL pbuffers"));
- initializeGeometry();
-}
-
-GLWidget::~GLWidget()
-{
- pbuffer->releaseFromDynamicTexture();
- glDeleteTextures(1, &dynamicTexture);
- delete pbuffer;
-
- qDeleteAll(cubes);
- qDeleteAll(tiles);
- delete cube;
-}
-
-void GLWidget::initializeGL()
-{
- initCommon();
- glShadeModel(GL_SMOOTH);
- glEnable(GL_LIGHTING);
- glEnable(GL_LIGHT0);
- static GLfloat lightPosition[4] = { 0.5, 5.0, 7.0, 1.0 };
- glLightfv(GL_LIGHT0, GL_POSITION, lightPosition);
- initPbuffer();
- cube->startAnimation();
- connect(cube, SIGNAL(changed()), this, SLOT(update()));
- for (int i = 0; i < 3; ++i)
- {
- cubes[i]->startAnimation();
- connect(cubes[i], SIGNAL(changed()), this, SLOT(update()));
- }
-}
-
-void GLWidget::paintGL()
-{
- pbuffer->makeCurrent();
- drawPbuffer();
- // On direct render platforms, drawing onto the pbuffer context above
- // automatically updates the dynamic texture. For cases where rendering
- // directly to a texture is not supported, explicitly copy.
- if (!hasDynamicTextureUpdate)
- pbuffer->updateDynamicTexture(dynamicTexture);
- makeCurrent();
-
- // Use the pbuffer as a texture to render the scene
- glBindTexture(GL_TEXTURE_2D, dynamicTexture);
-
- // set up to render the scene
- glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
- glLoadIdentity();
- glTranslatef(0.0f, 0.0f, -10.0f);
-
- // draw the background
- glPushMatrix();
- glScalef(aspect, 1.0f, 1.0f);
- for (int i = 0; i < tiles.count(); ++i)
- tiles[i]->draw();
- glPopMatrix();
-
- // draw the bouncing cubes
- for (int i = 0; i < cubes.count(); ++i)
- cubes[i]->draw();
-}
-
-void GLWidget::initializeGeometry()
-{
- geom = new Geometry();
- CubeBuilder cBuilder(geom, 0.5);
- cBuilder.setColor(QColor(255, 255, 255, 212));
- // build the 3 bouncing, spinning cubes
- for (int i = 3; i > 0; --i)
- cubes.append(cBuilder.newCube(QVector3D((float)(i-1), -1.5f, 5 - i)));
-
- // build the spinning cube which goes in the dynamic texture
- cube = cBuilder.newCube();
- cube->removeBounce();
-
- // build the background tiles
- TileBuilder tBuilder(geom);
- tBuilder.setColor(QColor(Qt::white));
- for (int c = -2; c <= +2; ++c)
- for (int r = -2; r <= +2; ++r)
- tiles.append(tBuilder.newTile(QVector3D(c, r, 0)));
-
- // graded backdrop for the pbuffer scene
- TileBuilder bBuilder(geom, 0.0f, 2.0f);
- bBuilder.setColor(QColor(102, 176, 54, 210));
- backdrop = bBuilder.newTile(QVector3D(0.0f, 0.0f, -1.5f));
- backdrop->setColors(colorArray);
-}
-
-void GLWidget::initCommon()
-{
- qglClearColor(QColor(Qt::darkGray));
-
- glEnable(GL_DEPTH_TEST);
- glEnable(GL_CULL_FACE);
- glEnable(GL_MULTISAMPLE);
-
- glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
- glEnable(GL_BLEND);
-
- glEnable(GL_TEXTURE_2D);
-
- geom->loadArrays();
-}
-
-void GLWidget::perspectiveProjection()
-{
- glMatrixMode(GL_PROJECTION);
- glLoadIdentity();
-#ifdef QT_OPENGL_ES
- glFrustumf(-aspect, +aspect, -1.0, +1.0, 4.0, 15.0);
-#else
- glFrustum(-aspect, +aspect, -1.0, +1.0, 4.0, 15.0);
-#endif
- glMatrixMode(GL_MODELVIEW);
-}
-
-void GLWidget::orthographicProjection()
-{
- glMatrixMode(GL_PROJECTION);
- glLoadIdentity();
-#ifdef QT_OPENGL_ES
- glOrthof(-1.0, +1.0, -1.0, +1.0, -90.0, +90.0);
-#else
- glOrtho(-1.0, +1.0, -1.0, +1.0, -90.0, +90.0);
-#endif
- glMatrixMode(GL_MODELVIEW);
-}
-
-void GLWidget::resizeGL(int width, int height)
-{
- glViewport(0, 0, width * devicePixelRatio(), height * devicePixelRatio());
- aspect = (qreal)width / (qreal)(height ? height : 1);
- perspectiveProjection();
-}
-
-void GLWidget::drawPbuffer()
-{
- orthographicProjection();
-
- glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
- glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
-
- glDisable(GL_TEXTURE_2D);
- backdrop->draw();
- glEnable(GL_TEXTURE_2D);
-
- glBindTexture(GL_TEXTURE_2D, cubeTexture);
- glDisable(GL_CULL_FACE);
- cube->draw();
- glEnable(GL_CULL_FACE);
-
- glFlush();
-}
-
-void GLWidget::initPbuffer()
-{
- pbuffer->makeCurrent();
-
- cubeTexture = bindTexture(QImage(":res/cubelogo.png"));
-
- initCommon();
-
- // generate a texture that has the same size/format as the pbuffer
- dynamicTexture = pbuffer->generateDynamicTexture();
-
- // bind the dynamic texture to the pbuffer - this is a no-op under X11
- hasDynamicTextureUpdate = pbuffer->bindToDynamicTexture(dynamicTexture);
- makeCurrent();
-}
-
-void GLWidget::setAnimationPaused(bool enable)
-{
- cube->setAnimationPaused(enable);
- for (int i = 0; i < 3; ++i)
- cubes[i]->setAnimationPaused(enable);
-}
diff --git a/examples/opengl/legacy/pbuffers/glwidget.h b/examples/opengl/legacy/pbuffers/glwidget.h
deleted file mode 100644
index 397329c428..0000000000
--- a/examples/opengl/legacy/pbuffers/glwidget.h
+++ /dev/null
@@ -1,99 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the examples of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:BSD$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** BSD License Usage
-** Alternatively, you may use this file under the terms of the BSD license
-** as follows:
-**
-** "Redistribution and use in source and binary forms, with or without
-** modification, are permitted provided that the following conditions are
-** met:
-** * Redistributions of source code must retain the above copyright
-** notice, this list of conditions and the following disclaimer.
-** * Redistributions in binary form must reproduce the above copyright
-** notice, this list of conditions and the following disclaimer in
-** the documentation and/or other materials provided with the
-** distribution.
-** * 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.
-**
-**
-** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
-** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
-** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
-** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
-** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
-** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
-** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
-** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
-** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef GLWIDGET_H
-#define GLWIDGET_H
-
-#include <QGLWidget>
-
-class Geometry;
-class Cube;
-class Tile;
-QT_BEGIN_NAMESPACE
-class QGLPixelBuffer;
-QT_END_NAMESPACE
-
-class GLWidget : public QGLWidget
-{
-public:
- GLWidget(QWidget *parent = 0);
- ~GLWidget();
-
-protected:
- void initializeGL() override;
- void paintGL() override;
- void resizeGL(int width, int height) override;
- void mousePressEvent(QMouseEvent *) override { setAnimationPaused(true); }
- void mouseReleaseEvent(QMouseEvent *) override { setAnimationPaused(false); }
-
-private:
- void initializeGeometry();
- void initPbuffer();
- void initCommon();
- void perspectiveProjection();
- void orthographicProjection();
- void drawPbuffer();
- void setAnimationPaused(bool enable);
-
- qreal aspect;
- GLuint dynamicTexture;
- GLuint cubeTexture;
- bool hasDynamicTextureUpdate;
- QGLPixelBuffer *pbuffer;
- Geometry *geom;
- Cube *cube;
- Tile *backdrop;
- QList<Cube *> cubes;
- QList<Tile *> tiles;
-
-};
-//! [3]
-
-#endif
diff --git a/examples/opengl/legacy/pbuffers/main.cpp b/examples/opengl/legacy/pbuffers/main.cpp
deleted file mode 100644
index 157f450b75..0000000000
--- a/examples/opengl/legacy/pbuffers/main.cpp
+++ /dev/null
@@ -1,75 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the examples of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:BSD$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** BSD License Usage
-** Alternatively, you may use this file under the terms of the BSD license
-** as follows:
-**
-** "Redistribution and use in source and binary forms, with or without
-** modification, are permitted provided that the following conditions are
-** met:
-** * Redistributions of source code must retain the above copyright
-** notice, this list of conditions and the following disclaimer.
-** * Redistributions in binary form must reproduce the above copyright
-** notice, this list of conditions and the following disclaimer in
-** the documentation and/or other materials provided with the
-** distribution.
-** * 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.
-**
-**
-** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
-** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
-** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
-** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
-** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
-** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
-** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
-** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
-** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include <QtWidgets/QApplication>
-#include <QtWidgets/QMessageBox>
-#include <QtOpenGL/QGLPixelBuffer>
-
-#include "glwidget.h"
-
-int main(int argc, char **argv)
-{
- Q_INIT_RESOURCE(pbuffers);
-
- QApplication a(argc, argv);
- GLWidget widget(0);
- widget.resize(640, 480);
- widget.makeCurrent();
-
- if (!QGLFormat::hasOpenGL() || !QGLPixelBuffer::hasOpenGLPbuffers()) {
- QMessageBox::information(0, "OpenGL pbuffers",
- "This system does not support OpenGL/pbuffers.");
- return -1;
- }
-
- widget.show();
- return a.exec();
-}
-
diff --git a/examples/opengl/legacy/pbuffers/pbuffers.pro b/examples/opengl/legacy/pbuffers/pbuffers.pro
deleted file mode 100644
index 7572ba3583..0000000000
--- a/examples/opengl/legacy/pbuffers/pbuffers.pro
+++ /dev/null
@@ -1,13 +0,0 @@
-HEADERS += glwidget.h \
- cube.h
-SOURCES += glwidget.cpp \
- main.cpp \
- cube.cpp
-RESOURCES += pbuffers.qrc
-QT += opengl widgets
-
-# install
-target.path = $$[QT_INSTALL_EXAMPLES]/opengl/legacy/pbuffers
-INSTALLS += target
-
-qtConfig(opengles.|angle|dynamicgl): error("This example requires Qt to be configured with -opengl desktop")
diff --git a/examples/opengl/legacy/pbuffers/pbuffers.qrc b/examples/opengl/legacy/pbuffers/pbuffers.qrc
deleted file mode 100644
index 9fc1a56a1a..0000000000
--- a/examples/opengl/legacy/pbuffers/pbuffers.qrc
+++ /dev/null
@@ -1,5 +0,0 @@
-<!DOCTYPE RCC><RCC version="1.0">
-<qresource prefix="/res">
- <file>cubelogo.png</file>
-</qresource>
-</RCC>
diff --git a/examples/opengl/legacy/pbuffers2/bubbles.svg b/examples/opengl/legacy/pbuffers2/bubbles.svg
deleted file mode 100644
index 51730124a2..0000000000
--- a/examples/opengl/legacy/pbuffers2/bubbles.svg
+++ /dev/null
@@ -1,215 +0,0 @@
-<?xml version="1.0" standalone="no"?>
-<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.0//EN" "http://www.w3.org/TR/2001/REC-SVG-20010904/DTD/svg10.dtd">
-<svg width="20cm" height="15cm" viewBox="0 0 800 600"
- xmlns="http://www.w3.org/2000/svg"
- xmlns:xlink="http://www.w3.org/1999/xlink/"
- baseProfile="tiny" version="1.2">
- <title>Spheres</title>
- <desc>Semi-transparent bubbles on a colored background.</desc>
- <defs>
- <!-- Create radial gradients for each bubble. -->
- <radialGradient id="blueBubble" gradientUnits="userSpaceOnUse"
- cx="0" cy="0" r="100" fx="-50" fy="-50">
- <stop offset="0%" stop-color="white" stop-opacity="1" />
- <stop offset="25%" stop-color="#cdcdff" stop-opacity=".65" />
- <stop offset="100%" stop-color="#cdaacd" stop-opacity=".75" />
- </radialGradient>
- <radialGradient id="redBubble" gradientUnits="userSpaceOnUse"
- cx="0" cy="0" r="100" fx="-50" fy="-50">
- <stop offset="0%" stop-color="white" stop-opacity="1" />
- <stop offset="25%" stop-color="#ffcdcd" stop-opacity=".65" />
- <stop offset="100%" stop-color="#bbbb99" stop-opacity=".75" />
- </radialGradient>
- <radialGradient id="greenBubble" gradientUnits="userSpaceOnUse"
- cx="0" cy="0" r="100" fx="-50" fy="-50">
- <stop offset="0%" stop-color="white" stop-opacity="1" />
- <stop offset="25%" stop-color="#cdffcd" stop-opacity=".65" />
- <stop offset="100%" stop-color="#99aaaa" stop-opacity=".75" />
- </radialGradient>
- <radialGradient id="yellowBubble" gradientUnits="userSpaceOnUse"
- cx="0" cy="0" r="100" fx="-50" fy="-50">
- <stop offset="0%" stop-color="white" stop-opacity="1" />
- <stop offset="25%" stop-color="#ffffcd" stop-opacity=".65" />
- <stop offset="100%" stop-color="#bbbbaa" stop-opacity=".75" />
- </radialGradient>
- <radialGradient id="background" gradientUnits="userSpaceOnUse"
- cx="0" cy="0" r="400" fx="250" fy="250">
- <stop offset="0%" stop-color="#ffffee" />
- <stop offset="100%" stop-color="#ccccaa" />
- </radialGradient>
- <linearGradient id="surface" gradientUnits="userSpaceOnUse"
- x1="-100" y1="200" x2="400" y2="200">
- <stop offset="0%" stop-color="#ffffcc" />
- <stop offset="100%" stop-color="#bbbb88" />
- </linearGradient>
-
- <!-- Create radial gradients for each circle to make them look like
- spheres. -->
- <radialGradient id="blueSphere" gradientUnits="userSpaceOnUse"
- cx="0" cy="0" r="100" fx="-50" fy="-50">
- <stop offset="0%" stop-color="white" />
- <stop offset="75%" stop-color="blue" />
- <stop offset="100%" stop-color="#222244" />
- </radialGradient>
- <radialGradient id="redSphere" gradientUnits="userSpaceOnUse"
- cx="0" cy="0" r="100" fx="-50" fy="-50">
- <stop offset="0%" stop-color="white" />
- <stop offset="75%" stop-color="red" />
- <stop offset="100%" stop-color="#442222" />
- </radialGradient>
- <radialGradient id="greenSphere" gradientUnits="userSpaceOnUse"
- cx="0" cy="0" r="100" fx="-50" fy="-50">
- <stop offset="0%" stop-color="white" />
- <stop offset="75%" stop-color="green" />
- <stop offset="100%" stop-color="#113311" />
- </radialGradient>
- <radialGradient id="yellowSphere" gradientUnits="userSpaceOnUse"
- cx="0" cy="0" r="100" fx="-50" fy="-50">
- <stop offset="0%" stop-color="white" />
- <stop offset="75%" stop-color="yellow" />
- <stop offset="100%" stop-color="#444422" />
- </radialGradient>
- <radialGradient id="shadowGrad" gradientUnits="userSpaceOnUse"
- cx="0" cy="0" r="100" fx="-50" fy="50">
- <stop offset="0%" stop-color="black" stop-opacity="1.0" />
- <stop offset="100%" stop-color="black" stop-opacity="0.0" />
- </radialGradient>
-
- <!-- Define a shadow for each sphere. -->
- <circle id="shadow" fill="url(#shadowGrad)" cx="0" cy="0" r="100" />
- <g id="bubble">
- <circle fill="black" cx="0" cy="0" r="50" />
- <circle fill="#a6ce39" cx="0" cy="0" r="33" />
- <path fill="black" d="M 37,50 L 50,37 L 12,-1 L 22,-11 L 10,-24 L -24,10
- L -11,22 L -1,12 Z" />
- <circle cx="0" cy="0" r="100" />
- </g>
- </defs>
- <g>
- <rect fill="url(#background)" x="0" y="0" width="800" height="600" />
- </g>
-
- <g transform="translate(200,700)">
- <use xlink:href="#bubble" fill="url(#blueBubble)" />
- <animateTransform attributeName="transform" type="translate" additive="sum"
- values="0,0; 0,-800" begin="1s" dur="10s" fill="freeze" repeatCount="indefinite" />
- </g>
- <g transform="translate(315,700)">
- <g transform="scale(0.5,0.5)">
- <use xlink:href="#bubble" fill="url(#redBubble)" />
- </g>
- <animateTransform attributeName="transform" type="translate" additive="sum"
- values="0,0; 0,-800" begin="3s" dur="7s" fill="freeze" repeatCount="indefinite" />
- </g>
- <g transform="translate(80,700)">
- <g transform="scale(0.65,0.65)">
- <use xlink:href="#bubble" fill="url(#greenBubble)" />
- </g>
- <animateTransform attributeName="transform" type="translate" additive="sum"
- values="0,0; 0,-800" begin="5s" dur="9s" fill="freeze" repeatCount="indefinite" />
- </g>
- <g transform="translate(255,700)">
- <g transform="scale(0.3,0.3)">
- <use xlink:href="#bubble" fill="url(#yellowBubble)" />
- </g>
- <animateTransform attributeName="transform" type="translate" additive="sum"
- values="0,0; 0,-800" begin="2s" dur="6s" fill="freeze" repeatCount="indefinite" />
- </g>
- <g transform="translate(565,700)">
- <g transform="scale(0.4,0.4)">
- <use xlink:href="#bubble" fill="url(#blueBubble)" />
- </g>
- <animateTransform attributeName="transform" type="translate" additive="sum"
- values="0,0; 0,-800" begin="4s" dur="8s" fill="freeze" repeatCount="indefinite" />
- </g>
- <g transform="translate(715,700)">
- <g transform="scale(0.6,0.6)">
- <use xlink:href="#bubble" fill="url(#redBubble)" />
- </g>
- <animateTransform attributeName="transform" type="translate" additive="sum"
- values="0,0; 0,-800" begin="1s" dur="4s" fill="freeze" repeatCount="indefinite" />
- </g>
- <g transform="translate(645,700)">
- <g transform="scale(0.375,0.375)">
- <use xlink:href="#bubble" fill="url(#greenBubble)" />
- </g>
- <animateTransform attributeName="transform" type="translate" additive="sum"
- values="0,0; 0,-800" begin="0s" dur="11s" fill="freeze" repeatCount="indefinite" />
- </g>
- <g transform="translate(555,700)">
- <g transform="scale(0.9,0.9)">
- <use xlink:href="#bubble" fill="url(#yellowBubble)" />
- </g>
- <animateTransform attributeName="transform" type="translate" additive="sum"
- values="0,0; 0,-800" begin="3s" dur="7.5s" fill="freeze" repeatCount="indefinite" />
- </g>
-
- <g transform="translate(360,700)">
- <g transform="scale(0.5,0.5)">
- <use xlink:href="#bubble" fill="url(#blueBubble)" />
- </g>
- <animateTransform attributeName="transform" type="translate" additive="sum"
- values="0,0; 0,-800" begin="3s" dur="6s" fill="freeze" repeatCount="indefinite" />
- </g>
- <g transform="translate(215,700)">
- <g transform="scale(0.45,0.45)">
- <use xlink:href="#bubble" fill="url(#redBubble)" />
- </g>
- <animateTransform attributeName="transform" type="translate" additive="sum"
- values="0,0; 0,-800" begin="5.5s" dur="7s" fill="freeze" repeatCount="indefinite" />
- </g>
- <g transform="translate(420,700)">
- <g transform="scale(0.75,0.75)">
- <use xlink:href="#bubble" fill="url(#greenBubble)" />
- </g>
- <animateTransform attributeName="transform" type="translate" additive="sum"
- values="0,0; 0,-800" begin="1s" dur="9s" fill="freeze" repeatCount="indefinite" />
- </g>
- <g transform="translate(815,700)">
- <g transform="scale(0.6,0.6)">
- <use xlink:href="#bubble" fill="url(#yellowBubble)" />
- </g>
- <animateTransform attributeName="transform" type="translate" additive="sum"
- values="0,0; 0,-800" begin="2s" dur="9.5s" fill="freeze" repeatCount="indefinite" />
- </g>
-
- <g transform="translate(225,375)" >
- <g transform="scale(1.0,0.5)" >
- <path d="M 0 0 L 350 0 L 450 450 L -100 450 z"
- fill="url(#surface)" stroke="none" />
- </g>
- </g>
- <g transform="translate(200,0)" >
- <g transform="translate(200,490) scale(2.0,1.0) rotate(45)" >
- <rect fill="#a6ce39" x="-69" y="-69" width="138" height="138" />
- <circle fill="black" cx="0" cy="0" r="50" />
- <circle fill="#a6ce39" cx="0" cy="0" r="33" />
- <path fill="black" d="M 37,50 L 50,37 L 12,-1 L 22,-11 L 10,-24 L -24,10
- L -11,22 L -1,12 Z" />
- <animateTransform attributeName="transform" type="rotate" additive="sum" values="0; 360"
- begin="0s" dur="10s" fill="freeze" repeatCount="indefinite" />
- </g>
- <g transform="translate(200,375)">
- <use xlink:href="#shadow" transform="translate(25,55) scale(1.0,0.5)" />
- <circle fill="url(#blueSphere)" cx="0" cy="0" r="100" />
- </g>
- <g transform="translate(315,440)">
- <g transform="scale(0.5,0.5)">
- <use xlink:href="#shadow" transform="translate(25,55) scale(1.0,0.5)" />
- <circle fill="url(#redSphere)" cx="0" cy="0" r="100" />
- </g>
- </g>
- <g transform="translate(80,475)">
- <g transform="scale(0.65,0.65)">
- <use xlink:href="#shadow" transform="translate(25,55) scale(1.0,0.5)" />
- <circle fill="url(#greenSphere)" cx="0" cy="0" r="100" />
- </g>
- </g>
- <g transform="translate(255,525)">
- <g transform="scale(0.3,0.3)">
- <use xlink:href="#shadow" transform="translate(25,55) scale(1.0,0.5)" />
- <circle fill="url(#yellowSphere)" cx="0" cy="0" r="100" />
- </g>
- </g>
- </g>
-</svg>
diff --git a/examples/opengl/legacy/pbuffers2/designer.png b/examples/opengl/legacy/pbuffers2/designer.png
deleted file mode 100644
index 4f32d57496..0000000000
--- a/examples/opengl/legacy/pbuffers2/designer.png
+++ /dev/null
Binary files differ
diff --git a/examples/opengl/legacy/pbuffers2/glwidget.cpp b/examples/opengl/legacy/pbuffers2/glwidget.cpp
deleted file mode 100644
index c710d03cab..0000000000
--- a/examples/opengl/legacy/pbuffers2/glwidget.cpp
+++ /dev/null
@@ -1,328 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the examples of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:BSD$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** BSD License Usage
-** Alternatively, you may use this file under the terms of the BSD license
-** as follows:
-**
-** "Redistribution and use in source and binary forms, with or without
-** modification, are permitted provided that the following conditions are
-** met:
-** * Redistributions of source code must retain the above copyright
-** notice, this list of conditions and the following disclaimer.
-** * Redistributions in binary form must reproduce the above copyright
-** notice, this list of conditions and the following disclaimer in
-** the documentation and/or other materials provided with the
-** distribution.
-** * 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.
-**
-**
-** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
-** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
-** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
-** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
-** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
-** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
-** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
-** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
-** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include <QtGui/QImage>
-#include <qmath.h>
-#include "glwidget.h"
-
-#ifndef GL_MULTISAMPLE
-#define GL_MULTISAMPLE 0x809D
-#endif
-
-GLWidget::GLWidget(QWidget *parent)
- : QGLWidget(QGLFormat(QGL::SampleBuffers), parent)
-{
- setWindowTitle(tr("OpenGL pbuffers 2"));
-
- pbuffer = new QGLPixelBuffer(1024, 1024, format(), this);
-
- rot_x = rot_y = rot_z = 0.0f;
- scale = 0.1f;
- anim = new QTimeLine(750, this);
- anim->setUpdateInterval(20);
- connect(anim, SIGNAL(valueChanged(qreal)), SLOT(animate(qreal)));
- connect(anim, SIGNAL(finished()), SLOT(animFinished()));
-
- svg_renderer = new QSvgRenderer(QLatin1String(":/res/bubbles.svg"), this);
- connect(svg_renderer, SIGNAL(repaintNeeded()), this, SLOT(draw()));
-
- logo = QImage(":/res/designer.png");
- logo = logo.convertToFormat(QImage::Format_ARGB32);
-
- makeCurrent(); // need a current context to create the display list
- tile_list = glGenLists(1);
- glNewList(tile_list, GL_COMPILE);
- glBegin(GL_QUADS);
- {
- glTexCoord2f(0.0f, 0.0f); glVertex3f(-1.0f, -1.0f, 1.0f);
- glTexCoord2f(1.0f, 0.0f); glVertex3f( 1.0f, -1.0f, 1.0f);
- glTexCoord2f(1.0f, 1.0f); glVertex3f( 1.0f, 1.0f, 1.0f);
- glTexCoord2f(0.0f, 1.0f); glVertex3f(-1.0f, 1.0f, 1.0f);
-
- glTexCoord2f(1.0f, 0.0f); glVertex3f(-1.0f, -1.0f, -1.0f);
- glTexCoord2f(1.0f, 1.0f); glVertex3f(-1.0f, 1.0f, -1.0f);
- glTexCoord2f(0.0f, 1.0f); glVertex3f( 1.0f, 1.0f, -1.0f);
- glTexCoord2f(0.0f, 0.0f); glVertex3f( 1.0f, -1.0f, -1.0f);
-
- glTexCoord2f(0.0f, 1.0f); glVertex3f(-1.0f, 1.0f, -1.0f);
- glTexCoord2f(0.0f, 0.0f); glVertex3f(-1.0f, 1.0f, 1.0f);
- glTexCoord2f(1.0f, 0.0f); glVertex3f( 1.0f, 1.0f, 1.0f);
- glTexCoord2f(1.0f, 1.0f); glVertex3f( 1.0f, 1.0f, -1.0f);
-
- glTexCoord2f(1.0f, 1.0f); glVertex3f(-1.0f, -1.0f, -1.0f);
- glTexCoord2f(0.0f, 1.0f); glVertex3f( 1.0f, -1.0f, -1.0f);
- glTexCoord2f(0.0f, 0.0f); glVertex3f( 1.0f, -1.0f, 1.0f);
- glTexCoord2f(1.0f, 0.0f); glVertex3f(-1.0f, -1.0f, 1.0f);
-
- glTexCoord2f(1.0f, 0.0f); glVertex3f( 1.0f, -1.0f, -1.0f);
- glTexCoord2f(1.0f, 1.0f); glVertex3f( 1.0f, 1.0f, -1.0f);
- glTexCoord2f(0.0f, 1.0f); glVertex3f( 1.0f, 1.0f, 1.0f);
- glTexCoord2f(0.0f, 0.0f); glVertex3f( 1.0f, -1.0f, 1.0f);
-
- glTexCoord2f(0.0f, 0.0f); glVertex3f(-1.0f, -1.0f, -1.0f);
- glTexCoord2f(1.0f, 0.0f); glVertex3f(-1.0f, -1.0f, 1.0f);
- glTexCoord2f(1.0f, 1.0f); glVertex3f(-1.0f, 1.0f, 1.0f);
- glTexCoord2f(0.0f, 1.0f); glVertex3f(-1.0f, 1.0f, -1.0f);
-}
- glEnd();
- glEndList();
-
- wave = new GLfloat[logo.width()*logo.height()];
- memset(wave, 0, logo.width()*logo.height());
- startTimer(30); // wave timer
-
- pbuffer->makeCurrent();
- dynamicTexture = pbuffer->generateDynamicTexture();
-
- // bind the dynamic texture to the pbuffer - this is a no-op under X11
- hasDynamicTextureUpdate = pbuffer->bindToDynamicTexture(dynamicTexture);
-}
-
-GLWidget::~GLWidget()
-{
- delete[] wave;
- glDeleteLists(tile_list, 1);
- pbuffer->releaseFromDynamicTexture();
- glDeleteTextures(1, &dynamicTexture);
- delete pbuffer;
-}
-
-void GLWidget::paintEvent(QPaintEvent *)
-{
- draw();
-}
-
-void GLWidget::draw()
-{
- QPainter p(this); // used for text overlay
-
- // save the GL state set for QPainter
- p.beginNativePainting();
- saveGLState();
-
- // render the 'bubbles.svg' file into our pbuffer
- QPainter pbuffer_painter(pbuffer);
- svg_renderer->render(&pbuffer_painter);
- pbuffer_painter.end();
- glFlush();
-
- if (!hasDynamicTextureUpdate)
- pbuffer->updateDynamicTexture(dynamicTexture);
-
- makeCurrent();
- // draw into the GL widget
- glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
- glMatrixMode(GL_PROJECTION);
- glLoadIdentity();
- glFrustum(-1, 1, -1, 1, 10, 100);
- glTranslatef(0.0f, 0.0f, -15.0f);
- glMatrixMode(GL_MODELVIEW);
- glLoadIdentity();
- glViewport(0, 0, width() * devicePixelRatio(), height() * devicePixelRatio());
-
- glBindTexture(GL_TEXTURE_2D, dynamicTexture);
- glEnable(GL_TEXTURE_2D);
- glEnable(GL_MULTISAMPLE);
- glEnable(GL_CULL_FACE);
- glEnable(GL_BLEND);
- glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
-
- // draw background
- glPushMatrix();
- glScalef(1.7f, 1.7f, 1.7f);
- glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
- glCallList(tile_list);
- glPopMatrix();
-
- const int w = logo.width();
- const int h = logo.height();
-
- glRotatef(rot_x, 1.0f, 0.0f, 0.0f);
- glRotatef(rot_y, 0.0f, 1.0f, 0.0f);
- glRotatef(rot_z, 0.0f, 0.0f, 1.0f);
- glScalef(scale/w, scale/w, scale/w);
-
- glDepthFunc(GL_LESS);
- glEnable(GL_DEPTH_TEST);
-
- // draw the Qt icon
- glTranslatef(-w+1, -h+1, 0.0f);
- for (int y=h-1; y>=0; --y) {
- uint *p = (uint*) logo.scanLine(y);
- uint *end = p + w;
- int x = 0;
- while (p < end) {
- glColor4ub(qRed(*p), qGreen(*p), qBlue(*p), uchar(qAlpha(*p)*.9));
- glTranslatef(0.0f, 0.0f, wave[y*w+x]);
- if (qAlpha(*p) > 128)
- glCallList(tile_list);
- glTranslatef(0.0f, 0.0f, -wave[y*w+x]);
- glTranslatef(2.0f, 0.0f, 0.0f);
- ++x;
- ++p;
- }
- glTranslatef(-w*2.0f, 2.0f, 0.0f);
- }
-
- // restore the GL state that QPainter expects
- restoreGLState();
- p.endNativePainting();
-
- // draw the overlayed text using QPainter
- p.setPen(QColor(197, 197, 197, 157));
- p.setBrush(QColor(197, 197, 197, 127));
- p.drawRect(QRect(0, 0, width(), 50));
- p.setPen(Qt::black);
- p.setBrush(Qt::NoBrush);
- const QString str1(tr("A simple OpenGL pbuffer example."));
- const QString str2(tr("Use the mouse wheel to zoom, press buttons and move mouse to rotate, double-click to flip."));
- QFontMetrics fm(p.font());
- p.drawText(width()/2 - fm.width(str1)/2, 20, str1);
- p.drawText(width()/2 - fm.width(str2)/2, 20 + fm.lineSpacing(), str2);
-}
-
-void GLWidget::mousePressEvent(QMouseEvent *e)
-{
- anchor = e->pos();
-}
-
-void GLWidget::mouseMoveEvent(QMouseEvent *e)
-{
- QPoint diff = e->pos() - anchor;
- if (e->buttons() & Qt::LeftButton) {
- rot_x += diff.y()/5.0f;
- rot_y += diff.x()/5.0f;
- } else if (e->buttons() & Qt::RightButton) {
- rot_z += diff.x()/5.0f;
- }
-
- anchor = e->pos();
- draw();
-}
-
-void GLWidget::wheelEvent(QWheelEvent *e)
-{
- e->delta() > 0 ? scale += scale*0.1f : scale -= scale*0.1f;
- draw();
-}
-
-void GLWidget::mouseDoubleClickEvent(QMouseEvent *)
-{
- anim->start();
-}
-
-void GLWidget::animate(qreal val)
-{
- rot_y = val * 180;
- draw();
-}
-
-void GLWidget::animFinished()
-{
- if (anim->direction() == QTimeLine::Forward)
- anim->setDirection(QTimeLine::Backward);
- else
- anim->setDirection(QTimeLine::Forward);
-}
-
-void GLWidget::saveGLState()
-{
- glPushAttrib(GL_ALL_ATTRIB_BITS);
- glMatrixMode(GL_PROJECTION);
- glPushMatrix();
- glMatrixMode(GL_MODELVIEW);
- glPushMatrix();
-}
-
-void GLWidget::restoreGLState()
-{
- glMatrixMode(GL_PROJECTION);
- glPopMatrix();
- glMatrixMode(GL_MODELVIEW);
- glPopMatrix();
- glPopAttrib();
-}
-
-void GLWidget::timerEvent(QTimerEvent *)
-{
- if (QApplication::mouseButtons() != 0)
- return;
-
- static bool scale_in = true;
-
- if (scale_in && scale > 35.0f)
- scale_in = false;
- else if (!scale_in && scale < .5f)
- scale_in = true;
-
- scale *= scale_in ? 1.01f : 0.99f;
- rot_z += 0.3f;
- rot_x += 0.1f;
-
- static float wt = 0.0;
- wt += 0.1f;
-
- const int width = logo.width();
- const int dx = width >> 1, dy = dx; // disturbance point
- const float v = -4; // wave speed
- const float W = .3f;
- const int AMP = 5;
-
- for (int i = 0; i < width; ++i) {
- for (int j = 0; j < width; ++j) {
- const float s = hypot(j - dx, i - dy);
- const double raw = AMP * sin(2 * M_PI * W * (wt + s / v));
- if (s != 0)
- wave[i * width + j] = raw / (0.2 * (s + 2));
- else
- wave[i * width + j] = raw;
- }
- }
-}
diff --git a/examples/opengl/legacy/pbuffers2/glwidget.h b/examples/opengl/legacy/pbuffers2/glwidget.h
deleted file mode 100644
index 2889754ce4..0000000000
--- a/examples/opengl/legacy/pbuffers2/glwidget.h
+++ /dev/null
@@ -1,94 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the examples of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:BSD$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** BSD License Usage
-** Alternatively, you may use this file under the terms of the BSD license
-** as follows:
-**
-** "Redistribution and use in source and binary forms, with or without
-** modification, are permitted provided that the following conditions are
-** met:
-** * Redistributions of source code must retain the above copyright
-** notice, this list of conditions and the following disclaimer.
-** * Redistributions in binary form must reproduce the above copyright
-** notice, this list of conditions and the following disclaimer in
-** the documentation and/or other materials provided with the
-** distribution.
-** * 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.
-**
-**
-** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
-** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
-** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
-** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
-** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
-** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
-** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
-** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
-** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include <QtOpenGL>
-#include <QImage>
-#include <QTimeLine>
-#include <QSvgRenderer>
-
-class GLWidget : public QGLWidget
-{
- Q_OBJECT
-
-public:
- GLWidget(QWidget *parent);
- ~GLWidget();
-
- void saveGLState();
- void restoreGLState();
-
- void paintEvent(QPaintEvent *);
- void mousePressEvent(QMouseEvent *);
- void mouseDoubleClickEvent(QMouseEvent *);
- void mouseMoveEvent(QMouseEvent *);
- void timerEvent(QTimerEvent *);
- void wheelEvent(QWheelEvent *);
-
-public slots:
- void animate(qreal);
- void animFinished();
- void draw();
-
-private:
- QPoint anchor;
- float scale;
- float rot_x, rot_y, rot_z;
- GLuint tile_list;
- GLfloat *wave;
- bool hasDynamicTextureUpdate;
-
- QImage logo;
- QTimeLine *anim;
- QSvgRenderer *svg_renderer;
-
- GLuint dynamicTexture;
- QGLPixelBuffer *pbuffer;
-};
-
diff --git a/examples/opengl/legacy/pbuffers2/main.cpp b/examples/opengl/legacy/pbuffers2/main.cpp
deleted file mode 100644
index 03da7ab545..0000000000
--- a/examples/opengl/legacy/pbuffers2/main.cpp
+++ /dev/null
@@ -1,71 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the examples of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:BSD$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** BSD License Usage
-** Alternatively, you may use this file under the terms of the BSD license
-** as follows:
-**
-** "Redistribution and use in source and binary forms, with or without
-** modification, are permitted provided that the following conditions are
-** met:
-** * Redistributions of source code must retain the above copyright
-** notice, this list of conditions and the following disclaimer.
-** * Redistributions in binary form must reproduce the above copyright
-** notice, this list of conditions and the following disclaimer in
-** the documentation and/or other materials provided with the
-** distribution.
-** * 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.
-**
-**
-** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
-** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
-** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
-** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
-** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
-** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
-** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
-** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
-** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include <QtWidgets/QApplication>
-#include <QtWidgets/QMessageBox>
-#include "glwidget.h"
-
-int main(int argc, char **argv)
-{
- Q_INIT_RESOURCE(pbuffers2);
-
- QApplication a(argc, argv);
- GLWidget widget(0);
- widget.resize(640, 480);
- widget.makeCurrent();
- if (!QGLFormat::hasOpenGL() || !QGLPixelBuffer::hasOpenGLPbuffers()) {
- QMessageBox::information(0, "OpenGL pbuffers 2",
- "This system does not support OpenGL/pbuffers.");
- return -1;
- }
- widget.show();
- return a.exec();
-}
-
diff --git a/examples/opengl/legacy/pbuffers2/pbuffers2.pro b/examples/opengl/legacy/pbuffers2/pbuffers2.pro
deleted file mode 100644
index f1baae3931..0000000000
--- a/examples/opengl/legacy/pbuffers2/pbuffers2.pro
+++ /dev/null
@@ -1,11 +0,0 @@
-QT += opengl svg widgets
-
-HEADERS += glwidget.h
-SOURCES += glwidget.cpp main.cpp
-RESOURCES += pbuffers2.qrc
-
-# install
-target.path = $$[QT_INSTALL_EXAMPLES]/opengl/legacy/pbuffers2
-INSTALLS += target
-
-qtConfig(opengles.|angle|dynamicgl): error("This example requires Qt to be configured with -opengl desktop")
diff --git a/examples/opengl/legacy/pbuffers2/pbuffers2.qrc b/examples/opengl/legacy/pbuffers2/pbuffers2.qrc
deleted file mode 100644
index 986f1ca385..0000000000
--- a/examples/opengl/legacy/pbuffers2/pbuffers2.qrc
+++ /dev/null
@@ -1,6 +0,0 @@
-<!DOCTYPE RCC><RCC version="1.0">
-<qresource prefix="/res">
- <file>bubbles.svg</file>
- <file>designer.png</file>
-</qresource>
-</RCC>
diff --git a/examples/opengl/legacy/samplebuffers/glwidget.cpp b/examples/opengl/legacy/samplebuffers/glwidget.cpp
deleted file mode 100644
index da30de4d55..0000000000
--- a/examples/opengl/legacy/samplebuffers/glwidget.cpp
+++ /dev/null
@@ -1,174 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the examples of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:BSD$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** BSD License Usage
-** Alternatively, you may use this file under the terms of the BSD license
-** as follows:
-**
-** "Redistribution and use in source and binary forms, with or without
-** modification, are permitted provided that the following conditions are
-** met:
-** * Redistributions of source code must retain the above copyright
-** notice, this list of conditions and the following disclaimer.
-** * Redistributions in binary form must reproduce the above copyright
-** notice, this list of conditions and the following disclaimer in
-** the documentation and/or other materials provided with the
-** distribution.
-** * 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.
-**
-**
-** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
-** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
-** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
-** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
-** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
-** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
-** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
-** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
-** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include "glwidget.h"
-#include <qmath.h>
-
-#ifndef GL_MULTISAMPLE
-#define GL_MULTISAMPLE 0x809D
-#endif
-
-GLWidget::GLWidget(QWidget *parent)
- : QGLWidget(QGLFormat(QGL::SampleBuffers), parent)
-{
- startTimer(40);
- setWindowTitle(tr("Sample Buffers"));
-}
-
-void GLWidget::initializeGL()
-{
- glMatrixMode(GL_PROJECTION);
- glLoadIdentity();
- glOrtho(-.5, .5, .5, -.5, -1000, 1000);
- glMatrixMode(GL_MODELVIEW);
- glLoadIdentity();
- glClearColor(1.0f, 1.0f, 1.0f, 1.0f);
-
- makeObject();
-}
-
-void GLWidget::resizeGL(int w, int h)
-{
- glViewport(0, 0, w, h);
-}
-
-void GLWidget::paintGL()
-{
- static float rot = 0.0;
- glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
-
- glMatrixMode(GL_MODELVIEW);
- glPushMatrix();
- glEnable(GL_MULTISAMPLE);
- glTranslatef(-0.25f, -0.10f, 0.0f);
- glScalef(0.75f, 1.15f, 0.0f);
- glRotatef(rot, 0.0f, 0.f, 1.0f);
- glCallList(list);
- glPopMatrix();
-
- glPushMatrix();
- glDisable(GL_MULTISAMPLE);
- glTranslatef(0.25f, -0.10f, 0.0f);
- glScalef(0.75f, 1.15f, 0.0f);
- glRotatef(rot, 0.0f, 0.0f, 1.0f);
- glCallList(list);
- glPopMatrix();
-
- rot += 0.2f;
-
- qglColor(Qt::black);
- renderText(-0.35, 0.4, 0.0, "Multisampling enabled");
- renderText(0.15, 0.4, 0.0, "Multisampling disabled");
-}
-
-void GLWidget::timerEvent(QTimerEvent *)
-{
- update();
-}
-
-void GLWidget::makeObject()
-{
- QColor qtGreen(QColor::fromCmykF(0.40, 0.0, 1.0, 0.0));
- const int NumSectors = 15;
- GLdouble x1 = +0.06;
- GLdouble y1 = -0.14;
- GLdouble x2 = +0.14;
- GLdouble y2 = -0.06;
- GLdouble x3 = +0.08;
- GLdouble y3 = +0.00;
- GLdouble x4 = +0.30;
- GLdouble y4 = +0.22;
-
- list = glGenLists(1);
- glNewList(list, GL_COMPILE);
- {
- const double sectorAngle = 2 * M_PI / NumSectors;
- for (int i = 0; i < NumSectors; ++i) {
- double angle = i * sectorAngle;
- GLdouble x5 = 0.30 * sin(angle);
- GLdouble y5 = 0.30 * cos(angle);
- GLdouble x6 = 0.20 * sin(angle);
- GLdouble y6 = 0.20 * cos(angle);
-
- angle += sectorAngle;
- GLdouble x7 = 0.20 * sin(angle);
- GLdouble y7 = 0.20 * cos(angle);
- GLdouble x8 = 0.30 * sin(angle);
- GLdouble y8 = 0.30 * cos(angle);
-
- qglColor(qtGreen);
- quad(GL_QUADS, x5, y5, x6, y6, x7, y7, x8, y8);
- qglColor(Qt::black);
- quad(GL_LINE_LOOP, x5, y5, x6, y6, x7, y7, x8, y8);
- }
-
- qglColor(qtGreen);
- quad(GL_QUADS, x1, y1, x2, y2, y2, x2, y1, x1);
- quad(GL_QUADS, x3, y3, x4, y4, y4, x4, y3, x3);
-
- qglColor(Qt::black);
- quad(GL_LINE_LOOP, x1, y1, x2, y2, y2, x2, y1, x1);
- quad(GL_LINE_LOOP, x3, y3, x4, y4, y4, x4, y3, x3);
- }
- glEndList();
-}
-
-void GLWidget::quad(GLenum primitive, GLdouble x1, GLdouble y1, GLdouble x2, GLdouble y2,
- GLdouble x3, GLdouble y3, GLdouble x4, GLdouble y4)
-{
- glBegin(primitive);
- {
- glVertex2d(x1, y1);
- glVertex2d(x2, y2);
- glVertex2d(x3, y3);
- glVertex2d(x4, y4);
- }
- glEnd();
-}
diff --git a/examples/opengl/legacy/samplebuffers/glwidget.h b/examples/opengl/legacy/samplebuffers/glwidget.h
deleted file mode 100644
index f02f0835ef..0000000000
--- a/examples/opengl/legacy/samplebuffers/glwidget.h
+++ /dev/null
@@ -1,71 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the examples of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:BSD$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** BSD License Usage
-** Alternatively, you may use this file under the terms of the BSD license
-** as follows:
-**
-** "Redistribution and use in source and binary forms, with or without
-** modification, are permitted provided that the following conditions are
-** met:
-** * Redistributions of source code must retain the above copyright
-** notice, this list of conditions and the following disclaimer.
-** * Redistributions in binary form must reproduce the above copyright
-** notice, this list of conditions and the following disclaimer in
-** the documentation and/or other materials provided with the
-** distribution.
-** * 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.
-**
-**
-** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
-** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
-** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
-** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
-** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
-** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
-** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
-** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
-** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include <QtOpenGL>
-
-class GLWidget : public QGLWidget
-{
-public:
- GLWidget(QWidget *parent);
-
-protected:
- void initializeGL() override;
- void resizeGL(int w, int h) override;
- void paintGL() override;
- void timerEvent(QTimerEvent *) override;
-
- void makeObject();
- void quad(GLenum primitive, GLdouble x1, GLdouble y1, GLdouble x2, GLdouble y2,
- GLdouble x3, GLdouble y3, GLdouble x4, GLdouble y4);
-
-private:
- GLuint list;
-};
-
diff --git a/examples/opengl/legacy/samplebuffers/main.cpp b/examples/opengl/legacy/samplebuffers/main.cpp
deleted file mode 100644
index 216dff1fda..0000000000
--- a/examples/opengl/legacy/samplebuffers/main.cpp
+++ /dev/null
@@ -1,81 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the examples of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:BSD$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** BSD License Usage
-** Alternatively, you may use this file under the terms of the BSD license
-** as follows:
-**
-** "Redistribution and use in source and binary forms, with or without
-** modification, are permitted provided that the following conditions are
-** met:
-** * Redistributions of source code must retain the above copyright
-** notice, this list of conditions and the following disclaimer.
-** * Redistributions in binary form must reproduce the above copyright
-** notice, this list of conditions and the following disclaimer in
-** the documentation and/or other materials provided with the
-** distribution.
-** * 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.
-**
-**
-** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
-** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
-** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
-** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
-** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
-** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
-** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
-** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
-** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include <QtWidgets/QApplication>
-#include <QtWidgets/QMessageBox>
-#include "glwidget.h"
-
-int main(int argc, char **argv)
-{
- QApplication a(argc, argv);
-
- QGLFormat f = QGLFormat::defaultFormat();
- f.setSampleBuffers(true);
- QGLFormat::setDefaultFormat(f);
- if (!QGLFormat::hasOpenGL()) {
- QMessageBox::information(0, "OpenGL samplebuffers",
- "This system does not support OpenGL.");
- return 0;
- }
-
- GLWidget widget(0);
-
- if (!widget.format().sampleBuffers()) {
- QMessageBox::information(0, "OpenGL samplebuffers",
- "This system does not have sample buffer support.");
- return 0;
- }
-
- widget.resize(640, 480);
- widget.show();
-
- return a.exec();
-}
-
diff --git a/examples/opengl/legacy/samplebuffers/samplebuffers.pro b/examples/opengl/legacy/samplebuffers/samplebuffers.pro
deleted file mode 100644
index aca56f8df8..0000000000
--- a/examples/opengl/legacy/samplebuffers/samplebuffers.pro
+++ /dev/null
@@ -1,10 +0,0 @@
-HEADERS += glwidget.h
-SOURCES += glwidget.cpp main.cpp
-
-QT += opengl widgets
-
-# install
-target.path = $$[QT_INSTALL_EXAMPLES]/opengl/legacy/samplebuffers
-INSTALLS += target
-
-qtConfig(opengles.|angle|dynamicgl): error("This example requires Qt to be configured with -opengl desktop")
diff --git a/examples/opengl/legacy/shared/qtlogo.cpp b/examples/opengl/legacy/shared/qtlogo.cpp
deleted file mode 100644
index 9ad274ce09..0000000000
--- a/examples/opengl/legacy/shared/qtlogo.cpp
+++ /dev/null
@@ -1,398 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the examples of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:BSD$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** BSD License Usage
-** Alternatively, you may use this file under the terms of the BSD license
-** as follows:
-**
-** "Redistribution and use in source and binary forms, with or without
-** modification, are permitted provided that the following conditions are
-** met:
-** * Redistributions of source code must retain the above copyright
-** notice, this list of conditions and the following disclaimer.
-** * Redistributions in binary form must reproduce the above copyright
-** notice, this list of conditions and the following disclaimer in
-** the documentation and/or other materials provided with the
-** distribution.
-** * 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.
-**
-**
-** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
-** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
-** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
-** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
-** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
-** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
-** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
-** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
-** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include "qtlogo.h"
-
-#include <QGLWidget>
-#include <QMatrix4x4>
-#include <QVector3D>
-#include <QOpenGLFunctions_1_1>
-
-#include <qmath.h>
-
-static const qreal tee_height = 0.311126;
-static const qreal cross_width = 0.25;
-static const qreal bar_thickness = 0.113137;
-static const qreal logo_depth = 0.10;
-
-//! [0]
-struct Geometry
-{
- QVector<GLushort> faces;
- QVector<QVector3D> vertices;
- QVector<QVector3D> normals;
- void appendSmooth(const QVector3D &a, const QVector3D &n, int from);
- void appendFaceted(const QVector3D &a, const QVector3D &n);
- void finalize();
- void loadArrays(QOpenGLFunctions_1_1 *functions) const;
-};
-//! [0]
-
-//! [1]
-class Patch
-{
-public:
- enum Smoothing { Faceted, Smooth };
- Patch(Geometry *);
- void setSmoothing(Smoothing s) { sm = s; }
- void translate(const QVector3D &t);
- void rotate(qreal deg, QVector3D axis);
- void draw(QOpenGLFunctions_1_1 *functions) const;
- void addTri(const QVector3D &a, const QVector3D &b, const QVector3D &c, const QVector3D &n);
- void addQuad(const QVector3D &a, const QVector3D &b, const QVector3D &c, const QVector3D &d);
-
- GLushort start;
- GLushort count;
- GLushort initv;
-
- GLfloat faceColor[4];
- QMatrix4x4 mat;
- Smoothing sm;
- Geometry *geom;
-};
-//! [1]
-
-static inline void qSetColor(float colorVec[], QColor c)
-{
- colorVec[0] = c.redF();
- colorVec[1] = c.greenF();
- colorVec[2] = c.blueF();
- colorVec[3] = c.alphaF();
-}
-
-void Geometry::loadArrays(QOpenGLFunctions_1_1 *functions) const
-{
- functions->glVertexPointer(3, GL_FLOAT, 0, vertices.constData());
- functions->glNormalPointer(GL_FLOAT, 0, normals.constData());
-}
-
-void Geometry::finalize()
-{
- // TODO: add vertex buffer uploading here
-
- // Finish smoothing normals by ensuring accumulated normals are returned
- // to length 1.0.
- for (int i = 0; i < normals.count(); ++i)
- normals[i].normalize();
-}
-
-void Geometry::appendSmooth(const QVector3D &a, const QVector3D &n, int from)
-{
- // Smooth normals are achieved by averaging the normals for faces meeting
- // at a point. First find the point in geometry already generated
- // (working backwards, since most often the points shared are between faces
- // recently added).
- int v = vertices.count() - 1;
- for ( ; v >= from; --v)
- if (qFuzzyCompare(vertices[v], a))
- break;
-
- if (v < from) {
- // The vertex was not found so add it as a new one, and initialize
- // its corresponding normal
- v = vertices.count();
- vertices.append(a);
- normals.append(n);
- } else {
- // Vert found, accumulate normals into corresponding normal slot.
- // Must call finalize once finished accumulating normals
- normals[v] += n;
- }
-
- // In both cases (found or not) reference the vertex via its index
- faces.append(v);
-}
-
-void Geometry::appendFaceted(const QVector3D &a, const QVector3D &n)
-{
- // Faceted normals are achieved by duplicating the vertex for every
- // normal, so that faces meeting at a vertex get a sharp edge.
- int v = vertices.count();
- vertices.append(a);
- normals.append(n);
- faces.append(v);
-}
-
-Patch::Patch(Geometry *g)
- : start(g->faces.count())
- , count(0)
- , initv(g->vertices.count())
- , sm(Patch::Smooth)
- , geom(g)
-{
- qSetColor(faceColor, QColor(Qt::darkGray));
-}
-
-void Patch::rotate(qreal deg, QVector3D axis)
-{
- mat.rotate(deg, axis);
-}
-
-void Patch::translate(const QVector3D &t)
-{
- mat.translate(t);
-}
-
-//! [2]
-void Patch::draw(QOpenGLFunctions_1_1 *functions) const
-{
- functions->glPushMatrix();
- functions->glMultMatrixf(mat.constData());
- functions->glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, faceColor);
-
- const GLushort *indices = geom->faces.constData();
- functions->glDrawElements(GL_TRIANGLES, count, GL_UNSIGNED_SHORT, indices + start);
- functions->glPopMatrix();
-}
-//! [2]
-
-void Patch::addTri(const QVector3D &a, const QVector3D &b, const QVector3D &c, const QVector3D &n)
-{
- QVector3D norm = n.isNull() ? QVector3D::normal(a, b, c) : n;
-
- if (sm == Smooth) {
- geom->appendSmooth(a, norm, initv);
- geom->appendSmooth(b, norm, initv);
- geom->appendSmooth(c, norm, initv);
- } else {
- geom->appendFaceted(a, norm);
- geom->appendFaceted(b, norm);
- geom->appendFaceted(c, norm);
- }
-
- count += 3;
-}
-
-void Patch::addQuad(const QVector3D &a, const QVector3D &b, const QVector3D &c, const QVector3D &d)
-{
- QVector3D norm = QVector3D::normal(a, b, c);
-
- if (sm == Smooth) {
- addTri(a, b, c, norm);
- addTri(a, c, d, norm);
- } else {
- // If faceted share the two common vertices
- addTri(a, b, c, norm);
- int k = geom->vertices.count();
- geom->appendSmooth(a, norm, k);
- geom->appendSmooth(c, norm, k);
- geom->appendFaceted(d, norm);
- count += 3;
- }
-}
-
-static inline QVector<QVector3D> extrude(const QVector<QVector3D> &vertices, qreal depth)
-{
- QVector<QVector3D> extr = vertices;
- for (int v = 0; v < extr.count(); ++v)
- extr[v].setZ(extr[v].z() - depth);
- return extr;
-}
-
-class Rectoid
-{
-public:
- void translate(const QVector3D &t)
- {
- for (int i = 0; i < parts.count(); ++i)
- parts[i]->translate(t);
- }
-
- void rotate(qreal deg, QVector3D axis)
- {
- for (int i = 0; i < parts.count(); ++i)
- parts[i]->rotate(deg, axis);
- }
-
- // No special Rectoid destructor - the parts are fetched out of this member
- // variable, and destroyed by the new owner
- QList<Patch *> parts;
-};
-
-class RectPrism : public Rectoid
-{
-public:
- RectPrism(Geometry *g, qreal width, qreal height, qreal depth);
-};
-
-RectPrism::RectPrism(Geometry *g, qreal width, qreal height, qreal depth)
-{
- enum { bl, br, tr, tl };
- Patch *fb = new Patch(g);
- fb->setSmoothing(Patch::Faceted);
-
- // front face
- QVector<QVector3D> r(4);
- r[br].setX(width);
- r[tr].setX(width);
- r[tr].setY(height);
- r[tl].setY(height);
- QVector3D adjToCenter(-width / 2.0, -height / 2.0, depth / 2.0);
- for (int i = 0; i < 4; ++i)
- r[i] += adjToCenter;
- fb->addQuad(r[bl], r[br], r[tr], r[tl]);
-
- // back face
- QVector<QVector3D> s = extrude(r, depth);
- fb->addQuad(s[tl], s[tr], s[br], s[bl]);
-
- // side faces
- Patch *sides = new Patch(g);
- sides->setSmoothing(Patch::Faceted);
- sides->addQuad(s[bl], s[br], r[br], r[bl]);
- sides->addQuad(s[br], s[tr], r[tr], r[br]);
- sides->addQuad(s[tr], s[tl], r[tl], r[tr]);
- sides->addQuad(s[tl], s[bl], r[bl], r[tl]);
-
- parts << fb << sides;
-}
-
-class RectTorus : public Rectoid
-{
-public:
- RectTorus(Geometry *g, qreal iRad, qreal oRad, qreal depth, int numSectors);
-};
-
-RectTorus::RectTorus(Geometry *g, qreal iRad, qreal oRad, qreal depth, int k)
-{
- QVector<QVector3D> inside;
- QVector<QVector3D> outside;
- for (int i = 0; i < k; ++i) {
- qreal angle = (i * 2 * M_PI) / k;
- inside << QVector3D(iRad * qSin(angle), iRad * qCos(angle), depth / 2.0);
- outside << QVector3D(oRad * qSin(angle), oRad * qCos(angle), depth / 2.0);
- }
- inside << QVector3D(0.0, iRad, 0.0);
- outside << QVector3D(0.0, oRad, 0.0);
- QVector<QVector3D> in_back = extrude(inside, depth);
- QVector<QVector3D> out_back = extrude(outside, depth);
-
- // Create front, back and sides as separate patches so that smooth normals
- // are generated for the curving sides, but a faceted edge is created between
- // sides and front/back
- Patch *front = new Patch(g);
- for (int i = 0; i < k; ++i)
- front->addQuad(outside[i], inside[i],
- inside[(i + 1) % k], outside[(i + 1) % k]);
- Patch *back = new Patch(g);
- for (int i = 0; i < k; ++i)
- back->addQuad(in_back[i], out_back[i],
- out_back[(i + 1) % k], in_back[(i + 1) % k]);
- Patch *is = new Patch(g);
- for (int i = 0; i < k; ++i)
- is->addQuad(in_back[i], in_back[(i + 1) % k],
- inside[(i + 1) % k], inside[i]);
- Patch *os = new Patch(g);
- for (int i = 0; i < k; ++i)
- os->addQuad(out_back[(i + 1) % k], out_back[i],
- outside[i], outside[(i + 1) % k]);
- parts << front << back << is << os;
-}
-
-QtLogo::QtLogo(QObject *parent, int divisions, qreal scale)
- : QObject(parent)
- , geom(new Geometry())
-{
- buildGeometry(divisions, scale);
-}
-
-QtLogo::~QtLogo()
-{
- qDeleteAll(parts);
- delete geom;
-}
-
-void QtLogo::setColor(QColor c)
-{
- for (int i = 0; i < parts.count(); ++i)
- qSetColor(parts[i]->faceColor, c);
-}
-
-//! [3]
-void QtLogo::buildGeometry(int divisions, qreal scale)
-{
- qreal cw = cross_width * scale;
- qreal bt = bar_thickness * scale;
- qreal ld = logo_depth * scale;
- qreal th = tee_height *scale;
-
- RectPrism cross(geom, cw, bt, ld);
- RectPrism stem(geom, bt, th, ld);
-
- QVector3D z(0.0, 0.0, 1.0);
- cross.rotate(45.0, z);
- stem.rotate(45.0, z);
-
- qreal stem_downshift = (th + bt) / 2.0;
- stem.translate(QVector3D(0.0, -stem_downshift, 0.0));
-
- RectTorus body(geom, 0.20, 0.30, 0.1, divisions);
-
- parts << stem.parts << cross.parts << body.parts;
-
- geom->finalize();
-}
-//! [3]
-
-//! [4]
-void QtLogo::draw(QOpenGLFunctions_1_1 *functions) const
-{
- geom->loadArrays(functions);
-
- functions->glEnableClientState(GL_VERTEX_ARRAY);
- functions->glEnableClientState(GL_NORMAL_ARRAY);
-
- for (int i = 0; i < parts.count(); ++i)
- parts[i]->draw(functions);
-
- functions->glDisableClientState(GL_VERTEX_ARRAY);
- functions->glDisableClientState(GL_NORMAL_ARRAY);
-}
-//! [4]
diff --git a/examples/opengl/legacy/shared/qtlogo.h b/examples/opengl/legacy/shared/qtlogo.h
deleted file mode 100644
index ed2d7d750d..0000000000
--- a/examples/opengl/legacy/shared/qtlogo.h
+++ /dev/null
@@ -1,78 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the examples of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:BSD$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** BSD License Usage
-** Alternatively, you may use this file under the terms of the BSD license
-** as follows:
-**
-** "Redistribution and use in source and binary forms, with or without
-** modification, are permitted provided that the following conditions are
-** met:
-** * Redistributions of source code must retain the above copyright
-** notice, this list of conditions and the following disclaimer.
-** * Redistributions in binary form must reproduce the above copyright
-** notice, this list of conditions and the following disclaimer in
-** the documentation and/or other materials provided with the
-** distribution.
-** * 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.
-**
-**
-** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
-** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
-** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
-** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
-** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
-** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
-** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
-** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
-** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef QTLOGO_H
-#define QTLOGO_H
-
-#include <QObject>
-#include <QColor>
-
-QT_FORWARD_DECLARE_CLASS(QOpenGLFunctions_1_1)
-
-class Patch;
-struct Geometry;
-
-//! [0]
-class QtLogo : public QObject
-{
-public:
- explicit QtLogo(QObject *parent, int d = 64, qreal s = 1.0);
- ~QtLogo();
- void setColor(QColor c);
- void draw(QOpenGLFunctions_1_1 *functions) const;
-private:
- void buildGeometry(int d, qreal s);
-
- QList<Patch *> parts;
- Geometry *geom;
-};
-//! [0]
-
-#endif // QTLOGO_H
diff --git a/examples/opengl/opengl.pro b/examples/opengl/opengl.pro
index 89b3e1d86e..6ee57c7018 100644
--- a/examples/opengl/opengl.pro
+++ b/examples/opengl/opengl.pro
@@ -1,20 +1,12 @@
TEMPLATE = subdirs
-SUBDIRS = hellowindow \
- paintedwindow \
- qopenglwindow
+SUBDIRS = openglwindow \
+ hellogles3
qtHaveModule(widgets) {
- SUBDIRS += contextinfo \
- threadedqopenglwidget \
- 2dpainting \
+ SUBDIRS += 2dpainting \
hellogl2 \
- qopenglwidget \
cube \
textures \
- hellogles3 \
- computegles31
+ stereoqopenglwidget
}
-
-EXAMPLE_FILES += \
- legacy
diff --git a/examples/opengl/openglwindow/CMakeLists.txt b/examples/opengl/openglwindow/CMakeLists.txt
new file mode 100644
index 0000000000..0258a42822
--- /dev/null
+++ b/examples/opengl/openglwindow/CMakeLists.txt
@@ -0,0 +1,38 @@
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
+
+cmake_minimum_required(VERSION 3.16)
+project(openglwindow LANGUAGES CXX)
+
+find_package(Qt6 REQUIRED COMPONENTS Core Gui OpenGL)
+
+qt_standard_project_setup()
+
+qt_add_executable(openglwindow
+ main.cpp
+ openglwindow.cpp openglwindow.h
+)
+
+set_target_properties(openglwindow PROPERTIES
+ WIN32_EXECUTABLE TRUE
+ MACOSX_BUNDLE TRUE
+)
+
+target_link_libraries(openglwindow PRIVATE
+ Qt6::Core
+ Qt6::Gui
+ Qt6::OpenGL
+)
+
+install(TARGETS openglwindow
+ BUNDLE DESTINATION .
+ RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
+ LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
+)
+
+qt_generate_deploy_app_script(
+ TARGET openglwindow
+ OUTPUT_SCRIPT deploy_script
+ NO_UNSUPPORTED_PLATFORM_ERROR
+)
+install(SCRIPT ${deploy_script})
diff --git a/examples/opengl/openglwindow/main.cpp b/examples/opengl/openglwindow/main.cpp
new file mode 100644
index 0000000000..89933fa379
--- /dev/null
+++ b/examples/opengl/openglwindow/main.cpp
@@ -0,0 +1,125 @@
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
+
+#include "openglwindow.h"
+
+#include <QGuiApplication>
+#include <QMatrix4x4>
+#include <QOpenGLShaderProgram>
+#include <QOpenGLBuffer>
+#include <QScreen>
+#include <QtMath>
+
+//! [1]
+class TriangleWindow : public OpenGLWindow
+{
+public:
+ using OpenGLWindow::OpenGLWindow;
+
+ void initialize() override;
+ void render() override;
+
+private:
+ GLint m_matrixUniform = 0;
+ QOpenGLBuffer m_vbo;
+ QOpenGLShaderProgram *m_program = nullptr;
+ int m_frame = 0;
+};
+//! [1]
+
+//! [2]
+int main(int argc, char **argv)
+{
+ QGuiApplication app(argc, argv);
+
+ QSurfaceFormat format;
+ format.setSamples(16);
+
+ TriangleWindow window;
+ window.setFormat(format);
+ window.resize(640, 480);
+ window.show();
+
+ window.setAnimating(true);
+
+ return app.exec();
+}
+//! [2]
+
+//! [3]
+static const char *vertexShaderSource = "attribute highp vec4 posAttr;\n"
+ "attribute lowp vec4 colAttr;\n"
+ "varying lowp vec4 col;\n"
+ "uniform highp mat4 matrix;\n"
+ "void main() {\n"
+ " col = colAttr;\n"
+ " gl_Position = matrix * posAttr;\n"
+ "}\n";
+
+static const char *fragmentShaderSource = "varying lowp vec4 col;\n"
+ "void main() {\n"
+ " gl_FragColor = col;\n"
+ "}\n";
+//! [3]
+
+//! [4]
+void TriangleWindow::initialize()
+{
+ static const GLfloat vertices_colors[] = { +0.0f, +0.707f, 1.0f, 0.0f, 0.0f,
+ -0.5f, -0.500f, 0.0f, 1.0f, 0.0f,
+ +0.5f, -0.500f, 0.0f, 0.0f, 1.0f };
+
+ m_vbo.create();
+ m_vbo.bind();
+ m_vbo.allocate(vertices_colors, sizeof(vertices_colors));
+
+ glEnableVertexAttribArray(0);
+ glEnableVertexAttribArray(1);
+
+ glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, 5 * sizeof(GLfloat), nullptr);
+ glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, 5 * sizeof(GLfloat),
+ reinterpret_cast<void *>(2 * sizeof(GLfloat)));
+
+ m_program = new QOpenGLShaderProgram(this);
+ m_program->addShaderFromSourceCode(QOpenGLShader::Vertex, vertexShaderSource);
+ m_program->addShaderFromSourceCode(QOpenGLShader::Fragment, fragmentShaderSource);
+ m_program->bindAttributeLocation("posAttr", 0);
+ m_program->bindAttributeLocation("colAttr", 1);
+ m_program->link();
+ m_program->bind();
+
+ m_matrixUniform = m_program->uniformLocation("matrix");
+ Q_ASSERT(m_matrixUniform != -1);
+}
+//! [4]
+
+//! [5]
+void TriangleWindow::render()
+{
+ const qreal retinaScale = devicePixelRatio();
+ glViewport(0, 0, width() * retinaScale, height() * retinaScale);
+
+ glClear(GL_COLOR_BUFFER_BIT);
+
+ m_program->bind();
+
+ QMatrix4x4 matrix;
+ matrix.perspective(60.0f, 4.0f / 3.0f, 0.1f, 100.0f);
+ matrix.translate(0, 0, -2);
+ matrix.rotate(100.0f * m_frame / screen()->refreshRate(), 0, 1, 0);
+
+ m_program->setUniformValue(m_matrixUniform, matrix);
+
+ glEnableVertexAttribArray(0);
+ glEnableVertexAttribArray(1);
+
+ glDrawArrays(GL_TRIANGLES, 0, 3);
+
+ glDisableVertexAttribArray(0);
+ glDisableVertexAttribArray(1);
+
+ m_program->release();
+
+ ++m_frame;
+}
+//! [5]
diff --git a/examples/opengl/openglwindow/openglwindow.cpp b/examples/opengl/openglwindow/openglwindow.cpp
new file mode 100644
index 0000000000..4869f45e4c
--- /dev/null
+++ b/examples/opengl/openglwindow/openglwindow.cpp
@@ -0,0 +1,114 @@
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
+
+#include "openglwindow.h"
+
+#include <QOpenGLContext>
+#include <QOpenGLPaintDevice>
+#include <QPainter>
+
+//! [1]
+OpenGLWindow::OpenGLWindow(QWindow *parent)
+ : QWindow(parent)
+{
+ setSurfaceType(QWindow::OpenGLSurface);
+}
+//! [1]
+
+OpenGLWindow::~OpenGLWindow()
+{
+ delete m_device;
+}
+//! [2]
+void OpenGLWindow::render(QPainter *painter)
+{
+ Q_UNUSED(painter);
+}
+
+void OpenGLWindow::initialize()
+{
+}
+
+void OpenGLWindow::render()
+{
+ if (!m_device)
+ m_device = new QOpenGLPaintDevice;
+
+ glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
+
+ m_device->setSize(size() * devicePixelRatio());
+ m_device->setDevicePixelRatio(devicePixelRatio());
+
+ QPainter painter(m_device);
+ render(&painter);
+}
+//! [2]
+
+//! [3]
+void OpenGLWindow::renderLater()
+{
+ requestUpdate();
+}
+
+bool OpenGLWindow::event(QEvent *event)
+{
+ switch (event->type()) {
+ case QEvent::UpdateRequest:
+ renderNow();
+ return true;
+ default:
+ return QWindow::event(event);
+ }
+}
+
+void OpenGLWindow::exposeEvent(QExposeEvent *event)
+{
+ Q_UNUSED(event);
+
+ if (isExposed())
+ renderNow();
+}
+//! [3]
+
+//! [4]
+void OpenGLWindow::renderNow()
+{
+ if (!isExposed())
+ return;
+
+ bool needsInitialize = false;
+
+ if (!m_context) {
+ m_context = new QOpenGLContext(this);
+ m_context->setFormat(requestedFormat());
+ m_context->create();
+
+ needsInitialize = true;
+ }
+
+ m_context->makeCurrent(this);
+
+ if (needsInitialize) {
+ initializeOpenGLFunctions();
+ initialize();
+ }
+
+ render();
+
+ m_context->swapBuffers(this);
+
+ if (m_animating)
+ renderLater();
+}
+//! [4]
+
+//! [5]
+void OpenGLWindow::setAnimating(bool animating)
+{
+ m_animating = animating;
+
+ if (animating)
+ renderLater();
+}
+//! [5]
+
diff --git a/examples/opengl/openglwindow/openglwindow.h b/examples/opengl/openglwindow/openglwindow.h
new file mode 100644
index 0000000000..41bcbab9c4
--- /dev/null
+++ b/examples/opengl/openglwindow/openglwindow.h
@@ -0,0 +1,46 @@
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
+
+#ifndef OPENGLWINDOW_H
+#define OPENGLWINDOW_H
+
+#include <QWindow>
+#include <QOpenGLFunctions>
+
+QT_FORWARD_DECLARE_CLASS(QPainter)
+QT_FORWARD_DECLARE_CLASS(QOpenGLContext)
+QT_FORWARD_DECLARE_CLASS(QOpenGLPaintDevice)
+
+//! [1]
+class OpenGLWindow : public QWindow, protected QOpenGLFunctions
+{
+ Q_OBJECT
+public:
+ explicit OpenGLWindow(QWindow *parent = nullptr);
+ ~OpenGLWindow();
+
+ virtual void render(QPainter *painter);
+ virtual void render();
+
+ virtual void initialize();
+
+ void setAnimating(bool animating);
+
+public slots:
+ void renderLater();
+ void renderNow();
+
+protected:
+ bool event(QEvent *event) override;
+
+ void exposeEvent(QExposeEvent *event) override;
+
+private:
+ bool m_animating = false;
+
+ QOpenGLContext *m_context = nullptr;
+ QOpenGLPaintDevice *m_device = nullptr;
+};
+//! [1]
+
+#endif // OPENGLWINDOW_H
diff --git a/examples/opengl/openglwindow/openglwindow.pri b/examples/opengl/openglwindow/openglwindow.pri
new file mode 100644
index 0000000000..30320df3b7
--- /dev/null
+++ b/examples/opengl/openglwindow/openglwindow.pri
@@ -0,0 +1,4 @@
+QT += opengl
+INCLUDEPATH += $$PWD
+SOURCES += $$PWD/openglwindow.cpp
+HEADERS += $$PWD/openglwindow.h
diff --git a/examples/opengl/openglwindow/openglwindow.pro b/examples/opengl/openglwindow/openglwindow.pro
new file mode 100644
index 0000000000..8b1ae71c14
--- /dev/null
+++ b/examples/opengl/openglwindow/openglwindow.pro
@@ -0,0 +1,7 @@
+include(openglwindow.pri)
+
+SOURCES += \
+ main.cpp
+
+target.path = $$[QT_INSTALL_EXAMPLES]/opengl/openglwindow
+INSTALLS += target
diff --git a/examples/opengl/paintedwindow/main.cpp b/examples/opengl/paintedwindow/main.cpp
deleted file mode 100644
index 7e3e64d98c..0000000000
--- a/examples/opengl/paintedwindow/main.cpp
+++ /dev/null
@@ -1,65 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the examples of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:BSD$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** BSD License Usage
-** Alternatively, you may use this file under the terms of the BSD license
-** as follows:
-**
-** "Redistribution and use in source and binary forms, with or without
-** modification, are permitted provided that the following conditions are
-** met:
-** * Redistributions of source code must retain the above copyright
-** notice, this list of conditions and the following disclaimer.
-** * Redistributions in binary form must reproduce the above copyright
-** notice, this list of conditions and the following disclaimer in
-** the documentation and/or other materials provided with the
-** distribution.
-** * 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.
-**
-**
-** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
-** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
-** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
-** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
-** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
-** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
-** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
-** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
-** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include <QGuiApplication>
-#include <QRect>
-
-#include "paintedwindow.h"
-
-int main(int argc, char **argv)
-{
- QGuiApplication app(argc, argv);
-
- PaintedWindow window;
- window.show();
-
- return app.exec();
-}
-
diff --git a/examples/opengl/paintedwindow/paintedwindow.cpp b/examples/opengl/paintedwindow/paintedwindow.cpp
deleted file mode 100644
index 799431a765..0000000000
--- a/examples/opengl/paintedwindow/paintedwindow.cpp
+++ /dev/null
@@ -1,231 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the examples of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:BSD$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** BSD License Usage
-** Alternatively, you may use this file under the terms of the BSD license
-** as follows:
-**
-** "Redistribution and use in source and binary forms, with or without
-** modification, are permitted provided that the following conditions are
-** met:
-** * Redistributions of source code must retain the above copyright
-** notice, this list of conditions and the following disclaimer.
-** * Redistributions in binary form must reproduce the above copyright
-** notice, this list of conditions and the following disclaimer in
-** the documentation and/or other materials provided with the
-** distribution.
-** * 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.
-**
-**
-** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
-** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
-** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
-** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
-** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
-** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
-** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
-** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
-** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include "paintedwindow.h"
-
-#include <QGuiApplication>
-#include <QOpenGLContext>
-#include <QOpenGLPaintDevice>
-#include <QPainter>
-#include <QScreen>
-#include <QTimer>
-
-#include <qmath.h>
-
-PaintedWindow::PaintedWindow()
-{
- QSurfaceFormat format;
- format.setStencilBufferSize(8);
- format.setSamples(4);
-
- setSurfaceType(QWindow::OpenGLSurface);
- setFlags(Qt::Window | Qt::WindowTitleHint | Qt::WindowSystemMenuHint | Qt::WindowMinMaxButtonsHint | Qt::WindowCloseButtonHint);
- setFormat(format);
-
- create();
-
- m_context = new QOpenGLContext(this);
- m_context->setFormat(format);
- m_context->create();
-
- m_animation = new QPropertyAnimation(this, "rotation");
- m_animation->setStartValue(qreal(0));
- m_animation->setEndValue(qreal(1));
- m_animation->setDuration(500);
-
- QRect screenGeometry = screen()->availableGeometry();
-
- QPoint center = screenGeometry.center();
- QRect windowRect = screen()->isLandscape(screen()->orientation()) ? QRect(0, 0, 640, 480) : QRect(0, 0, 480, 640);
- setGeometry(QRect(center - windowRect.center(), windowRect.size()));
-
- m_rotation = 0;
-
- reportContentOrientationChange(screen()->orientation());
-
- m_targetOrientation = contentOrientation();
- m_nextTargetOrientation = Qt::PrimaryOrientation;
-
- connect(screen(), &QScreen::orientationChanged, this, &PaintedWindow::orientationChanged);
- connect(m_animation, &QAbstractAnimation::finished, this, &PaintedWindow::rotationDone);
- connect(this, &PaintedWindow::rotationChanged, this, QOverload<>::of(&PaintedWindow::paint));
-}
-
-void PaintedWindow::exposeEvent(QExposeEvent *)
-{
- if (isExposed())
- paint();
-}
-
-void PaintedWindow::mousePressEvent(QMouseEvent *)
-{
- Qt::ScreenOrientation o = contentOrientation();
- switch (o) {
- case Qt::LandscapeOrientation:
- orientationChanged(Qt::PortraitOrientation);
- break;
- case Qt::PortraitOrientation:
- orientationChanged(Qt::InvertedLandscapeOrientation);
- break;
- case Qt::InvertedLandscapeOrientation:
- orientationChanged(Qt::InvertedPortraitOrientation);
- break;
- case Qt::InvertedPortraitOrientation:
- orientationChanged(Qt::LandscapeOrientation);
- break;
- default:
- Q_ASSERT(false);
- }
-
- paint();
-}
-
-void PaintedWindow::orientationChanged(Qt::ScreenOrientation newOrientation)
-{
- if (contentOrientation() == newOrientation)
- return;
-
- if (m_animation->state() == QAbstractAnimation::Running) {
- m_nextTargetOrientation = newOrientation;
- return;
- }
-
- QRect rect(0, 0, width(), height());
-
- m_prevImage = QImage(width(), height(), QImage::Format_ARGB32_Premultiplied);
- m_nextImage = QImage(width(), height(), QImage::Format_ARGB32_Premultiplied);
- m_prevImage.fill(0);
- m_nextImage.fill(0);
-
- QPainter p;
- p.begin(&m_prevImage);
- p.setTransform(screen()->transformBetween(contentOrientation(), screen()->orientation(), rect));
- paint(&p, screen()->mapBetween(contentOrientation(), screen()->orientation(), rect));
- p.end();
-
- p.begin(&m_nextImage);
- p.setTransform(screen()->transformBetween(newOrientation, screen()->orientation(), rect));
- paint(&p, screen()->mapBetween(newOrientation, screen()->orientation(), rect));
- p.end();
-
- m_deltaRotation = screen()->angleBetween(newOrientation, contentOrientation());
- if (m_deltaRotation > 180)
- m_deltaRotation = 180 - m_deltaRotation;
-
- m_targetOrientation = newOrientation;
- m_animation->start();
-}
-
-void PaintedWindow::rotationDone()
-{
- reportContentOrientationChange(m_targetOrientation);
- if (m_nextTargetOrientation != Qt::PrimaryOrientation) {
- Q_ASSERT(m_animation->state() != QAbstractAnimation::Running);
- orientationChanged(m_nextTargetOrientation);
- m_nextTargetOrientation = Qt::PrimaryOrientation;
- }
-}
-
-void PaintedWindow::setRotation(qreal r)
-{
- if (r != m_rotation) {
- m_rotation = r;
- emit rotationChanged(r);
- }
-}
-
-void PaintedWindow::paint()
-{
- m_context->makeCurrent(this);
-
- QRect rect(0, 0, width() * devicePixelRatio(), height() * devicePixelRatio());
-
- QOpenGLPaintDevice device(size() * devicePixelRatio());
- QPainter painter(&device);
-
- QPainterPath path;
- path.addEllipse(rect);
- painter.setCompositionMode(QPainter::CompositionMode_Source);
- painter.fillRect(rect, Qt::transparent);
- painter.setCompositionMode(QPainter::CompositionMode_SourceOver);
- painter.fillPath(path, Qt::blue);
-
- if (contentOrientation() != m_targetOrientation) {
- painter.setRenderHint(QPainter::SmoothPixmapTransform);
- painter.save();
- painter.translate(width() / 2, height() / 2);
- painter.rotate(m_deltaRotation * m_rotation);
- painter.translate(-width() / 2, -height() / 2);
- painter.drawImage(0, 0, m_prevImage);
- painter.restore();
- painter.translate(width() / 2, height() / 2);
- painter.rotate(m_deltaRotation * m_rotation - m_deltaRotation);
- painter.translate(-width() / 2, -height() / 2);
- painter.setOpacity(m_rotation);
- painter.drawImage(0, 0, m_nextImage);
- } else {
- QRect mapped = screen()->mapBetween(contentOrientation(), screen()->orientation(), rect);
-
- painter.setTransform(screen()->transformBetween(contentOrientation(), screen()->orientation(), rect));
- paint(&painter, mapped);
- painter.end();
- }
-
- m_context->swapBuffers(this);
-}
-
-void PaintedWindow::paint(QPainter *painter, const QRect &rect)
-{
- painter->setRenderHint(QPainter::Antialiasing);
- QFont font;
- font.setPixelSize(64);
- painter->setFont(font);
- painter->drawText(rect, Qt::AlignCenter, "Hello");
-}
diff --git a/examples/opengl/paintedwindow/paintedwindow.h b/examples/opengl/paintedwindow/paintedwindow.h
deleted file mode 100644
index 7281451924..0000000000
--- a/examples/opengl/paintedwindow/paintedwindow.h
+++ /dev/null
@@ -1,104 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the examples of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:BSD$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** BSD License Usage
-** Alternatively, you may use this file under the terms of the BSD license
-** as follows:
-**
-** "Redistribution and use in source and binary forms, with or without
-** modification, are permitted provided that the following conditions are
-** met:
-** * Redistributions of source code must retain the above copyright
-** notice, this list of conditions and the following disclaimer.
-** * Redistributions in binary form must reproduce the above copyright
-** notice, this list of conditions and the following disclaimer in
-** the documentation and/or other materials provided with the
-** distribution.
-** * 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.
-**
-**
-** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
-** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
-** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
-** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
-** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
-** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
-** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
-** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
-** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include <QWindow>
-
-#include <QtGui/qopengl.h>
-#include <QtGui/qopenglshaderprogram.h>
-#include <QtGui/qopenglframebufferobject.h>
-
-#include <QPropertyAnimation>
-
-#include <QColor>
-#include <QImage>
-#include <QTime>
-
-QT_BEGIN_NAMESPACE
-class QOpenGLContext;
-QT_END_NAMESPACE
-
-class PaintedWindow : public QWindow
-{
- Q_OBJECT
- Q_PROPERTY(qreal rotation READ rotation WRITE setRotation NOTIFY rotationChanged)
-
-public:
- PaintedWindow();
-
- qreal rotation() const { return m_rotation; }
-
-signals:
- void rotationChanged(qreal rotation);
-
-private slots:
- void paint();
- void setRotation(qreal r);
- void orientationChanged(Qt::ScreenOrientation newOrientation);
- void rotationDone();
-
-private:
- void exposeEvent(QExposeEvent *) override;
- void mousePressEvent(QMouseEvent *) override;
-
- void paint(QPainter *painter, const QRect &rect);
-
- QOpenGLContext *m_context;
- qreal m_rotation;
-
- QImage m_prevImage;
- QImage m_nextImage;
- qreal m_deltaRotation;
-
- Qt::ScreenOrientation m_targetOrientation;
- Qt::ScreenOrientation m_nextTargetOrientation;
-
- QPropertyAnimation *m_animation;
- QTimer *m_paintTimer;
-};
diff --git a/examples/opengl/paintedwindow/paintedwindow.pro b/examples/opengl/paintedwindow/paintedwindow.pro
deleted file mode 100644
index 1846aa4049..0000000000
--- a/examples/opengl/paintedwindow/paintedwindow.pro
+++ /dev/null
@@ -1,6 +0,0 @@
-HEADERS += paintedwindow.h
-SOURCES += paintedwindow.cpp main.cpp
-
-# install
-target.path = $$[QT_INSTALL_EXAMPLES]/opengl/paintedwindow
-INSTALLS += target
diff --git a/examples/opengl/qopenglwidget/bubble.cpp b/examples/opengl/qopenglwidget/bubble.cpp
deleted file mode 100644
index 7e69aac3e7..0000000000
--- a/examples/opengl/qopenglwidget/bubble.cpp
+++ /dev/null
@@ -1,146 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the examples of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:BSD$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** BSD License Usage
-** Alternatively, you may use this file under the terms of the BSD license
-** as follows:
-**
-** "Redistribution and use in source and binary forms, with or without
-** modification, are permitted provided that the following conditions are
-** met:
-** * Redistributions of source code must retain the above copyright
-** notice, this list of conditions and the following disclaimer.
-** * Redistributions in binary form must reproduce the above copyright
-** notice, this list of conditions and the following disclaimer in
-** the documentation and/or other materials provided with the
-** distribution.
-** * 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.
-**
-**
-** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
-** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
-** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
-** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
-** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
-** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
-** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
-** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
-** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include <QtWidgets>
-
-#include "bubble.h"
-
-Bubble::Bubble(const QPointF &position, qreal radius, const QPointF &velocity)
- : position(position), vel(velocity), radius(radius)
-{
- innerColor = randomColor();
- outerColor = randomColor();
- updateBrush();
-}
-
-//! [0]
-void Bubble::updateCache()
-{
- delete cache;
- cache = new QImage(qRound(radius * 2 + 2), qRound(radius * 2 + 2), QImage::Format_ARGB32_Premultiplied);
- cache->fill(0x00000000);
- QPainter p(cache);
- p.setRenderHint(QPainter::Antialiasing);
- QPen pen(Qt::white);
- pen.setWidth(2);
- p.setPen(pen);
- p.setBrush(brush);
- p.drawEllipse(1, 1, int(2*radius), int(2*radius));
-}
-//! [0]
-
-Bubble::~Bubble()
-{
- delete cache;
-}
-
-void Bubble::updateBrush()
-{
- QRadialGradient gradient(QPointF(radius, radius), radius,
- QPointF(radius*0.5, radius*0.5));
-
- gradient.setColorAt(0, QColor(255, 255, 255, 255));
- gradient.setColorAt(0.25, innerColor);
- gradient.setColorAt(1, outerColor);
- brush = QBrush(gradient);
- updateCache();
-}
-
-//! [1]
-void Bubble::drawBubble(QPainter *painter)
-{
- painter->save();
- painter->translate(position.x() - radius, position.y() - radius);
- painter->setOpacity(0.8);
- painter->drawImage(0, 0, *cache);
- painter->restore();
-}
-//! [1]
-
-QColor Bubble::randomColor()
-{
- int red = int(185 + QRandomGenerator::global()->bounded(70));
- int green = int(185 + QRandomGenerator::global()->bounded(70));
- int blue = int(205 + QRandomGenerator::global()->bounded(50));
- int alpha = int(91 + QRandomGenerator::global()->bounded(100));
-
- return QColor(red, green, blue, alpha);
-}
-
-void Bubble::move(const QRect &bbox)
-{
- position += vel;
- qreal leftOverflow = position.x() - radius - bbox.left();
- qreal rightOverflow = position.x() + radius - bbox.right();
- qreal topOverflow = position.y() - radius - bbox.top();
- qreal bottomOverflow = position.y() + radius - bbox.bottom();
-
- if (leftOverflow < 0.0) {
- position.setX(position.x() - 2 * leftOverflow);
- vel.setX(-vel.x());
- } else if (rightOverflow > 0.0) {
- position.setX(position.x() - 2 * rightOverflow);
- vel.setX(-vel.x());
- }
-
- if (topOverflow < 0.0) {
- position.setY(position.y() - 2 * topOverflow);
- vel.setY(-vel.y());
- } else if (bottomOverflow > 0.0) {
- position.setY(position.y() - 2 * bottomOverflow);
- vel.setY(-vel.y());
- }
-}
-
-QRectF Bubble::rect()
-{
- return QRectF(position.x() - radius, position.y() - radius,
- 2 * radius, 2 * radius);
-}
diff --git a/examples/opengl/qopenglwidget/bubble.h b/examples/opengl/qopenglwidget/bubble.h
deleted file mode 100644
index 833ea02288..0000000000
--- a/examples/opengl/qopenglwidget/bubble.h
+++ /dev/null
@@ -1,86 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the examples of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:BSD$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** BSD License Usage
-** Alternatively, you may use this file under the terms of the BSD license
-** as follows:
-**
-** "Redistribution and use in source and binary forms, with or without
-** modification, are permitted provided that the following conditions are
-** met:
-** * Redistributions of source code must retain the above copyright
-** notice, this list of conditions and the following disclaimer.
-** * Redistributions in binary form must reproduce the above copyright
-** notice, this list of conditions and the following disclaimer in
-** the documentation and/or other materials provided with the
-** distribution.
-** * 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.
-**
-**
-** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
-** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
-** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
-** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
-** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
-** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
-** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
-** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
-** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef BUBBLE_H
-#define BUBBLE_H
-
-#include <QBrush>
-#include <QColor>
-#include <QPointF>
-#include <QRect>
-#include <QRectF>
-
-QT_FORWARD_DECLARE_CLASS(QPainter)
-
-class Bubble
-{
-public:
- Bubble(const QPointF &position, qreal radius, const QPointF &velocity);
- ~Bubble();
-
- void drawBubble(QPainter *painter);
- void updateBrush();
- void move(const QRect &bbox);
- void updateCache();
- QRectF rect();
-
-private:
- QColor randomColor();
-
- QBrush brush;
- QPointF position;
- QPointF vel;
- qreal radius;
- QColor innerColor;
- QColor outerColor;
- QImage *cache = nullptr;
-};
-
-#endif
diff --git a/examples/opengl/qopenglwidget/glwidget.cpp b/examples/opengl/qopenglwidget/glwidget.cpp
deleted file mode 100644
index 89c8469662..0000000000
--- a/examples/opengl/qopenglwidget/glwidget.cpp
+++ /dev/null
@@ -1,560 +0,0 @@
-/****************************************************************************
- **
- ** Copyright (C) 2016 The Qt Company Ltd.
- ** Contact: https://www.qt.io/licensing/
- **
- ** This file is part of the examples of the Qt Toolkit.
- **
- ** $QT_BEGIN_LICENSE:BSD$
- ** Commercial License Usage
- ** Licensees holding valid commercial Qt licenses may use this file in
- ** accordance with the commercial license agreement provided with the
- ** Software or, alternatively, in accordance with the terms contained in
- ** a written agreement between you and The Qt Company. For licensing terms
- ** and conditions see https://www.qt.io/terms-conditions. For further
- ** information use the contact form at https://www.qt.io/contact-us.
- **
- ** BSD License Usage
- ** Alternatively, you may use this file under the terms of the BSD license
- ** as follows:
- **
- ** "Redistribution and use in source and binary forms, with or without
- ** modification, are permitted provided that the following conditions are
- ** met:
- ** * Redistributions of source code must retain the above copyright
- ** notice, this list of conditions and the following disclaimer.
- ** * Redistributions in binary form must reproduce the above copyright
- ** notice, this list of conditions and the following disclaimer in
- ** the documentation and/or other materials provided with the
- ** distribution.
- ** * 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.
- **
- **
- ** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- ** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- ** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- ** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
- ** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- ** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- ** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- ** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- ** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- ** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- ** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
- **
- ** $QT_END_LICENSE$
- **
- ****************************************************************************/
-
-#include "glwidget.h"
-#include <QPainter>
-#include <QPaintEngine>
-#include <QOpenGLShaderProgram>
-#include <QOpenGLTexture>
-#include <QRandomGenerator>
-#include <QCoreApplication>
-#include <qmath.h>
-
-#include "mainwindow.h"
-#include "bubble.h"
-
-const int bubbleNum = 8;
-
-#ifndef GL_SRGB8_ALPHA8
-#define GL_SRGB8_ALPHA8 0x8C43
-#endif
-
-GLWidget::GLWidget(MainWindow *mw, bool button, const QColor &background)
- : m_mainWindow(mw),
- m_hasButton(button),
- m_background(background)
-{
- setMinimumSize(300, 250);
- if (QCoreApplication::arguments().contains(QStringLiteral("--srgb")))
- setTextureFormat(GL_SRGB8_ALPHA8);
-}
-
-GLWidget::~GLWidget()
-{
- qDeleteAll(m_bubbles);
-
- // And now release all OpenGL resources.
- makeCurrent();
- delete m_texture;
- delete m_program1;
- delete m_program2;
- delete m_vshader1;
- delete m_fshader1;
- delete m_vshader2;
- delete m_fshader2;
- m_vbo1.destroy();
- m_vbo2.destroy();
- doneCurrent();
-}
-
-void GLWidget::setScaling(int scale)
-{
- if (scale > 30)
- m_fScale = 1 + qreal(scale - 30) / 30 * 0.25;
- else if (scale < 30)
- m_fScale = 1 - (qreal(30 - scale) / 30 * 0.25);
- else
- m_fScale = 1;
-}
-
-void GLWidget::setLogo()
-{
- m_qtLogo = true;
-}
-
-void GLWidget::setTexture()
-{
- m_qtLogo = false;
-}
-
-void GLWidget::setShowBubbles(bool bubbles)
-{
- m_showBubbles = bubbles;
-}
-
-void GLWidget::paintQtLogo()
-{
- m_program1->enableAttributeArray(m_vertexAttr1);
- m_program1->enableAttributeArray(m_normalAttr1);
-
- m_vbo1.bind();
- // The data in the buffer is placed like this:
- // vertex1.x, vertex1.y, vertex1.z, normal1.x, normal1.y, normal1.z, vertex2.x, ...
- m_program1->setAttributeBuffer(m_vertexAttr1, GL_FLOAT, 0, 3, 6 * sizeof(GLfloat));
- m_program1->setAttributeBuffer(m_normalAttr1, GL_FLOAT, 3 * sizeof(GLfloat), 3, 6 * sizeof(GLfloat));
- m_vbo1.release();
-
- glDrawArrays(GL_TRIANGLES, 0, m_vertices.size());
-
- m_program1->disableAttributeArray(m_normalAttr1);
- m_program1->disableAttributeArray(m_vertexAttr1);
-}
-
-void GLWidget::paintTexturedCube()
-{
- m_texture->bind();
-
- if (!m_vbo2.isCreated()) {
- static GLfloat afVertices[] = {
- -0.5, 0.5, 0.5, 0.5,-0.5,0.5,-0.5,-0.5,0.5,
- 0.5, -0.5, 0.5, -0.5,0.5,0.5,0.5,0.5,0.5,
- -0.5, -0.5, -0.5, 0.5,-0.5,-0.5,-0.5,0.5,-0.5,
- 0.5, 0.5, -0.5, -0.5,0.5,-0.5,0.5,-0.5,-0.5,
-
- 0.5, -0.5, -0.5, 0.5,-0.5,0.5,0.5,0.5,-0.5,
- 0.5, 0.5, 0.5, 0.5,0.5,-0.5,0.5,-0.5,0.5,
- -0.5, 0.5, -0.5, -0.5,-0.5,0.5,-0.5,-0.5,-0.5,
- -0.5, -0.5, 0.5, -0.5,0.5,-0.5,-0.5,0.5,0.5,
-
- 0.5, 0.5, -0.5, -0.5, 0.5, 0.5, -0.5, 0.5, -0.5,
- -0.5, 0.5, 0.5, 0.5, 0.5, -0.5, 0.5, 0.5, 0.5,
- -0.5, -0.5, -0.5, -0.5, -0.5, 0.5, 0.5, -0.5, -0.5,
- 0.5, -0.5, 0.5, 0.5, -0.5, -0.5, -0.5, -0.5, 0.5
- };
-
- static GLfloat afTexCoord[] = {
- 0.0f,0.0f, 1.0f,1.0f, 1.0f,0.0f,
- 1.0f,1.0f, 0.0f,0.0f, 0.0f,1.0f,
- 1.0f,1.0f, 1.0f,0.0f, 0.0f,1.0f,
- 0.0f,0.0f, 0.0f,1.0f, 1.0f,0.0f,
-
- 1.0f,1.0f, 1.0f,0.0f, 0.0f,1.0f,
- 0.0f,0.0f, 0.0f,1.0f, 1.0f,0.0f,
- 0.0f,0.0f, 1.0f,1.0f, 1.0f,0.0f,
- 1.0f,1.0f, 0.0f,0.0f, 0.0f,1.0f,
-
- 0.0f,1.0f, 1.0f,0.0f, 1.0f,1.0f,
- 1.0f,0.0f, 0.0f,1.0f, 0.0f,0.0f,
- 1.0f,0.0f, 1.0f,1.0f, 0.0f,0.0f,
- 0.0f,1.0f, 0.0f,0.0f, 1.0f,1.0f
- };
-
- GLfloat afNormals[] = {
-
- 0,0,-1, 0,0,-1, 0,0,-1,
- 0,0,-1, 0,0,-1, 0,0,-1,
- 0,0,1, 0,0,1, 0,0,1,
- 0,0,1, 0,0,1, 0,0,1,
-
- -1,0,0, -1,0,0, -1,0,0,
- -1,0,0, -1,0,0, -1,0,0,
- 1,0,0, 1,0,0, 1,0,0,
- 1,0,0, 1,0,0, 1,0,0,
-
- 0,-1,0, 0,-1,0, 0,-1,0,
- 0,-1,0, 0,-1,0, 0,-1,0,
- 0,1,0, 0,1,0, 0,1,0,
- 0,1,0, 0,1,0, 0,1,0
- };
-
- m_vbo2.create();
- m_vbo2.bind();
- m_vbo2.allocate(36 * 8 * sizeof(GLfloat));
- m_vbo2.write(0, afVertices, sizeof(afVertices));
- m_vbo2.write(sizeof(afVertices), afTexCoord, sizeof(afTexCoord));
- m_vbo2.write(sizeof(afVertices) + sizeof(afTexCoord), afNormals, sizeof(afNormals));
- m_vbo2.release();
- }
-
- m_program2->setUniformValue(m_textureUniform2, 0); // use texture unit 0
-
- m_program2->enableAttributeArray(m_vertexAttr2);
- m_program2->enableAttributeArray(m_normalAttr2);
- m_program2->enableAttributeArray(m_texCoordAttr2);
-
- m_vbo2.bind();
- // In the buffer we first have 36 vertices (3 floats for each), then 36 texture
- // coordinates (2 floats for each), then 36 normals (3 floats for each).
- m_program2->setAttributeBuffer(m_vertexAttr2, GL_FLOAT, 0, 3);
- m_program2->setAttributeBuffer(m_texCoordAttr2, GL_FLOAT, 36 * 3 * sizeof(GLfloat), 2);
- m_program2->setAttributeBuffer(m_normalAttr2, GL_FLOAT, 36 * 5 * sizeof(GLfloat), 3);
- m_vbo2.release();
-
- glDrawArrays(GL_TRIANGLES, 0, 36);
-
- m_program2->disableAttributeArray(m_vertexAttr2);
- m_program2->disableAttributeArray(m_normalAttr2);
- m_program2->disableAttributeArray(m_texCoordAttr2);
-}
-
-void GLWidget::initializeGL()
-{
- initializeOpenGLFunctions();
-
- m_texture = new QOpenGLTexture(QImage(":/qt.png"));
-
- m_vshader1 = new QOpenGLShader(QOpenGLShader::Vertex);
- const char *vsrc1 =
- "attribute highp vec4 vertex;\n"
- "attribute mediump vec3 normal;\n"
- "uniform mediump mat4 matrix;\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 = vec3(0.40, 1.0, 0.0);\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";
- m_vshader1->compileSourceCode(vsrc1);
-
- m_fshader1 = new QOpenGLShader(QOpenGLShader::Fragment);
- const char *fsrc1 =
- "varying mediump vec4 color;\n"
- "void main(void)\n"
- "{\n"
- " gl_FragColor = color;\n"
- "}\n";
- m_fshader1->compileSourceCode(fsrc1);
-
- m_program1 = new QOpenGLShaderProgram;
- m_program1->addShader(m_vshader1);
- m_program1->addShader(m_fshader1);
- m_program1->link();
-
- m_vertexAttr1 = m_program1->attributeLocation("vertex");
- m_normalAttr1 = m_program1->attributeLocation("normal");
- m_matrixUniform1 = m_program1->uniformLocation("matrix");
-
- m_vshader2 = new QOpenGLShader(QOpenGLShader::Vertex);
- const char *vsrc2 =
- "attribute highp vec4 vertex;\n"
- "attribute highp vec4 texCoord;\n"
- "attribute mediump vec3 normal;\n"
- "uniform mediump mat4 matrix;\n"
- "varying highp vec4 texc;\n"
- "varying mediump float angle;\n"
- "void main(void)\n"
- "{\n"
- " vec3 toLight = normalize(vec3(0.0, 0.3, 1.0));\n"
- " angle = max(dot(normal, toLight), 0.0);\n"
- " gl_Position = matrix * vertex;\n"
- " texc = texCoord;\n"
- "}\n";
- m_vshader2->compileSourceCode(vsrc2);
-
- m_fshader2 = new QOpenGLShader(QOpenGLShader::Fragment);
- const char *fsrc2 =
- "varying highp vec4 texc;\n"
- "uniform sampler2D tex;\n"
- "varying mediump float angle;\n"
- "void main(void)\n"
- "{\n"
- " highp vec3 color = texture2D(tex, texc.st).rgb;\n"
- " color = color * 0.2 + color * 0.8 * angle;\n"
- " gl_FragColor = vec4(clamp(color, 0.0, 1.0), 1.0);\n"
- "}\n";
- m_fshader2->compileSourceCode(fsrc2);
-
- m_program2 = new QOpenGLShaderProgram;
- m_program2->addShader(m_vshader2);
- m_program2->addShader(m_fshader2);
- m_program2->link();
-
- m_vertexAttr2 = m_program2->attributeLocation("vertex");
- m_normalAttr2 = m_program2->attributeLocation("normal");
- m_texCoordAttr2 = m_program2->attributeLocation("texCoord");
- m_matrixUniform2 = m_program2->uniformLocation("matrix");
- m_textureUniform2 = m_program2->uniformLocation("tex");
-
- m_fAngle = 0;
- m_fScale = 1;
-
- createGeometry();
-
- // Use a vertex buffer object. Client-side pointers are old-school and should be avoided.
- m_vbo1.create();
- m_vbo1.bind();
- // For the cube all the data belonging to the texture coordinates and
- // normals is placed separately, after the vertices. Here, for the Qt logo,
- // let's do something different and potentially more efficient: create a
- // properly interleaved data set.
- const int vertexCount = m_vertices.count();
- QVector<GLfloat> buf;
- buf.resize(vertexCount * 3 * 2);
- GLfloat *p = buf.data();
- for (int i = 0; i < vertexCount; ++i) {
- *p++ = m_vertices[i].x();
- *p++ = m_vertices[i].y();
- *p++ = m_vertices[i].z();
- *p++ = m_normals[i].x();
- *p++ = m_normals[i].y();
- *p++ = m_normals[i].z();
- }
- m_vbo1.allocate(buf.constData(), buf.count() * sizeof(GLfloat));
- m_vbo1.release();
-
- createBubbles(bubbleNum - m_bubbles.count());
-}
-
-void GLWidget::paintGL()
-{
- createBubbles(bubbleNum - m_bubbles.count());
-
- QPainter painter;
- painter.begin(this);
-
- painter.beginNativePainting();
-
- glClearColor(m_background.redF(), m_background.greenF(), m_background.blueF(), m_transparent ? 0.0f : 1.0f);
- glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
-
- glFrontFace(GL_CW);
- glCullFace(GL_FRONT);
- glEnable(GL_CULL_FACE);
- glEnable(GL_DEPTH_TEST);
-
- QMatrix4x4 modelview;
- modelview.rotate(m_fAngle, 0.0f, 1.0f, 0.0f);
- modelview.rotate(m_fAngle, 1.0f, 0.0f, 0.0f);
- modelview.rotate(m_fAngle, 0.0f, 0.0f, 1.0f);
- modelview.scale(m_fScale);
- modelview.translate(0.0f, -0.2f, 0.0f);
-
- if (m_qtLogo) {
- m_program1->bind();
- m_program1->setUniformValue(m_matrixUniform1, modelview);
- paintQtLogo();
- m_program1->release();
- } else {
- m_program2->bind();
- m_program2->setUniformValue(m_matrixUniform2, modelview);
- paintTexturedCube();
- m_program2->release();
- }
-
- glDisable(GL_DEPTH_TEST);
- glDisable(GL_CULL_FACE);
-
- painter.endNativePainting();
-
- if (m_showBubbles) {
- for (Bubble *bubble : qAsConst(m_bubbles))
- bubble->drawBubble(&painter);
- }
-
- if (const int elapsed = m_time.elapsed()) {
- QString framesPerSecond;
- framesPerSecond.setNum(m_frames /(elapsed / 1000.0), 'f', 2);
- painter.setPen(m_transparent ? Qt::black : Qt::white);
- painter.drawText(20, 40, framesPerSecond + " paintGL calls / s");
- }
-
- painter.end();
-
- for (Bubble *bubble : qAsConst(m_bubbles))
- bubble->move(rect());
-
- if (!(m_frames % 100)) {
- m_time.start();
- m_frames = 0;
- }
- m_fAngle += 1.0f;
- ++m_frames;
-
- // When requested, follow the ideal way to animate: Rely on
- // blocking swap and just schedule updates continuously.
- if (!m_mainWindow->timerEnabled())
- update();
-}
-
-void GLWidget::createBubbles(int number)
-{
- for (int i = 0; i < number; ++i) {
- QPointF position(width()*(0.1 + QRandomGenerator::global()->bounded(0.8)),
- height()*(0.1 + QRandomGenerator::global()->bounded(0.8)));
- qreal radius = qMin(width(), height())*(0.0175 + QRandomGenerator::global()->bounded(0.0875));
- QPointF velocity(width()*0.0175*(-0.5 + QRandomGenerator::global()->bounded(1.0)),
- height()*0.0175*(-0.5 + QRandomGenerator::global()->bounded(1.0)));
-
- m_bubbles.append(new Bubble(position, radius, velocity));
- }
-}
-
-void GLWidget::createGeometry()
-{
- m_vertices.clear();
- m_normals.clear();
-
- qreal x1 = +0.06f;
- qreal y1 = -0.14f;
- qreal x2 = +0.14f;
- qreal y2 = -0.06f;
- qreal x3 = +0.08f;
- qreal y3 = +0.00f;
- qreal x4 = +0.30f;
- qreal y4 = +0.22f;
-
- quad(x1, y1, x2, y2, y2, x2, y1, x1);
- quad(x3, y3, x4, y4, y4, x4, y3, x3);
-
- extrude(x1, y1, x2, y2);
- extrude(x2, y2, y2, x2);
- extrude(y2, x2, y1, x1);
- extrude(y1, x1, x1, y1);
- extrude(x3, y3, x4, y4);
- extrude(x4, y4, y4, x4);
- extrude(y4, x4, y3, x3);
-
- const int NumSectors = 100;
- const qreal sectorAngle = 2 * qreal(M_PI) / NumSectors;
-
- for (int i = 0; i < NumSectors; ++i) {
- qreal angle = i * sectorAngle;
- qreal x5 = 0.30 * sin(angle);
- qreal y5 = 0.30 * cos(angle);
- qreal x6 = 0.20 * sin(angle);
- qreal y6 = 0.20 * cos(angle);
-
- angle += sectorAngle;
- qreal x7 = 0.20 * sin(angle);
- qreal y7 = 0.20 * cos(angle);
- qreal x8 = 0.30 * sin(angle);
- qreal y8 = 0.30 * cos(angle);
-
- quad(x5, y5, x6, y6, x7, y7, x8, y8);
-
- extrude(x6, y6, x7, y7);
- extrude(x8, y8, x5, y5);
- }
-
- for (int i = 0;i < m_vertices.size();i++)
- m_vertices[i] *= 2.0f;
-}
-
-void GLWidget::quad(qreal x1, qreal y1, qreal x2, qreal y2, qreal x3, qreal y3, qreal x4, qreal y4)
-{
- m_vertices << QVector3D(x1, y1, -0.05f);
- m_vertices << QVector3D(x2, y2, -0.05f);
- m_vertices << QVector3D(x4, y4, -0.05f);
-
- m_vertices << QVector3D(x3, y3, -0.05f);
- m_vertices << QVector3D(x4, y4, -0.05f);
- m_vertices << QVector3D(x2, y2, -0.05f);
-
- QVector3D n = QVector3D::normal
- (QVector3D(x2 - x1, y2 - y1, 0.0f), QVector3D(x4 - x1, y4 - y1, 0.0f));
-
- m_normals << n;
- m_normals << n;
- m_normals << n;
-
- m_normals << n;
- m_normals << n;
- m_normals << n;
-
- m_vertices << QVector3D(x4, y4, 0.05f);
- m_vertices << QVector3D(x2, y2, 0.05f);
- m_vertices << QVector3D(x1, y1, 0.05f);
-
- m_vertices << QVector3D(x2, y2, 0.05f);
- m_vertices << QVector3D(x4, y4, 0.05f);
- m_vertices << QVector3D(x3, y3, 0.05f);
-
- n = QVector3D::normal
- (QVector3D(x2 - x4, y2 - y4, 0.0f), QVector3D(x1 - x4, y1 - y4, 0.0f));
-
- m_normals << n;
- m_normals << n;
- m_normals << n;
-
- m_normals << n;
- m_normals << n;
- m_normals << n;
-}
-
-void GLWidget::extrude(qreal x1, qreal y1, qreal x2, qreal y2)
-{
- m_vertices << QVector3D(x1, y1, +0.05f);
- m_vertices << QVector3D(x2, y2, +0.05f);
- m_vertices << QVector3D(x1, y1, -0.05f);
-
- m_vertices << QVector3D(x2, y2, -0.05f);
- m_vertices << QVector3D(x1, y1, -0.05f);
- m_vertices << QVector3D(x2, y2, +0.05f);
-
- QVector3D n = QVector3D::normal
- (QVector3D(x2 - x1, y2 - y1, 0.0f), QVector3D(0.0f, 0.0f, -0.1f));
-
- m_normals << n;
- m_normals << n;
- m_normals << n;
-
- m_normals << n;
- m_normals << n;
- m_normals << n;
-}
-
-void GLWidget::setTransparent(bool transparent)
-{
- setAttribute(Qt::WA_AlwaysStackOnTop, transparent);
- m_transparent = transparent;
- // Call update() on the top-level window after toggling AlwayStackOnTop to make sure
- // the entire backingstore is updated accordingly.
- window()->update();
-}
-
-void GLWidget::resizeGL(int, int)
-{
- if (m_hasButton) {
- if (!m_btn) {
- m_btn = new QPushButton("A widget on top.\nPress for more widgets.", this);
- connect(m_btn, &QPushButton::clicked, this, &GLWidget::handleButtonPress);
- }
- m_btn->move(20, 80);
- }
-}
-
-void GLWidget::handleButtonPress()
-{
- m_mainWindow->addNew();
-}
diff --git a/examples/opengl/qopenglwidget/glwidget.h b/examples/opengl/qopenglwidget/glwidget.h
deleted file mode 100644
index 99288261c0..0000000000
--- a/examples/opengl/qopenglwidget/glwidget.h
+++ /dev/null
@@ -1,133 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the examples of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:BSD$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** BSD License Usage
-** Alternatively, you may use this file under the terms of the BSD license
-** as follows:
-**
-** "Redistribution and use in source and binary forms, with or without
-** modification, are permitted provided that the following conditions are
-** met:
-** * Redistributions of source code must retain the above copyright
-** notice, this list of conditions and the following disclaimer.
-** * Redistributions in binary form must reproduce the above copyright
-** notice, this list of conditions and the following disclaimer in
-** the documentation and/or other materials provided with the
-** distribution.
-** * 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.
-**
-**
-** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
-** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
-** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
-** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
-** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
-** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
-** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
-** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
-** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef GLWIDGET_H
-#define GLWIDGET_H
-
-#include <QOpenGLWidget>
-#include <QOpenGLFunctions>
-#include <QOpenGLBuffer>
-#include <QVector3D>
-#include <QMatrix4x4>
-#include <QElapsedTimer>
-#include <QVector>
-#include <QPushButton>
-
-class Bubble;
-class MainWindow;
-
-QT_FORWARD_DECLARE_CLASS(QOpenGLTexture)
-QT_FORWARD_DECLARE_CLASS(QOpenGLShader)
-QT_FORWARD_DECLARE_CLASS(QOpenGLShaderProgram)
-
-class GLWidget : public QOpenGLWidget, protected QOpenGLFunctions
-{
- Q_OBJECT
-public:
- GLWidget(MainWindow *mw, bool button, const QColor &background);
- ~GLWidget();
-
-public slots:
- void setScaling(int scale);
- void setLogo();
- void setTexture();
- void setShowBubbles(bool);
- void setTransparent(bool transparent);
-
-private slots:
- void handleButtonPress();
-
-protected:
- void resizeGL(int w, int h) override;
- void paintGL() override;
- void initializeGL() override;
-
-private:
- void paintTexturedCube();
- void paintQtLogo();
- void createGeometry();
- void createBubbles(int number);
- void quad(qreal x1, qreal y1, qreal x2, qreal y2, qreal x3, qreal y3, qreal x4, qreal y4);
- void extrude(qreal x1, qreal y1, qreal x2, qreal y2);
-
- MainWindow *m_mainWindow;
- qreal m_fAngle = 0;
- qreal m_fScale = 1;
- bool m_showBubbles = true;
- QVector<QVector3D> m_vertices;
- QVector<QVector3D> m_normals;
- bool m_qtLogo = true;
- QVector<Bubble *> m_bubbles;
- int m_frames = 0;
- QElapsedTimer m_time;
- QOpenGLShader *m_vshader1 = nullptr;
- QOpenGLShader *m_fshader1 = nullptr;
- QOpenGLShader *m_vshader2 = nullptr;
- QOpenGLShader *m_fshader2 = nullptr;
- QOpenGLShaderProgram *m_program1 = nullptr;
- QOpenGLShaderProgram *m_program2 = nullptr;
- QOpenGLTexture *m_texture = nullptr;
- QOpenGLBuffer m_vbo1;
- QOpenGLBuffer m_vbo2;
- int m_vertexAttr1 = 0;
- int m_normalAttr1 = 0;
- int m_matrixUniform1 = 0;
- int m_vertexAttr2 = 0;
- int m_normalAttr2 = 0;
- int m_texCoordAttr2 = 0;
- int m_matrixUniform2 = 0;
- int m_textureUniform2 = 0;
- bool m_transparent = false;
- QPushButton *m_btn = nullptr;
- bool m_hasButton;
- QColor m_background;
-};
-
-#endif
diff --git a/examples/opengl/qopenglwidget/main.cpp b/examples/opengl/qopenglwidget/main.cpp
deleted file mode 100644
index 42fc772445..0000000000
--- a/examples/opengl/qopenglwidget/main.cpp
+++ /dev/null
@@ -1,88 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the examples of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:BSD$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** BSD License Usage
-** Alternatively, you may use this file under the terms of the BSD license
-** as follows:
-**
-** "Redistribution and use in source and binary forms, with or without
-** modification, are permitted provided that the following conditions are
-** met:
-** * Redistributions of source code must retain the above copyright
-** notice, this list of conditions and the following disclaimer.
-** * Redistributions in binary form must reproduce the above copyright
-** notice, this list of conditions and the following disclaimer in
-** the documentation and/or other materials provided with the
-** distribution.
-** * 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.
-**
-**
-** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
-** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
-** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
-** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
-** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
-** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
-** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
-** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
-** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include <QApplication>
-#include <QMainWindow>
-#include <QSurfaceFormat>
-#include <QCommandLineParser>
-#include <QCommandLineOption>
-#include "mainwindow.h"
-
-int main( int argc, char ** argv )
-{
- Q_INIT_RESOURCE(texture);
- QApplication a( argc, argv );
-
- QCoreApplication::setApplicationName("Qt QOpenGLWidget Example");
- QCoreApplication::setOrganizationName("QtProject");
- QCoreApplication::setApplicationVersion(QT_VERSION_STR);
- QCommandLineParser parser;
- parser.setApplicationDescription(QCoreApplication::applicationName());
- parser.addHelpOption();
- parser.addVersionOption();
- QCommandLineOption multipleSampleOption("multisample", "Multisampling");
- parser.addOption(multipleSampleOption);
- QCommandLineOption srgbOption("srgb", "Use sRGB Color Space");
- parser.addOption(srgbOption);
- parser.process(a);
-
- QSurfaceFormat format;
- format.setDepthBufferSize(24);
- format.setStencilBufferSize(8);
- if (parser.isSet(srgbOption))
- format.setColorSpace(QSurfaceFormat::sRGBColorSpace);
- if (parser.isSet(multipleSampleOption))
- format.setSamples(4);
- QSurfaceFormat::setDefaultFormat(format);
-
- MainWindow mw;
- mw.showMaximized();
- return a.exec();
-}
diff --git a/examples/opengl/qopenglwidget/mainwindow.cpp b/examples/opengl/qopenglwidget/mainwindow.cpp
deleted file mode 100644
index 6fab3df79e..0000000000
--- a/examples/opengl/qopenglwidget/mainwindow.cpp
+++ /dev/null
@@ -1,187 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the examples of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:BSD$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** BSD License Usage
-** Alternatively, you may use this file under the terms of the BSD license
-** as follows:
-**
-** "Redistribution and use in source and binary forms, with or without
-** modification, are permitted provided that the following conditions are
-** met:
-** * Redistributions of source code must retain the above copyright
-** notice, this list of conditions and the following disclaimer.
-** * Redistributions in binary form must reproduce the above copyright
-** notice, this list of conditions and the following disclaimer in
-** the documentation and/or other materials provided with the
-** distribution.
-** * 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.
-**
-**
-** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
-** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
-** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
-** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
-** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
-** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
-** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
-** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
-** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include "mainwindow.h"
-
-#include <QApplication>
-#include <QMenuBar>
-#include <QGroupBox>
-#include <QSlider>
-#include <QLabel>
-#include <QCheckBox>
-#include <QRandomGenerator>
-#include <QSpinBox>
-#include <QScrollArea>
-
-#include "glwidget.h"
-
-MainWindow::MainWindow()
- : m_nextX(1), m_nextY(1)
-{
- GLWidget *glwidget = new GLWidget(this, true, qRgb(20, 20, 50));
- m_glWidgets << glwidget;
- QLabel *label = new QLabel(this);
- m_timer = new QTimer(this);
- QSlider *slider = new QSlider(this);
- slider->setOrientation(Qt::Horizontal);
-
- QLabel *updateLabel = new QLabel("Update interval");
- QSpinBox *updateInterval = new QSpinBox(this);
- updateInterval->setSuffix(" ms");
- updateInterval->setValue(10);
- updateInterval->setToolTip("Interval for the timer that calls update().\n"
- "Note that on most systems the swap will block to wait for vsync\n"
- "and therefore an interval < 16 ms will likely lead to a 60 FPS update rate.");
- QGroupBox *updateGroupBox = new QGroupBox(this);
- QCheckBox *timerBased = new QCheckBox("Use timer", this);
- timerBased->setChecked(false);
- timerBased->setToolTip("Toggles using a timer to trigger update().\n"
- "When not set, each paintGL() schedules the next update immediately,\n"
- "expecting the blocking swap to throttle the thread.\n"
- "This shows how unnecessary the timer is in most cases.");
- QCheckBox *transparent = new QCheckBox("Transparent background", this);
- transparent->setToolTip("Toggles Qt::WA_AlwaysStackOnTop and transparent clear color for glClear().\n"
- "Note how the button on top stacks incorrectly when enabling this.");
- QHBoxLayout *updateLayout = new QHBoxLayout;
- updateLayout->addWidget(updateLabel);
- updateLayout->addWidget(updateInterval);
- updateLayout->addWidget(timerBased);
- updateLayout->addWidget(transparent);
- updateGroupBox->setLayout(updateLayout);
-
- slider->setRange(0, 50);
- slider->setSliderPosition(30);
- m_timer->setInterval(10);
- label->setText("A scrollable QOpenGLWidget");
- label->setAlignment(Qt::AlignHCenter);
-
- QGroupBox * groupBox = new QGroupBox(this);
- setCentralWidget(groupBox);
- groupBox->setTitle("QOpenGLWidget Example");
-
- m_layout = new QGridLayout(groupBox);
-
- QScrollArea *scrollArea = new QScrollArea;
- scrollArea->setWidget(glwidget);
-
- m_layout->addWidget(scrollArea,1,0,8,1);
- m_layout->addWidget(label,9,0,1,1);
- m_layout->addWidget(updateGroupBox, 10, 0, 1, 1);
- m_layout->addWidget(slider, 11,0,1,1);
-
- groupBox->setLayout(m_layout);
-
-
- QMenu *fileMenu = menuBar()->addMenu("&File");
- fileMenu->addAction("E&xit", this, &QWidget::close);
- QMenu *showMenu = menuBar()->addMenu("&Show");
- showMenu->addAction("Show 3D Logo", glwidget, &GLWidget::setLogo);
- showMenu->addAction("Show 2D Texture", glwidget, &GLWidget::setTexture);
- QAction *showBubbles = showMenu->addAction("Show bubbles", glwidget, &GLWidget::setShowBubbles);
- showBubbles->setCheckable(true);
- showBubbles->setChecked(true);
- QMenu *helpMenu = menuBar()->addMenu("&Help");
- helpMenu->addAction("About Qt", qApp, &QApplication::aboutQt);
-
- connect(m_timer, &QTimer::timeout, glwidget, QOverload<>::of(&QWidget::update));
-
- connect(slider, &QAbstractSlider::valueChanged, glwidget, &GLWidget::setScaling);
- connect(transparent, &QCheckBox::toggled, glwidget, &GLWidget::setTransparent);
- connect(updateInterval, QOverload<int>::of(&QSpinBox::valueChanged),
- this, &MainWindow::updateIntervalChanged);
- connect(timerBased, &QCheckBox::toggled, this, &MainWindow::timerUsageChanged);
- connect(timerBased, &QCheckBox::toggled, updateInterval, &QWidget::setEnabled);
-
- if (timerBased->isChecked())
- m_timer->start();
- else
- updateInterval->setEnabled(false);
-}
-
-void MainWindow::updateIntervalChanged(int value)
-{
- m_timer->setInterval(value);
- if (m_timer->isActive())
- m_timer->start();
-}
-
-void MainWindow::addNew()
-{
- if (m_nextY == 4)
- return;
- GLWidget *w = new GLWidget(this, false, qRgb(QRandomGenerator::global()->bounded(256),
- QRandomGenerator::global()->bounded(256),
- QRandomGenerator::global()->bounded(256)));
- m_glWidgets << w;
- connect(m_timer, &QTimer::timeout, w, QOverload<>::of(&QWidget::update));
- m_layout->addWidget(w, m_nextY, m_nextX, 1, 1);
- if (m_nextX == 3) {
- m_nextX = 1;
- ++m_nextY;
- } else {
- ++m_nextX;
- }
-}
-
-void MainWindow::timerUsageChanged(bool enabled)
-{
- if (enabled) {
- m_timer->start();
- } else {
- m_timer->stop();
- for (QOpenGLWidget *w : qAsConst(m_glWidgets))
- w->update();
- }
-}
-
-void MainWindow::resizeEvent(QResizeEvent *)
-{
- m_glWidgets[0]->setMinimumSize(size() + QSize(128, 128));
-}
diff --git a/examples/opengl/qopenglwidget/mainwindow.h b/examples/opengl/qopenglwidget/mainwindow.h
deleted file mode 100644
index bec1a563e0..0000000000
--- a/examples/opengl/qopenglwidget/mainwindow.h
+++ /dev/null
@@ -1,83 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the examples of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:BSD$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** BSD License Usage
-** Alternatively, you may use this file under the terms of the BSD license
-** as follows:
-**
-** "Redistribution and use in source and binary forms, with or without
-** modification, are permitted provided that the following conditions are
-** met:
-** * Redistributions of source code must retain the above copyright
-** notice, this list of conditions and the following disclaimer.
-** * Redistributions in binary form must reproduce the above copyright
-** notice, this list of conditions and the following disclaimer in
-** the documentation and/or other materials provided with the
-** distribution.
-** * 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.
-**
-**
-** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
-** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
-** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
-** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
-** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
-** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
-** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
-** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
-** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef MAINWINDOW_H
-#define MAINWINDOW_H
-
-#include <QMainWindow>
-#include <QTimer>
-#include <QGridLayout>
-
-QT_FORWARD_DECLARE_CLASS(QOpenGLWidget)
-
-class MainWindow : public QMainWindow
-{
- Q_OBJECT
-
-public:
- MainWindow();
- void addNew();
- bool timerEnabled() const { return m_timer->isActive(); }
-
- void resizeEvent(QResizeEvent *);
-
-private slots:
- void updateIntervalChanged(int value);
- void timerUsageChanged(bool enabled);
-
-private:
- QTimer *m_timer;
- QGridLayout *m_layout;
- int m_nextX;
- int m_nextY;
- QVector<QOpenGLWidget *> m_glWidgets;
-};
-
-#endif
diff --git a/examples/opengl/qopenglwidget/qopenglwidget.pro b/examples/opengl/qopenglwidget/qopenglwidget.pro
deleted file mode 100644
index 1df3de1290..0000000000
--- a/examples/opengl/qopenglwidget/qopenglwidget.pro
+++ /dev/null
@@ -1,15 +0,0 @@
-QT += widgets opengl
-
-SOURCES += main.cpp \
- glwidget.cpp \
- mainwindow.cpp \
- bubble.cpp
-
-HEADERS += glwidget.h \
- mainwindow.h \
- bubble.h
-
-RESOURCES += texture.qrc
-
-target.path = $$[QT_INSTALL_EXAMPLES]/opengl/qopenglwidget
-INSTALLS += target
diff --git a/examples/opengl/qopenglwidget/qt.png b/examples/opengl/qopenglwidget/qt.png
deleted file mode 100644
index 4f68e162de..0000000000
--- a/examples/opengl/qopenglwidget/qt.png
+++ /dev/null
Binary files differ
diff --git a/examples/opengl/qopenglwidget/texture.qrc b/examples/opengl/qopenglwidget/texture.qrc
deleted file mode 100644
index ff1d0e535f..0000000000
--- a/examples/opengl/qopenglwidget/texture.qrc
+++ /dev/null
@@ -1,5 +0,0 @@
-<!DOCTYPE RCC><RCC version="1.0">
-<qresource>
- <file>qt.png</file>
-</qresource>
-</RCC>
diff --git a/examples/opengl/qopenglwindow/background.frag b/examples/opengl/qopenglwindow/background.frag
deleted file mode 100644
index 4af85aae8e..0000000000
--- a/examples/opengl/qopenglwindow/background.frag
+++ /dev/null
@@ -1,30 +0,0 @@
-#define M_PI 3.14159265358979323846
-#define SPEED 10000.0
-
-uniform int currentTime;
-uniform highp vec2 windowSize;
-
-highp float noise(highp vec2 co)
-{
- return 0.5 * fract(sin(dot(co.xy, vec2(12.9898,78.233))) * 43758.5453);
-}
-
-highp float curvSpeed()
-{
- return (mod(float(currentTime), SPEED) / SPEED) * (2.0 * M_PI);
-}
-
-highp float curv(int curvCount)
-{
- 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.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
deleted file mode 100644
index acbbe74841..0000000000
--- a/examples/opengl/qopenglwindow/background_renderer.cpp
+++ /dev/null
@@ -1,214 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the examples of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:BSD$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** BSD License Usage
-** Alternatively, you may use this file under the terms of the BSD license
-** as follows:
-**
-** "Redistribution and use in source and binary forms, with or without
-** modification, are permitted provided that the following conditions are
-** met:
-** * Redistributions of source code must retain the above copyright
-** notice, this list of conditions and the following disclaimer.
-** * Redistributions in binary form must reproduce the above copyright
-** notice, this list of conditions and the following disclaimer in
-** the documentation and/or other materials provided with the
-** distribution.
-** * 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.
-**
-**
-** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
-** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
-** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
-** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
-** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
-** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
-** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
-** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
-** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include "background_renderer.h"
-
-#include <qmath.h>
-#include <QFileInfo>
-#include <QTime>
-
-#include <QOpenGLShaderProgram>
-#include <QOpenGLContext>
-#include <QOpenGLFunctions>
-
-#include <math.h>
-
-static const char vertex_shader[] =
- "attribute highp vec3 vertexCoord;"
- "void main() {"
- " gl_Position = vec4(vertexCoord,1.0);"
- "}";
-
-static const char fragment_shader[] =
- "void main() {"
- " gl_FragColor = vec4(0.0,1.0,0.0,1.0);"
- "}";
-
-static const float vertices[] = { -1, -1, 0,
- -1, 1, 0,
- 1, -1, 0,
- 1, 1, 0 };
-
-FragmentToy::FragmentToy(const QString &fragmentSource, QObject *parent)
- : QObject(parent)
- , m_recompile_shaders(true)
-{
- if (QFile::exists(fragmentSource)) {
- QFileInfo info(fragmentSource);
- m_fragment_file_last_modified = info.lastModified();
- m_fragment_file = fragmentSource;
-#if QT_CONFIG(filesystemwatcher)
- m_watcher.addPath(info.canonicalPath());
- QObject::connect(&m_watcher, &QFileSystemWatcher::directoryChanged, this, &FragmentToy::fileChanged);
-#endif
- }
-}
-
-FragmentToy::~FragmentToy()
- = default;
-
-void FragmentToy::draw(const QSize &windowSize)
-{
- if (!m_program)
- initializeOpenGLFunctions();
-
- glDisable(GL_STENCIL_TEST);
- glDisable(GL_DEPTH_TEST);
-
- glClearColor(0, 0, 0, 1);
- glClear(GL_COLOR_BUFFER_BIT);
- if (!m_vao.isCreated())
- m_vao.create();
-
- QOpenGLVertexArrayObject::Binder binder(&m_vao);
-
- if (!m_vertex_buffer.isCreated()) {
- m_vertex_buffer.create();
- m_vertex_buffer.bind();
- m_vertex_buffer.allocate(vertices, sizeof(vertices));
- m_vertex_buffer.release();
- }
-
- if (!m_program) {
- m_program.reset(new QOpenGLShaderProgram);
- m_program->create();
- m_vertex_shader.reset(new QOpenGLShader(QOpenGLShader::Vertex));
- if (!m_vertex_shader->compileSourceCode(vertex_shader)) {
- qWarning() << "Failed to compile the vertex shader:" << m_vertex_shader->log();
- }
- if (!m_program->addShader(m_vertex_shader.get())) {
- qWarning() << "Failed to add vertex shader to program:" << m_program->log();
- }
- }
-
- if (!m_fragment_shader && m_recompile_shaders) {
- QByteArray data;
- if (m_fragment_file.size()) {
- QFile file(m_fragment_file);
- if (file.open(QIODevice::ReadOnly)) {
- data = file.readAll();
- } else {
- qWarning() << "Failed to load input file, falling back to default";
- data = QByteArray::fromRawData(fragment_shader, sizeof(fragment_shader));
- }
- } else {
- QFile qrcFile(":/background.frag");
- if (qrcFile.open(QIODevice::ReadOnly))
- data = qrcFile.readAll();
- else
- data = QByteArray::fromRawData(fragment_shader, sizeof(fragment_shader));
- }
- if (data.size()) {
- m_fragment_shader.reset(new QOpenGLShader(QOpenGLShader::Fragment));
- if (!m_fragment_shader->compileSourceCode(data)) {
- qWarning() << "Failed to compile fragment shader:" << m_fragment_shader->log();
- m_fragment_shader.reset(nullptr);
- }
- } else {
- qWarning() << "Unknown error, no fragment shader";
- }
-
- if (m_fragment_shader) {
- if (!m_program->addShader(m_fragment_shader.get())) {
- qWarning() << "Failed to add fragment shader to program:" << m_program->log();
- }
- }
- }
-
- if (m_recompile_shaders) {
- m_recompile_shaders = false;
-
- if (m_program->link()) {
- m_vertex_coord_pos = m_program->attributeLocation("vertexCoord");
- } else {
- qWarning() << "Failed to link shader program" << m_program->log();
- }
-
- }
-
- if (!m_program->isLinked())
- return;
-
- m_program->bind();
-
- m_vertex_buffer.bind();
- m_program->setAttributeBuffer("vertexCoord", GL_FLOAT, 0, 3, 0);
- m_program->enableAttributeArray("vertexCoord");
- m_vertex_buffer.release();
-
- m_program->setUniformValue("currentTime", (uint) QDateTime::currentMSecsSinceEpoch());
- m_program->setUniformValue("windowSize", windowSize);
-
- QOpenGLContext::currentContext()->functions()->glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
-
- m_program->release();
-}
-
-void FragmentToy::fileChanged(const QString &path)
-{
- Q_UNUSED(path);
- if (QFile::exists(m_fragment_file)) {
- QFileInfo fragment_source(m_fragment_file);
- if (fragment_source.lastModified() > m_fragment_file_last_modified) {
- m_fragment_file_last_modified = fragment_source.lastModified();
- m_recompile_shaders = true;
- if (m_program) {
- m_program->removeShader(m_fragment_shader.get());
- m_fragment_shader.reset(nullptr);
- }
- }
- } else {
- m_recompile_shaders = true;
- if (m_program) {
- m_program->removeShader(m_fragment_shader.get());
- m_fragment_shader.reset(nullptr);
- }
- }
-}
diff --git a/examples/opengl/qopenglwindow/background_renderer.h b/examples/opengl/qopenglwindow/background_renderer.h
deleted file mode 100644
index 0e3caf5981..0000000000
--- a/examples/opengl/qopenglwindow/background_renderer.h
+++ /dev/null
@@ -1,93 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the examples of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:BSD$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** BSD License Usage
-** Alternatively, you may use this file under the terms of the BSD license
-** as follows:
-**
-** "Redistribution and use in source and binary forms, with or without
-** modification, are permitted provided that the following conditions are
-** met:
-** * Redistributions of source code must retain the above copyright
-** notice, this list of conditions and the following disclaimer.
-** * Redistributions in binary form must reproduce the above copyright
-** notice, this list of conditions and the following disclaimer in
-** the documentation and/or other materials provided with the
-** distribution.
-** * 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.
-**
-**
-** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
-** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
-** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
-** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
-** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
-** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
-** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
-** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
-** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef FRAGMENT_TOY_H
-#define FRAGMENT_TOY_H
-
-#include <QObject>
-#include <QFile>
-#include <QDateTime>
-#if QT_CONFIG(filesystemwatcher)
-#include <QFileSystemWatcher>
-#endif
-#include <QOpenGLVertexArrayObject>
-#include <QOpenGLBuffer>
-#include <QOpenGLShaderProgram>
-#include <QOpenGLFunctions>
-
-#include <memory>
-
-class FragmentToy : public QObject, protected QOpenGLFunctions
-{
- Q_OBJECT
-public:
- explicit FragmentToy(const QString &fragmentSource, QObject *parent = nullptr);
- ~FragmentToy();
-
- void draw(const QSize &windowSize);
-
-private:
- void fileChanged(const QString &path);
- bool m_recompile_shaders;
-#if QT_CONFIG(filesystemwatcher)
- QFileSystemWatcher m_watcher;
-#endif
- QString m_fragment_file;
- QDateTime m_fragment_file_last_modified;
-
- std::unique_ptr<QOpenGLShaderProgram> m_program;
- std::unique_ptr<QOpenGLShader> m_vertex_shader;
- std::unique_ptr<QOpenGLShader> m_fragment_shader;
- QOpenGLVertexArrayObject m_vao;
- QOpenGLBuffer m_vertex_buffer;
- GLuint m_vertex_coord_pos;
-};
-
-#endif //FRAGMENT_TOY_H
diff --git a/examples/opengl/qopenglwindow/main.cpp b/examples/opengl/qopenglwindow/main.cpp
deleted file mode 100644
index 8932269ddf..0000000000
--- a/examples/opengl/qopenglwindow/main.cpp
+++ /dev/null
@@ -1,200 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the examples of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:BSD$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** BSD License Usage
-** Alternatively, you may use this file under the terms of the BSD license
-** as follows:
-**
-** "Redistribution and use in source and binary forms, with or without
-** modification, are permitted provided that the following conditions are
-** met:
-** * Redistributions of source code must retain the above copyright
-** notice, this list of conditions and the following disclaimer.
-** * Redistributions in binary form must reproduce the above copyright
-** notice, this list of conditions and the following disclaimer in
-** the documentation and/or other materials provided with the
-** distribution.
-** * 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.
-**
-**
-** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
-** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
-** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
-** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
-** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
-** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
-** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
-** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
-** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include <QOpenGLWindow>
-#include <QScreen>
-#include <QPainter>
-#include <QGuiApplication>
-#include <QMatrix4x4>
-#include <QStaticText>
-#include <QKeyEvent>
-
-#include "background_renderer.h"
-
-static QPainterPath painterPathForTriangle()
-{
- static const QPointF bottomLeft(-1.0, -1.0);
- static const QPointF top(0.0, 1.0);
- static const QPointF bottomRight(1.0, -1.0);
-
- QPainterPath path(bottomLeft);
- path.lineTo(top);
- path.lineTo(bottomRight);
- path.closeSubpath();
- return path;
-}
-
-class OpenGLWindow : public QOpenGLWindow
-{
- Q_OBJECT
-
-public:
- OpenGLWindow();
-
-protected:
- void paintGL() override;
- void resizeGL(int w, int h) override;
- void keyPressEvent(QKeyEvent *e) override;
-
-private:
- void setAnimating(bool enabled);
-
- QMatrix4x4 m_window_normalised_matrix;
- QMatrix4x4 m_window_painter_matrix;
- QMatrix4x4 m_projection;
- QMatrix4x4 m_view;
- QMatrix4x4 m_model_triangle;
- QMatrix4x4 m_model_text;
-
- FragmentToy m_fragment_toy;
- QStaticText m_text_layout;
- bool m_animate;
-};
-
-// Use NoPartialUpdate. This means that all the rendering goes directly to
-// the window surface, no additional framebuffer object stands in the
-// middle. This is fine since we will clear the entire framebuffer on each
-// paint. Under the hood this means that the behavior is equivalent to the
-// manual makeCurrent - perform OpenGL calls - swapBuffers loop that is
-// typical in pure QWindow-based applications.
-OpenGLWindow::OpenGLWindow()
- : QOpenGLWindow(QOpenGLWindow::NoPartialUpdate)
- , m_fragment_toy("./background.frag")
- , m_text_layout("The triangle and this text is rendered with QPainter")
- , m_animate(true)
-{
- setGeometry(300, 300, 500, 500);
-
- m_view.lookAt(QVector3D(3,1,1),
- QVector3D(0,0,0),
- QVector3D(0,1,0));
-
- setAnimating(m_animate);
-}
-
-void OpenGLWindow::paintGL()
-{
- m_fragment_toy.draw(size());
-
- QPainter p(this);
- p.setWorldTransform(m_window_normalised_matrix.toTransform());
-
- QMatrix4x4 mvp = m_projection * m_view * m_model_triangle;
- p.setTransform(mvp.toTransform(), true);
-
- p.fillPath(painterPathForTriangle(), QBrush(QGradient(QGradient::NightFade)));
-
- QTransform text_transform = (m_window_painter_matrix * m_view * m_model_text).toTransform();
- p.setTransform(text_transform, false);
- p.setPen(QPen(Qt::black));
- m_text_layout.prepare(text_transform);
- qreal x = - (m_text_layout.size().width() / 2);
- qreal y = 0;
- p.drawStaticText(x, y, m_text_layout);
-
- m_model_triangle.rotate(-1, 0, 1, 0);
- m_model_text.rotate(1, 0, 1, 0);
-}
-
-void OpenGLWindow::resizeGL(int w, int h)
-{
- m_window_normalised_matrix.setToIdentity();
- m_window_normalised_matrix.translate(w / 2.0, h / 2.0);
- m_window_normalised_matrix.scale(w / 2.0, -h / 2.0);
-
- m_window_painter_matrix.setToIdentity();
- m_window_painter_matrix.translate(w / 2.0, h / 2.0);
-
- m_text_layout.setTextWidth(std::max(w * 0.2, 80.0));
-
- m_projection.setToIdentity();
- m_projection.perspective(45.f, qreal(w) / qreal(h), 0.1f, 100.f);
-}
-
-void OpenGLWindow::keyPressEvent(QKeyEvent *e)
-{
- if (e->key() == Qt::Key_P) { // pause
- m_animate = !m_animate;
- setAnimating(m_animate);
- }
-}
-
-void OpenGLWindow::setAnimating(bool enabled)
-{
- if (enabled) {
- // Animate continuously, throttled by the blocking swapBuffers() call the
- // QOpenGLWindow internally executes after each paint. Once that is done
- // (frameSwapped signal is emitted), we schedule a new update. This
- // obviously assumes that the swap interval (see
- // QSurfaceFormat::setSwapInterval()) is non-zero.
- connect(this, &QOpenGLWindow::frameSwapped,
- this, QOverload<>::of(&QPaintDeviceWindow::update));
- update();
- } else {
- disconnect(this, &QOpenGLWindow::frameSwapped,
- this, QOverload<>::of(&QPaintDeviceWindow::update));
- }
-}
-
-int main(int argc, char **argv)
-{
- QGuiApplication app(argc, argv);
-
- OpenGLWindow window;
- QSurfaceFormat fmt;
- fmt.setDepthBufferSize(24);
- fmt.setStencilBufferSize(8);
- window.setFormat(fmt);
- window.show();
-
- return app.exec();
-}
-
-#include "main.moc"
diff --git a/examples/opengl/qopenglwindow/qopenglwindow.pro b/examples/opengl/qopenglwindow/qopenglwindow.pro
deleted file mode 100644
index e7073a324b..0000000000
--- a/examples/opengl/qopenglwindow/qopenglwindow.pro
+++ /dev/null
@@ -1,16 +0,0 @@
-TEMPLATE = app
-TARGET = qopenglwindow
-INCLUDEPATH += .
-QT += opengl
-
-RESOURCES += shaders.qrc
-
-SOURCES += \
- main.cpp \
- background_renderer.cpp
-
-HEADERS += \
- background_renderer.h
-
-target.path = $$[QT_INSTALL_EXAMPLES]/opengl/qopenglwindow
-INSTALLS += target
diff --git a/examples/opengl/qopenglwindow/shaders.qrc b/examples/opengl/qopenglwindow/shaders.qrc
deleted file mode 100644
index 64eefe2c70..0000000000
--- a/examples/opengl/qopenglwindow/shaders.qrc
+++ /dev/null
@@ -1,5 +0,0 @@
-<!DOCTYPE RCC><RCC version="1.0">
-<qresource>
- <file>background.frag</file>
-</qresource>
-</RCC>
diff --git a/examples/opengl/stereoqopenglwidget/CMakeLists.txt b/examples/opengl/stereoqopenglwidget/CMakeLists.txt
new file mode 100644
index 0000000000..d0fb7a0345
--- /dev/null
+++ b/examples/opengl/stereoqopenglwidget/CMakeLists.txt
@@ -0,0 +1,42 @@
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
+
+cmake_minimum_required(VERSION 3.16)
+project(stereoqopenglwidget LANGUAGES CXX)
+
+set(CMAKE_AUTOMOC ON)
+
+find_package(Qt6 REQUIRED COMPONENTS Core Gui OpenGL OpenGLWidgets Widgets)
+
+qt_add_executable(stereoqopenglwidget
+ glwidget.cpp glwidget.h
+ main.cpp
+ mainwindow.cpp mainwindow.h
+)
+
+set_target_properties(stereoqopenglwidget PROPERTIES
+ WIN32_EXECUTABLE TRUE
+ MACOSX_BUNDLE TRUE
+)
+
+target_link_libraries(stereoqopenglwidget PUBLIC
+ Qt6::Core
+ Qt6::Gui
+ Qt6::OpenGL
+ Qt6::OpenGLWidgets
+ Qt6::Widgets
+)
+
+
+install(TARGETS stereoqopenglwidget
+ BUNDLE DESTINATION .
+ RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
+ LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
+)
+
+qt_generate_deploy_app_script(
+ TARGET stereoqopenglwidget
+ OUTPUT_SCRIPT deploy_script
+ NO_UNSUPPORTED_PLATFORM_ERROR
+)
+install(SCRIPT ${deploy_script})
diff --git a/examples/opengl/stereoqopenglwidget/glwidget.cpp b/examples/opengl/stereoqopenglwidget/glwidget.cpp
new file mode 100644
index 0000000000..36a6300348
--- /dev/null
+++ b/examples/opengl/stereoqopenglwidget/glwidget.cpp
@@ -0,0 +1,277 @@
+// Copyright (C) 2022 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
+
+#include "glwidget.h"
+#include <QPainter>
+#include <QPaintEngine>
+#include <QOpenGLShaderProgram>
+#include <QOpenGLTexture>
+#include <QRandomGenerator>
+#include <QCoreApplication>
+#include <QFileDialog>
+#include <qmath.h>
+
+GLWidget::GLWidget(const QColor &background)
+ : m_background(background)
+{
+ setMinimumSize(300, 250);
+}
+
+GLWidget::~GLWidget()
+{
+ reset();
+}
+
+void GLWidget::saveImage(TargetBuffer targetBuffer)
+{
+ QImage img = grabFramebuffer(targetBuffer);
+ if (img.isNull()) {
+ qFatal("Failed to grab framebuffer");
+ }
+
+ const char *fn =
+ targetBuffer == TargetBuffer::LeftBuffer
+ ? "leftBuffer.png" : "rightBuffer.png";
+
+ QFileDialog fd(this);
+ fd.setAcceptMode(QFileDialog::AcceptSave);
+ fd.setDefaultSuffix("png");
+ fd.selectFile(fn);
+ if (fd.exec() == QDialog::Accepted)
+ img.save(fd.selectedFiles().first());
+}
+
+void GLWidget::reset()
+{
+ // And now release all OpenGL resources.
+ makeCurrent();
+ delete m_program;
+ m_program = nullptr;
+ delete m_vshader;
+ m_vshader = nullptr;
+ delete m_fshader;
+ m_fshader = nullptr;
+ m_vbo.destroy();
+ doneCurrent();
+
+ // We are done with the current QOpenGLContext, forget it. If there is a
+ // subsequent initialize(), that will then connect to the new context.
+ QObject::disconnect(m_contextWatchConnection);
+}
+void GLWidget::initializeGL()
+{
+ initializeOpenGLFunctions();
+
+ m_vshader = new QOpenGLShader(QOpenGLShader::Vertex);
+ const char *vsrc1 =
+ "attribute highp vec4 vertex;\n"
+ "attribute mediump vec3 normal;\n"
+ "uniform mediump mat4 matrix;\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 = vec3(0.40, 1.0, 0.0);\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";
+ m_vshader->compileSourceCode(vsrc1);
+
+ m_fshader = new QOpenGLShader(QOpenGLShader::Fragment);
+ const char *fsrc1 =
+ "varying mediump vec4 color;\n"
+ "void main(void)\n"
+ "{\n"
+ " gl_FragColor = color;\n"
+ "}\n";
+ m_fshader->compileSourceCode(fsrc1);
+
+ m_program = new QOpenGLShaderProgram;
+ m_program->addShader(m_vshader);
+ m_program->addShader(m_fshader);
+ m_program->link();
+
+
+ m_vertexAttr = m_program->attributeLocation("vertex");
+ m_normalAttr = m_program->attributeLocation("normal");
+ m_matrixUniform = m_program->uniformLocation("matrix");
+
+ createGeometry();
+
+ m_vbo.create();
+ m_vbo.bind();
+ const int vertexCount = m_vertices.count();
+ QList<GLfloat> buf;
+ buf.resize(vertexCount * 3 * 2);
+ GLfloat *p = buf.data();
+ for (int i = 0; i < vertexCount; ++i) {
+ *p++ = m_vertices[i].x();
+ *p++ = m_vertices[i].y();
+ *p++ = m_vertices[i].z();
+ *p++ = m_normals[i].x();
+ *p++ = m_normals[i].y();
+ *p++ = m_normals[i].z();
+ }
+ m_vbo.allocate(buf.constData(), (int)buf.count() * sizeof(GLfloat));
+ m_vbo.release();
+
+ m_contextWatchConnection = QObject::connect(context(), &QOpenGLContext::aboutToBeDestroyed, context(), [this] { reset(); });
+
+ glFrontFace(GL_CW);
+ glCullFace(GL_FRONT);
+ glEnable(GL_CULL_FACE);
+ glEnable(GL_DEPTH_TEST);
+}
+
+void GLWidget::paintGL()
+{
+ // When QSurfaceFormat::StereoBuffers is enabled, this function is called twice.
+ // Once where currentTargetBuffer() == QOpenGLWidget::LeftBuffer,
+ // and once where currentTargetBuffer() == QOpenGLWidget::RightBuffer.
+
+ glClearColor(m_background.redF(), m_background.greenF(), m_background.blueF(), 1.0f);
+
+ glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
+
+ //! [1]
+ // Slightly translate the model, so that there's a visible difference in each buffer.
+ QMatrix4x4 modelview;
+ if (currentTargetBuffer() == QOpenGLWidget::LeftBuffer)
+ modelview.translate(-0.4f, 0.0f, 0.0f);
+ else if (currentTargetBuffer() == QOpenGLWidget::RightBuffer)
+ modelview.translate(0.4f, 0.0f, 0.0f);
+ //! [1]
+
+ m_program->bind();
+ m_program->setUniformValue(m_matrixUniform, modelview);
+ m_program->enableAttributeArray(m_vertexAttr);
+ m_program->enableAttributeArray(m_normalAttr);
+
+ m_vbo.bind();
+ m_program->setAttributeBuffer(m_vertexAttr, GL_FLOAT, 0, 3, 6 * sizeof(GLfloat));
+ m_program->setAttributeBuffer(m_normalAttr, GL_FLOAT, 3 * sizeof(GLfloat), 3, 6 * sizeof(GLfloat));
+ m_vbo.release();
+
+ glDrawArrays(GL_TRIANGLES, 0, m_vertices.size());
+
+ m_program->disableAttributeArray(m_normalAttr);
+ m_program->disableAttributeArray(m_vertexAttr);
+ m_program->release();
+ update();
+}
+
+void GLWidget::createGeometry()
+{
+ m_vertices.clear();
+ m_normals.clear();
+
+ qreal x1 = +0.06f;
+ qreal y1 = -0.14f;
+ qreal x2 = +0.14f;
+ qreal y2 = -0.06f;
+ qreal x3 = +0.08f;
+ qreal y3 = +0.00f;
+ qreal x4 = +0.30f;
+ qreal y4 = +0.22f;
+
+ quad(x1, y1, x2, y2, y2, x2, y1, x1);
+ quad(x3, y3, x4, y4, y4, x4, y3, x3);
+
+ extrude(x1, y1, x2, y2);
+ extrude(x2, y2, y2, x2);
+ extrude(y2, x2, y1, x1);
+ extrude(y1, x1, x1, y1);
+ extrude(x3, y3, x4, y4);
+ extrude(x4, y4, y4, x4);
+ extrude(y4, x4, y3, x3);
+
+ const int NumSectors = 100;
+ const qreal sectorAngle = 2 * qreal(M_PI) / NumSectors;
+
+ for (int i = 0; i < NumSectors; ++i) {
+ qreal angle = i * sectorAngle;
+ qreal x5 = 0.30 * sin(angle);
+ qreal y5 = 0.30 * cos(angle);
+ qreal x6 = 0.20 * sin(angle);
+ qreal y6 = 0.20 * cos(angle);
+
+ angle += sectorAngle;
+ qreal x7 = 0.20 * sin(angle);
+ qreal y7 = 0.20 * cos(angle);
+ qreal x8 = 0.30 * sin(angle);
+ qreal y8 = 0.30 * cos(angle);
+
+ quad(x5, y5, x6, y6, x7, y7, x8, y8);
+
+ extrude(x6, y6, x7, y7);
+ extrude(x8, y8, x5, y5);
+ }
+
+ for (int i = 0;i < m_vertices.size();i++)
+ m_vertices[i] *= 2.0f;
+}
+
+void GLWidget::quad(qreal x1, qreal y1, qreal x2, qreal y2, qreal x3, qreal y3, qreal x4, qreal y4)
+{
+ m_vertices << QVector3D(x1, y1, -0.05f);
+ m_vertices << QVector3D(x2, y2, -0.05f);
+ m_vertices << QVector3D(x4, y4, -0.05f);
+
+ m_vertices << QVector3D(x3, y3, -0.05f);
+ m_vertices << QVector3D(x4, y4, -0.05f);
+ m_vertices << QVector3D(x2, y2, -0.05f);
+
+ QVector3D n = QVector3D::normal
+ (QVector3D(x2 - x1, y2 - y1, 0.0f), QVector3D(x4 - x1, y4 - y1, 0.0f));
+
+ m_normals << n;
+ m_normals << n;
+ m_normals << n;
+
+ m_normals << n;
+ m_normals << n;
+ m_normals << n;
+
+ m_vertices << QVector3D(x4, y4, 0.05f);
+ m_vertices << QVector3D(x2, y2, 0.05f);
+ m_vertices << QVector3D(x1, y1, 0.05f);
+
+ m_vertices << QVector3D(x2, y2, 0.05f);
+ m_vertices << QVector3D(x4, y4, 0.05f);
+ m_vertices << QVector3D(x3, y3, 0.05f);
+
+ n = QVector3D::normal
+ (QVector3D(x2 - x4, y2 - y4, 0.0f), QVector3D(x1 - x4, y1 - y4, 0.0f));
+
+ m_normals << n;
+ m_normals << n;
+ m_normals << n;
+
+ m_normals << n;
+ m_normals << n;
+ m_normals << n;
+}
+
+void GLWidget::extrude(qreal x1, qreal y1, qreal x2, qreal y2)
+{
+ m_vertices << QVector3D(x1, y1, +0.05f);
+ m_vertices << QVector3D(x2, y2, +0.05f);
+ m_vertices << QVector3D(x1, y1, -0.05f);
+
+ m_vertices << QVector3D(x2, y2, -0.05f);
+ m_vertices << QVector3D(x1, y1, -0.05f);
+ m_vertices << QVector3D(x2, y2, +0.05f);
+
+ QVector3D n = QVector3D::normal
+ (QVector3D(x2 - x1, y2 - y1, 0.0f), QVector3D(0.0f, 0.0f, -0.1f));
+
+ m_normals << n;
+ m_normals << n;
+ m_normals << n;
+
+ m_normals << n;
+ m_normals << n;
+ m_normals << n;
+}
diff --git a/examples/opengl/stereoqopenglwidget/glwidget.h b/examples/opengl/stereoqopenglwidget/glwidget.h
new file mode 100644
index 0000000000..0014ee37c1
--- /dev/null
+++ b/examples/opengl/stereoqopenglwidget/glwidget.h
@@ -0,0 +1,53 @@
+// Copyright (C) 2022 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
+
+#ifndef GLWIDGET_H
+#define GLWIDGET_H
+
+#include <QOpenGLWidget>
+#include <QOpenGLFunctions>
+#include <QOpenGLBuffer>
+#include <QVector3D>
+#include <QMatrix4x4>
+#include <QElapsedTimer>
+#include <QList>
+#include <QPushButton>
+
+
+QT_FORWARD_DECLARE_CLASS(QOpenGLTexture)
+QT_FORWARD_DECLARE_CLASS(QOpenGLShader)
+QT_FORWARD_DECLARE_CLASS(QOpenGLShaderProgram)
+
+class GLWidget : public QOpenGLWidget, protected QOpenGLFunctions
+{
+ Q_OBJECT
+public:
+ GLWidget(const QColor &background);
+ ~GLWidget();
+
+ void saveImage(QOpenGLWidget::TargetBuffer targetBuffer);
+
+protected:
+ void paintGL() override;
+ void initializeGL() override;
+
+private:
+ void createGeometry();
+ void quad(qreal x1, qreal y1, qreal x2, qreal y2, qreal x3, qreal y3, qreal x4, qreal y4);
+ void extrude(qreal x1, qreal y1, qreal x2, qreal y2);
+ void reset();
+
+ QList<QVector3D> m_vertices;
+ QList<QVector3D> m_normals;
+ QOpenGLShader *m_vshader = nullptr;
+ QOpenGLShader *m_fshader = nullptr;
+ QOpenGLShaderProgram *m_program = nullptr;
+ QOpenGLBuffer m_vbo;
+ int m_vertexAttr;
+ int m_normalAttr;
+ int m_matrixUniform;
+ QColor m_background;
+ QMetaObject::Connection m_contextWatchConnection;
+};
+
+#endif
diff --git a/examples/opengl/stereoqopenglwidget/main.cpp b/examples/opengl/stereoqopenglwidget/main.cpp
new file mode 100644
index 0000000000..8aad756eca
--- /dev/null
+++ b/examples/opengl/stereoqopenglwidget/main.cpp
@@ -0,0 +1,31 @@
+// Copyright (C) 2022 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
+
+#include <QApplication>
+#include <QSurfaceFormat>
+#include "mainwindow.h"
+
+int main( int argc, char ** argv )
+{
+ QApplication a( argc, argv );
+
+ QCoreApplication::setApplicationName("Qt QOpenGLWidget Stereoscopic Rendering Example");
+ QCoreApplication::setOrganizationName("QtProject");
+ QCoreApplication::setApplicationVersion(QT_VERSION_STR);
+
+ //! [1]
+ QSurfaceFormat format;
+ format.setDepthBufferSize(24);
+ format.setStencilBufferSize(8);
+
+ // Enable stereoscopic rendering support
+ format.setStereo(true);
+
+ QSurfaceFormat::setDefaultFormat(format);
+ //! [1]
+
+ MainWindow mw;
+ mw.resize(1280, 720);
+ mw.show();
+ return a.exec();
+}
diff --git a/examples/opengl/stereoqopenglwidget/mainwindow.cpp b/examples/opengl/stereoqopenglwidget/mainwindow.cpp
new file mode 100644
index 0000000000..33f93ba7de
--- /dev/null
+++ b/examples/opengl/stereoqopenglwidget/mainwindow.cpp
@@ -0,0 +1,25 @@
+// Copyright (C) 2022 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
+
+#include "mainwindow.h"
+#include <QApplication>
+#include <QMenuBar>
+#include "glwidget.h"
+
+MainWindow::MainWindow()
+{
+ GLWidget *glwidget = new GLWidget(qRgb(20, 20, 50));
+ setCentralWidget(glwidget);
+
+ QMenu *screenShotMenu = menuBar()->addMenu("&Screenshot");
+ screenShotMenu->addAction("Left buffer", this, [glwidget](){
+ glwidget->saveImage(QOpenGLWidget::LeftBuffer);
+ });
+
+ screenShotMenu->addAction("Right buffer", this, [glwidget](){
+ glwidget->saveImage(QOpenGLWidget::RightBuffer);
+ });
+
+ QMenu *helpMenu = menuBar()->addMenu("&Help");
+ helpMenu->addAction("About Qt", qApp, &QApplication::aboutQt);
+}
diff --git a/examples/opengl/stereoqopenglwidget/mainwindow.h b/examples/opengl/stereoqopenglwidget/mainwindow.h
new file mode 100644
index 0000000000..aa6f722e59
--- /dev/null
+++ b/examples/opengl/stereoqopenglwidget/mainwindow.h
@@ -0,0 +1,21 @@
+// Copyright (C) 2022 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
+
+#ifndef MAINWINDOW_H
+#define MAINWINDOW_H
+
+#include <QMainWindow>
+#include <QTimer>
+#include <QGridLayout>
+
+QT_FORWARD_DECLARE_CLASS(QOpenGLWidget)
+
+class MainWindow : public QMainWindow
+{
+ Q_OBJECT
+
+public:
+ MainWindow();
+};
+
+#endif
diff --git a/examples/opengl/threadedqopenglwidget/threadedqopenglwidget.pro b/examples/opengl/stereoqopenglwidget/stereoqopenglwidget.pro
index 70694459b2..197afff571 100644
--- a/examples/opengl/threadedqopenglwidget/threadedqopenglwidget.pro
+++ b/examples/opengl/stereoqopenglwidget/stereoqopenglwidget.pro
@@ -1,4 +1,4 @@
-QT += widgets opengl
+QT += widgets opengl openglwidgets
SOURCES += main.cpp \
glwidget.cpp \
@@ -7,5 +7,5 @@ SOURCES += main.cpp \
HEADERS += glwidget.h \
mainwindow.h
-target.path = $$[QT_INSTALL_EXAMPLES]/opengl/threadedqopenglwidget
+target.path = $$[QT_INSTALL_EXAMPLES]/opengl/stereoqopenglwidget
INSTALLS += target
diff --git a/examples/opengl/textures/CMakeLists.txt b/examples/opengl/textures/CMakeLists.txt
new file mode 100644
index 0000000000..2765355c5a
--- /dev/null
+++ b/examples/opengl/textures/CMakeLists.txt
@@ -0,0 +1,58 @@
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
+
+cmake_minimum_required(VERSION 3.16)
+project(textures LANGUAGES CXX)
+
+find_package(Qt6 REQUIRED COMPONENTS Core Gui OpenGL OpenGLWidgets Widgets)
+
+qt_standard_project_setup()
+
+qt_add_executable(textures
+ glwidget.cpp glwidget.h
+ main.cpp
+ window.cpp window.h
+)
+
+set_target_properties(textures PROPERTIES
+ WIN32_EXECUTABLE TRUE
+ MACOSX_BUNDLE TRUE
+)
+
+target_link_libraries(textures PRIVATE
+ Qt6::Core
+ Qt6::Gui
+ Qt6::OpenGL
+ Qt6::OpenGLWidgets
+ Qt6::Widgets
+)
+
+# Resources:
+set(textures_resource_files
+ "images/side1.png"
+ "images/side2.png"
+ "images/side3.png"
+ "images/side4.png"
+ "images/side5.png"
+ "images/side6.png"
+)
+
+qt6_add_resources(textures "textures"
+ PREFIX
+ "/"
+ FILES
+ ${textures_resource_files}
+)
+
+install(TARGETS textures
+ BUNDLE DESTINATION .
+ RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
+ LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
+)
+
+qt_generate_deploy_app_script(
+ TARGET textures
+ OUTPUT_SCRIPT deploy_script
+ NO_UNSUPPORTED_PLATFORM_ERROR
+)
+install(SCRIPT ${deploy_script})
diff --git a/examples/opengl/textures/glwidget.cpp b/examples/opengl/textures/glwidget.cpp
index 307190f308..cca08f4c91 100644
--- a/examples/opengl/textures/glwidget.cpp
+++ b/examples/opengl/textures/glwidget.cpp
@@ -1,52 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the examples of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:BSD$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** BSD License Usage
-** Alternatively, you may use this file under the terms of the BSD license
-** as follows:
-**
-** "Redistribution and use in source and binary forms, with or without
-** modification, are permitted provided that the following conditions are
-** met:
-** * Redistributions of source code must retain the above copyright
-** notice, this list of conditions and the following disclaimer.
-** * Redistributions in binary form must reproduce the above copyright
-** notice, this list of conditions and the following disclaimer in
-** the documentation and/or other materials provided with the
-** distribution.
-** * 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.
-**
-**
-** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
-** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
-** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
-** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
-** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
-** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
-** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
-** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
-** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
#include "glwidget.h"
#include <QOpenGLShaderProgram>
@@ -93,9 +46,6 @@ void GLWidget::initializeGL()
makeObject();
- glEnable(GL_DEPTH_TEST);
- glEnable(GL_CULL_FACE);
-
#define PROGRAM_VERTEX_ATTRIBUTE 0
#define PROGRAM_TEXCOORD_ATTRIBUTE 1
@@ -138,6 +88,9 @@ void GLWidget::paintGL()
glClearColor(clearColor.redF(), clearColor.greenF(), clearColor.blueF(), clearColor.alphaF());
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
+ glEnable(GL_DEPTH_TEST);
+ glEnable(GL_CULL_FACE);
+
QMatrix4x4 m;
m.ortho(-0.5f, +0.5f, +0.5f, -0.5f, 4.0f, 15.0f);
m.translate(0.0f, 0.0f, -10.0f);
@@ -145,6 +98,8 @@ void GLWidget::paintGL()
m.rotate(yRot / 16.0f, 0.0f, 1.0f, 0.0f);
m.rotate(zRot / 16.0f, 0.0f, 0.0f, 1.0f);
+ vbo.bind();
+ program->bind();
program->setUniformValue("matrix", m);
program->enableAttributeArray(PROGRAM_VERTEX_ATTRIBUTE);
program->enableAttributeArray(PROGRAM_TEXCOORD_ATTRIBUTE);
@@ -164,20 +119,20 @@ void GLWidget::resizeGL(int width, int height)
void GLWidget::mousePressEvent(QMouseEvent *event)
{
- lastPos = event->pos();
+ lastPos = event->position().toPoint();
}
void GLWidget::mouseMoveEvent(QMouseEvent *event)
{
- int dx = event->x() - lastPos.x();
- int dy = event->y() - lastPos.y();
+ int dx = event->position().toPoint().x() - lastPos.x();
+ int dy = event->position().toPoint().y() - lastPos.y();
if (event->buttons() & Qt::LeftButton) {
rotateBy(8 * dy, 8 * dx, 0);
} else if (event->buttons() & Qt::RightButton) {
rotateBy(8 * dy, 0, 8 * dx);
}
- lastPos = event->pos();
+ lastPos = event->position().toPoint();
}
void GLWidget::mouseReleaseEvent(QMouseEvent * /* event */)
@@ -199,7 +154,7 @@ void GLWidget::makeObject()
for (int j = 0; j < 6; ++j)
textures[j] = new QOpenGLTexture(QImage(QString(":/images/side%1.png").arg(j + 1)).mirrored());
- QVector<GLfloat> vertData;
+ QList<GLfloat> vertData;
for (int i = 0; i < 6; ++i) {
for (int j = 0; j < 4; ++j) {
// vertex position
diff --git a/examples/opengl/textures/glwidget.h b/examples/opengl/textures/glwidget.h
index 585d44dbfe..ff81f9faae 100644
--- a/examples/opengl/textures/glwidget.h
+++ b/examples/opengl/textures/glwidget.h
@@ -1,52 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the examples of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:BSD$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** BSD License Usage
-** Alternatively, you may use this file under the terms of the BSD license
-** as follows:
-**
-** "Redistribution and use in source and binary forms, with or without
-** modification, are permitted provided that the following conditions are
-** met:
-** * Redistributions of source code must retain the above copyright
-** notice, this list of conditions and the following disclaimer.
-** * Redistributions in binary form must reproduce the above copyright
-** notice, this list of conditions and the following disclaimer in
-** the documentation and/or other materials provided with the
-** distribution.
-** * 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.
-**
-**
-** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
-** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
-** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
-** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
-** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
-** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
-** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
-** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
-** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
#ifndef GLWIDGET_H
#define GLWIDGET_H
diff --git a/examples/opengl/textures/main.cpp b/examples/opengl/textures/main.cpp
index ad611e7016..7e5f0646cb 100644
--- a/examples/opengl/textures/main.cpp
+++ b/examples/opengl/textures/main.cpp
@@ -1,52 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the examples of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:BSD$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** BSD License Usage
-** Alternatively, you may use this file under the terms of the BSD license
-** as follows:
-**
-** "Redistribution and use in source and binary forms, with or without
-** modification, are permitted provided that the following conditions are
-** met:
-** * Redistributions of source code must retain the above copyright
-** notice, this list of conditions and the following disclaimer.
-** * Redistributions in binary form must reproduce the above copyright
-** notice, this list of conditions and the following disclaimer in
-** the documentation and/or other materials provided with the
-** distribution.
-** * 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.
-**
-**
-** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
-** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
-** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
-** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
-** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
-** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
-** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
-** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
-** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
#include <QApplication>
#include <QSurfaceFormat>
@@ -55,8 +8,6 @@
int main(int argc, char *argv[])
{
- Q_INIT_RESOURCE(textures);
-
QApplication app(argc, argv);
QSurfaceFormat format;
diff --git a/examples/opengl/textures/textures.pro b/examples/opengl/textures/textures.pro
index ae1ae4d34c..d2a6506cb8 100644
--- a/examples/opengl/textures/textures.pro
+++ b/examples/opengl/textures/textures.pro
@@ -6,7 +6,7 @@ SOURCES = glwidget.cpp \
RESOURCES = textures.qrc
-QT += widgets opengl
+QT += widgets opengl openglwidgets
# install
target.path = $$[QT_INSTALL_EXAMPLES]/opengl/textures
diff --git a/examples/opengl/textures/window.cpp b/examples/opengl/textures/window.cpp
index 642435c333..c86fa089d5 100644
--- a/examples/opengl/textures/window.cpp
+++ b/examples/opengl/textures/window.cpp
@@ -1,52 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the examples of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:BSD$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** BSD License Usage
-** Alternatively, you may use this file under the terms of the BSD license
-** as follows:
-**
-** "Redistribution and use in source and binary forms, with or without
-** modification, are permitted provided that the following conditions are
-** met:
-** * Redistributions of source code must retain the above copyright
-** notice, this list of conditions and the following disclaimer.
-** * Redistributions in binary form must reproduce the above copyright
-** notice, this list of conditions and the following disclaimer in
-** the documentation and/or other materials provided with the
-** distribution.
-** * 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.
-**
-**
-** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
-** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
-** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
-** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
-** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
-** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
-** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
-** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
-** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
#include <QtWidgets>
diff --git a/examples/opengl/textures/window.h b/examples/opengl/textures/window.h
index 19b114b798..ad9b01e704 100644
--- a/examples/opengl/textures/window.h
+++ b/examples/opengl/textures/window.h
@@ -1,52 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the examples of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:BSD$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** BSD License Usage
-** Alternatively, you may use this file under the terms of the BSD license
-** as follows:
-**
-** "Redistribution and use in source and binary forms, with or without
-** modification, are permitted provided that the following conditions are
-** met:
-** * Redistributions of source code must retain the above copyright
-** notice, this list of conditions and the following disclaimer.
-** * Redistributions in binary form must reproduce the above copyright
-** notice, this list of conditions and the following disclaimer in
-** the documentation and/or other materials provided with the
-** distribution.
-** * 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.
-**
-**
-** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
-** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
-** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
-** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
-** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
-** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
-** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
-** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
-** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
#ifndef WINDOW_H
#define WINDOW_H
diff --git a/examples/opengl/threadedqopenglwidget/glwidget.cpp b/examples/opengl/threadedqopenglwidget/glwidget.cpp
deleted file mode 100644
index 2101575fd4..0000000000
--- a/examples/opengl/threadedqopenglwidget/glwidget.cpp
+++ /dev/null
@@ -1,367 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the examples of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:BSD$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** BSD License Usage
-** Alternatively, you may use this file under the terms of the BSD license
-** as follows:
-**
-** "Redistribution and use in source and binary forms, with or without
-** modification, are permitted provided that the following conditions are
-** met:
-** * Redistributions of source code must retain the above copyright
-** notice, this list of conditions and the following disclaimer.
-** * Redistributions in binary form must reproduce the above copyright
-** notice, this list of conditions and the following disclaimer in
-** the documentation and/or other materials provided with the
-** distribution.
-** * 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.
-**
-**
-** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
-** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
-** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
-** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
-** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
-** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
-** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
-** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
-** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include "glwidget.h"
-#include <qmath.h>
-#include <QGuiApplication>
-
-GLWidget::GLWidget(QWidget *parent)
- : QOpenGLWidget(parent)
-{
- setMinimumSize(300, 250);
-
- connect(this, &QOpenGLWidget::aboutToCompose, this, &GLWidget::onAboutToCompose);
- connect(this, &QOpenGLWidget::frameSwapped, this, &GLWidget::onFrameSwapped);
- connect(this, &QOpenGLWidget::aboutToResize, this, &GLWidget::onAboutToResize);
- connect(this, &QOpenGLWidget::resized, this, &GLWidget::onResized);
-
- m_thread = new QThread;
- m_renderer = new Renderer(this);
- m_renderer->moveToThread(m_thread);
- connect(m_thread, &QThread::finished, m_renderer, &QObject::deleteLater);
-
- connect(this, &GLWidget::renderRequested, m_renderer, &Renderer::render);
- connect(m_renderer, &Renderer::contextWanted, this, &GLWidget::grabContext);
-
- m_thread->start();
-}
-
-GLWidget::~GLWidget()
-{
- m_renderer->prepareExit();
- m_thread->quit();
- m_thread->wait();
- delete m_thread;
-}
-
-void GLWidget::onAboutToCompose()
-{
- // We are on the gui thread here. Composition is about to
- // begin. Wait until the render thread finishes.
- m_renderer->lockRenderer();
-}
-
-void GLWidget::onFrameSwapped()
-{
- m_renderer->unlockRenderer();
- // Assuming a blocking swap, our animation is driven purely by the
- // vsync in this example.
- emit renderRequested();
-}
-
-void GLWidget::onAboutToResize()
-{
- m_renderer->lockRenderer();
-}
-
-void GLWidget::onResized()
-{
- m_renderer->unlockRenderer();
-}
-
-void GLWidget::grabContext()
-{
- m_renderer->lockRenderer();
- QMutexLocker lock(m_renderer->grabMutex());
- context()->moveToThread(m_thread);
- m_renderer->grabCond()->wakeAll();
- m_renderer->unlockRenderer();
-}
-
-Renderer::Renderer(GLWidget *w) : m_glwidget(w) {}
-
-void Renderer::paintQtLogo()
-{
- vbo.bind();
- program.setAttributeBuffer(vertexAttr, GL_FLOAT, 0, 3);
- program.setAttributeBuffer(normalAttr, GL_FLOAT, vertices.count() * 3 * sizeof(GLfloat), 3);
- vbo.release();
-
- program.enableAttributeArray(vertexAttr);
- program.enableAttributeArray(normalAttr);
-
- glDrawArrays(GL_TRIANGLES, 0, vertices.size());
-
- program.disableAttributeArray(normalAttr);
- program.disableAttributeArray(vertexAttr);
-}
-
-// Some OpenGL implementations have serious issues with compiling and linking
-// shaders on multiple threads concurrently. Avoid this.
-Q_GLOBAL_STATIC(QMutex, initMutex)
-
-void Renderer::render()
-{
- if (m_exiting)
- return;
-
- QOpenGLContext *ctx = m_glwidget->context();
- if (!ctx) // QOpenGLWidget not yet initialized
- return;
-
- // Grab the context.
- m_grabMutex.lock();
- emit contextWanted();
- m_grabCond.wait(&m_grabMutex);
- QMutexLocker lock(&m_renderMutex);
- m_grabMutex.unlock();
-
- if (m_exiting)
- return;
-
- Q_ASSERT(ctx->thread() == QThread::currentThread());
-
- // Make the context (and an offscreen surface) current for this thread. The
- // QOpenGLWidget's fbo is bound in the context.
- m_glwidget->makeCurrent();
-
- if (!m_inited) {
- m_inited = true;
- initializeOpenGLFunctions();
-
- QMutexLocker initLock(initMutex());
- 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"
- "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 = vec3(0.40, 1.0, 0.0);\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);
-
- 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);
-
- program.addShader(vshader);
- program.addShader(fshader);
- program.link();
-
- vertexAttr = program.attributeLocation("vertex");
- normalAttr = program.attributeLocation("normal");
- matrixUniform = program.uniformLocation("matrix");
-
- m_fAngle = 0;
- m_fScale = 1;
- createGeometry();
-
- vbo.create();
- vbo.bind();
- const int verticesSize = vertices.count() * 3 * sizeof(GLfloat);
- vbo.allocate(verticesSize * 2);
- vbo.write(0, vertices.constData(), verticesSize);
- vbo.write(verticesSize, normals.constData(), verticesSize);
-
- m_elapsed.start();
- }
-
- //qDebug("%p elapsed %lld", QThread::currentThread(), m_elapsed.restart());
-
- glClearColor(0.1f, 0.2f, 0.2f, 1.0f);
- glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
-
- glFrontFace(GL_CW);
- glCullFace(GL_FRONT);
- glEnable(GL_CULL_FACE);
- glEnable(GL_DEPTH_TEST);
-
- QMatrix4x4 modelview;
- modelview.rotate(m_fAngle, 0.0f, 1.0f, 0.0f);
- modelview.rotate(m_fAngle, 1.0f, 0.0f, 0.0f);
- modelview.rotate(m_fAngle, 0.0f, 0.0f, 1.0f);
- modelview.scale(m_fScale);
- modelview.translate(0.0f, -0.2f, 0.0f);
-
- program.bind();
- program.setUniformValue(matrixUniform, modelview);
- paintQtLogo();
- program.release();
-
- glDisable(GL_DEPTH_TEST);
- glDisable(GL_CULL_FACE);
-
- m_fAngle += 1.0f;
-
- // Make no context current on this thread and move the QOpenGLWidget's
- // context back to the gui thread.
- m_glwidget->doneCurrent();
- ctx->moveToThread(qGuiApp->thread());
-
- // Schedule composition. Note that this will use QueuedConnection, meaning
- // that update() will be invoked on the gui thread.
- QMetaObject::invokeMethod(m_glwidget, "update");
-}
-
-void Renderer::createGeometry()
-{
- vertices.clear();
- normals.clear();
-
- qreal x1 = +0.06f;
- qreal y1 = -0.14f;
- qreal x2 = +0.14f;
- qreal y2 = -0.06f;
- qreal x3 = +0.08f;
- qreal y3 = +0.00f;
- qreal x4 = +0.30f;
- qreal y4 = +0.22f;
-
- quad(x1, y1, x2, y2, y2, x2, y1, x1);
- quad(x3, y3, x4, y4, y4, x4, y3, x3);
-
- extrude(x1, y1, x2, y2);
- extrude(x2, y2, y2, x2);
- extrude(y2, x2, y1, x1);
- extrude(y1, x1, x1, y1);
- extrude(x3, y3, x4, y4);
- extrude(x4, y4, y4, x4);
- extrude(y4, x4, y3, x3);
-
- const int NumSectors = 100;
- const qreal sectorAngle = 2 * qreal(M_PI) / NumSectors;
-
- for (int i = 0; i < NumSectors; ++i) {
- qreal angle = i * sectorAngle;
- qreal x5 = 0.30 * sin(angle);
- qreal y5 = 0.30 * cos(angle);
- qreal x6 = 0.20 * sin(angle);
- qreal y6 = 0.20 * cos(angle);
-
- angle += sectorAngle;
- qreal x7 = 0.20 * sin(angle);
- qreal y7 = 0.20 * cos(angle);
- qreal x8 = 0.30 * sin(angle);
- qreal y8 = 0.30 * cos(angle);
-
- quad(x5, y5, x6, y6, x7, y7, x8, y8);
-
- extrude(x6, y6, x7, y7);
- extrude(x8, y8, x5, y5);
- }
-
- for (int i = 0;i < vertices.size();i++)
- vertices[i] *= 2.0f;
-}
-
-void Renderer::quad(qreal x1, qreal y1, qreal x2, qreal y2, qreal x3, qreal y3, qreal x4, qreal y4)
-{
- vertices << QVector3D(x1, y1, -0.05f);
- vertices << QVector3D(x2, y2, -0.05f);
- vertices << QVector3D(x4, y4, -0.05f);
-
- vertices << QVector3D(x3, y3, -0.05f);
- vertices << QVector3D(x4, y4, -0.05f);
- vertices << QVector3D(x2, y2, -0.05f);
-
- QVector3D n = QVector3D::normal
- (QVector3D(x2 - x1, y2 - y1, 0.0f), QVector3D(x4 - x1, y4 - y1, 0.0f));
-
- normals << n;
- normals << n;
- normals << n;
-
- normals << n;
- normals << n;
- normals << n;
-
- vertices << QVector3D(x4, y4, 0.05f);
- vertices << QVector3D(x2, y2, 0.05f);
- vertices << QVector3D(x1, y1, 0.05f);
-
- vertices << QVector3D(x2, y2, 0.05f);
- vertices << QVector3D(x4, y4, 0.05f);
- vertices << QVector3D(x3, y3, 0.05f);
-
- n = QVector3D::normal
- (QVector3D(x2 - x4, y2 - y4, 0.0f), QVector3D(x1 - x4, y1 - y4, 0.0f));
-
- normals << n;
- normals << n;
- normals << n;
-
- normals << n;
- normals << n;
- normals << n;
-}
-
-void Renderer::extrude(qreal x1, qreal y1, qreal x2, qreal y2)
-{
- vertices << QVector3D(x1, y1, +0.05f);
- vertices << QVector3D(x2, y2, +0.05f);
- vertices << QVector3D(x1, y1, -0.05f);
-
- vertices << QVector3D(x2, y2, -0.05f);
- vertices << QVector3D(x1, y1, -0.05f);
- vertices << QVector3D(x2, y2, +0.05f);
-
- QVector3D n = QVector3D::normal
- (QVector3D(x2 - x1, y2 - y1, 0.0f), QVector3D(0.0f, 0.0f, -0.1f));
-
- normals << n;
- normals << n;
- normals << n;
-
- normals << n;
- normals << n;
- normals << n;
-}
diff --git a/examples/opengl/threadedqopenglwidget/glwidget.h b/examples/opengl/threadedqopenglwidget/glwidget.h
deleted file mode 100644
index 8dc84dd0b1..0000000000
--- a/examples/opengl/threadedqopenglwidget/glwidget.h
+++ /dev/null
@@ -1,136 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the examples of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:BSD$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** BSD License Usage
-** Alternatively, you may use this file under the terms of the BSD license
-** as follows:
-**
-** "Redistribution and use in source and binary forms, with or without
-** modification, are permitted provided that the following conditions are
-** met:
-** * Redistributions of source code must retain the above copyright
-** notice, this list of conditions and the following disclaimer.
-** * Redistributions in binary form must reproduce the above copyright
-** notice, this list of conditions and the following disclaimer in
-** the documentation and/or other materials provided with the
-** distribution.
-** * 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.
-**
-**
-** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
-** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
-** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
-** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
-** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
-** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
-** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
-** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
-** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef GLWIDGET_H
-#define GLWIDGET_H
-
-#include <QOpenGLWidget>
-#include <QOpenGLFunctions>
-#include <QOpenGLShaderProgram>
-#include <QOpenGLBuffer>
-#include <QVector3D>
-#include <QMatrix4x4>
-#include <QThread>
-#include <QMutex>
-#include <QWaitCondition>
-#include <QElapsedTimer>
-
-class GLWidget;
-
-class Renderer : public QObject, protected QOpenGLFunctions
-{
- Q_OBJECT
-
-public:
- Renderer(GLWidget *w);
- void lockRenderer() { m_renderMutex.lock(); }
- void unlockRenderer() { m_renderMutex.unlock(); }
- QMutex *grabMutex() { return &m_grabMutex; }
- QWaitCondition *grabCond() { return &m_grabCond; }
- void prepareExit() { m_exiting = true; m_grabCond.wakeAll(); }
-
-signals:
- void contextWanted();
-
-public slots:
- void render();
-
-private:
- void paintQtLogo();
- void createGeometry();
- void quad(qreal x1, qreal y1, qreal x2, qreal y2, qreal x3, qreal y3, qreal x4, qreal y4);
- void extrude(qreal x1, qreal y1, qreal x2, qreal y2);
-
- bool m_inited = false;
- qreal m_fAngle = 0;
- qreal m_fScale = 1;
- QVector<QVector3D> vertices;
- QVector<QVector3D> normals;
- QOpenGLShaderProgram program;
- QOpenGLBuffer vbo;
- int vertexAttr = 0;
- int normalAttr = 0;
- int matrixUniform = 0;
- GLWidget *m_glwidget = nullptr;
- QMutex m_renderMutex;
- QElapsedTimer m_elapsed;
- QMutex m_grabMutex;
- QWaitCondition m_grabCond;
- bool m_exiting = false;
-};
-
-class GLWidget : public QOpenGLWidget
-{
- Q_OBJECT
-public:
- explicit GLWidget(QWidget *parent = nullptr);
- ~GLWidget();
-
-protected:
- void paintEvent(QPaintEvent *) override { }
-
-signals:
- void renderRequested();
-
-public slots:
- void grabContext();
-
-private slots:
- void onAboutToCompose();
- void onFrameSwapped();
- void onAboutToResize();
- void onResized();
-
-private:
- QThread *m_thread;
- Renderer *m_renderer;
-};
-
-#endif
diff --git a/examples/opengl/threadedqopenglwidget/main.cpp b/examples/opengl/threadedqopenglwidget/main.cpp
deleted file mode 100644
index 975def030b..0000000000
--- a/examples/opengl/threadedqopenglwidget/main.cpp
+++ /dev/null
@@ -1,131 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the examples of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:BSD$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** BSD License Usage
-** Alternatively, you may use this file under the terms of the BSD license
-** as follows:
-**
-** "Redistribution and use in source and binary forms, with or without
-** modification, are permitted provided that the following conditions are
-** met:
-** * Redistributions of source code must retain the above copyright
-** notice, this list of conditions and the following disclaimer.
-** * Redistributions in binary form must reproduce the above copyright
-** notice, this list of conditions and the following disclaimer in
-** the documentation and/or other materials provided with the
-** distribution.
-** * 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.
-**
-**
-** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
-** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
-** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
-** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
-** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
-** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
-** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
-** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
-** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include <QApplication>
-#include <QMainWindow>
-#include <QScreen>
-#include <QSurfaceFormat>
-#include <QOpenGLContext>
-#include <QCommandLineParser>
-#include <QCommandLineOption>
-#include "mainwindow.h"
-#include "glwidget.h"
-
-#include <memory>
-
-static QString getGlString(QOpenGLFunctions *functions, GLenum name)
-{
- if (const GLubyte *p = functions->glGetString(name))
- return QString::fromLatin1(reinterpret_cast<const char *>(p));
- return QString();
-}
-
-int main( int argc, char ** argv )
-{
- QApplication a( argc, argv );
-
- QCoreApplication::setApplicationName("Qt Threaded QOpenGLWidget Example");
- QCoreApplication::setOrganizationName("QtProject");
- QCoreApplication::setApplicationVersion(QT_VERSION_STR);
- QCommandLineParser parser;
- parser.setApplicationDescription(QCoreApplication::applicationName());
- parser.addHelpOption();
- parser.addVersionOption();
- QCommandLineOption singleOption("single", "Single thread");
- parser.addOption(singleOption);
- parser.process(a);
-
- QSurfaceFormat format;
- format.setDepthBufferSize(16);
- QSurfaceFormat::setDefaultFormat(format);
-
- // Two top-level windows with two QOpenGLWidget children in each.
- // The rendering for the four QOpenGLWidgets happens on four separate threads.
-
- GLWidget topLevelGlWidget;
- QPoint pos = topLevelGlWidget.screen()->availableGeometry().topLeft() + QPoint(200, 200);
- topLevelGlWidget.setWindowTitle(QStringLiteral("Threaded QOpenGLWidget example top level"));
- topLevelGlWidget.resize(200, 200);
- topLevelGlWidget.move(pos);
- topLevelGlWidget.show();
-
- const QString glInfo = getGlString(topLevelGlWidget.context()->functions(), GL_VENDOR)
- + QLatin1Char('/') + getGlString(topLevelGlWidget.context()->functions(), GL_RENDERER);
-
- const bool supportsThreading = !glInfo.contains(QLatin1String("nouveau"), Qt::CaseInsensitive)
- && !glInfo.contains(QLatin1String("ANGLE"), Qt::CaseInsensitive)
- && !glInfo.contains(QLatin1String("llvmpipe"), Qt::CaseInsensitive);
-
- const QString toolTip = supportsThreading ? glInfo : glInfo + QStringLiteral("\ndoes not support threaded OpenGL.");
- topLevelGlWidget.setToolTip(toolTip);
-
- std::unique_ptr<MainWindow> mw1;
- std::unique_ptr<MainWindow> mw2;
- if (!parser.isSet(singleOption)) {
- if (supportsThreading) {
- pos += QPoint(100, 100);
- mw1.reset(new MainWindow);
- mw1->setToolTip(toolTip);
- mw1->move(pos);
- mw1->setWindowTitle(QStringLiteral("Threaded QOpenGLWidget example #1"));
- mw1->show();
- pos += QPoint(100, 100);
- mw2.reset(new MainWindow);
- mw2->setToolTip(toolTip);
- mw2->move(pos);
- mw2->setWindowTitle(QStringLiteral("Threaded QOpenGLWidget example #2"));
- mw2->show();
- } else {
- qWarning() << toolTip;
- }
- }
-
- return a.exec();
-}
diff --git a/examples/opengl/threadedqopenglwidget/mainwindow.cpp b/examples/opengl/threadedqopenglwidget/mainwindow.cpp
deleted file mode 100644
index 60367c91d8..0000000000
--- a/examples/opengl/threadedqopenglwidget/mainwindow.cpp
+++ /dev/null
@@ -1,63 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the examples of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:BSD$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** BSD License Usage
-** Alternatively, you may use this file under the terms of the BSD license
-** as follows:
-**
-** "Redistribution and use in source and binary forms, with or without
-** modification, are permitted provided that the following conditions are
-** met:
-** * Redistributions of source code must retain the above copyright
-** notice, this list of conditions and the following disclaimer.
-** * Redistributions in binary form must reproduce the above copyright
-** notice, this list of conditions and the following disclaimer in
-** the documentation and/or other materials provided with the
-** distribution.
-** * 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.
-**
-**
-** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
-** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
-** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
-** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
-** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
-** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
-** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
-** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
-** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include "mainwindow.h"
-#include "glwidget.h"
-
-MainWindow::MainWindow()
-{
- setMinimumSize(800, 400);
- GLWidget *glwidget1 = new GLWidget(this);
- glwidget1->resize(400, 400);
-
- GLWidget *glwidget2 = new GLWidget(this);
- glwidget2->resize(400, 400);
- glwidget2->move(400, 0);
-}
diff --git a/examples/opengl/threadedqopenglwidget/mainwindow.h b/examples/opengl/threadedqopenglwidget/mainwindow.h
deleted file mode 100644
index 6e7b17467f..0000000000
--- a/examples/opengl/threadedqopenglwidget/mainwindow.h
+++ /dev/null
@@ -1,64 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the examples of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:BSD$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** BSD License Usage
-** Alternatively, you may use this file under the terms of the BSD license
-** as follows:
-**
-** "Redistribution and use in source and binary forms, with or without
-** modification, are permitted provided that the following conditions are
-** met:
-** * Redistributions of source code must retain the above copyright
-** notice, this list of conditions and the following disclaimer.
-** * Redistributions in binary form must reproduce the above copyright
-** notice, this list of conditions and the following disclaimer in
-** the documentation and/or other materials provided with the
-** distribution.
-** * 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.
-**
-**
-** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
-** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
-** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
-** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
-** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
-** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
-** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
-** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
-** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef MAINWINDOW_H
-#define MAINWINDOW_H
-
-#include <QWidget>
-
-class MainWindow : public QWidget
-{
- Q_OBJECT
-
-public:
- MainWindow();
-};
-
-#endif