summaryrefslogtreecommitdiffstats
path: root/tests/manual/qopenglwidget
diff options
context:
space:
mode:
Diffstat (limited to 'tests/manual/qopenglwidget')
-rw-r--r--tests/manual/qopenglwidget/openglwidget/main.cpp73
-rw-r--r--tests/manual/qopenglwidget/openglwidget/openglwidget.cpp193
-rw-r--r--tests/manual/qopenglwidget/openglwidget/openglwidget.h63
-rw-r--r--tests/manual/qopenglwidget/openglwidget/openglwidget.pro9
4 files changed, 338 insertions, 0 deletions
diff --git a/tests/manual/qopenglwidget/openglwidget/main.cpp b/tests/manual/qopenglwidget/openglwidget/main.cpp
new file mode 100644
index 0000000000..68f9be7199
--- /dev/null
+++ b/tests/manual/qopenglwidget/openglwidget/main.cpp
@@ -0,0 +1,73 @@
+/****************************************************************************
+**
+** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/legal
+**
+** This file is part of the test suite of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** 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 Digia. For licensing terms and
+** conditions see http://qt.digia.com/licensing. For further information
+** use the contact form at http://qt.digia.com/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Digia gives you certain additional
+** rights. These rights are described in the Digia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "openglwidget.h"
+#include <QApplication>
+#include <QPushButton>
+#include <QMdiArea>
+#include <QLCDNumber>
+#include <QTimer>
+
+
+int main(int argc, char *argv[])
+{
+ QApplication a(argc, argv);
+
+ QMdiArea w;
+ w.resize(400,400);
+
+ OpenGLWidget *glw = new OpenGLWidget;
+ w.addSubWindow(glw);
+ glw->setMinimumSize(100,100);
+
+ OpenGLWidget *glw2 = new OpenGLWidget;
+ glw2->setMinimumSize(100,100);
+ w.addSubWindow(glw2);
+
+ QLCDNumber *lcd = new QLCDNumber;
+ lcd->display(1337);
+ lcd->setMinimumSize(300,100);
+ w.addSubWindow(lcd);
+
+ w.show();
+
+ return a.exec();
+}
diff --git a/tests/manual/qopenglwidget/openglwidget/openglwidget.cpp b/tests/manual/qopenglwidget/openglwidget/openglwidget.cpp
new file mode 100644
index 0000000000..09e0dd5419
--- /dev/null
+++ b/tests/manual/qopenglwidget/openglwidget/openglwidget.cpp
@@ -0,0 +1,193 @@
+/****************************************************************************
+**
+** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/legal
+**
+** This file is part of the test suite of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** 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 Digia. For licensing terms and
+** conditions see http://qt.digia.com/licensing. For further information
+** use the contact form at http://qt.digia.com/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Digia gives you certain additional
+** rights. These rights are described in the Digia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#define GL_GLEXT_PROTOTYPES
+
+#include "openglwidget.h"
+#include <QtWidgets/private/qwidget_p.h>
+#include <QOpenGLFramebufferObject>
+#include <QWindow>
+#include <qpa/qplatformwindow.h>
+#include <QDebug>
+#include <QTimer>
+
+#include <QtGui/QOpenGLFunctions>
+#include <QtGui/QGuiApplication>
+#include <QtGui/QMatrix4x4>
+#include <QtGui/QOpenGLShaderProgram>
+#include <QtGui/QScreen>
+
+#include <QtCore/qmath.h>
+#include <qopengl.h>
+
+#include <GL/glext.h>
+
+class OpenGLWidgetPrivate
+{
+public:
+ OpenGLWidgetPrivate()
+ : m_program(0), m_frame(0)
+ {
+
+ }
+
+ void initialize();
+ void render();
+
+
+ int width() {return w;}
+ int height() {return h;}
+
+ GLuint m_posAttr;
+ GLuint m_colAttr;
+ GLuint m_matrixUniform;
+
+ QOpenGLShaderProgram *m_program;
+ int m_frame;
+
+ int w,h;
+};
+
+
+OpenGLWidget::OpenGLWidget(QWidget *parent)
+ : QOpenGLWidget(parent)
+{
+ d = new OpenGLWidgetPrivate;
+ QTimer *timer = new QTimer(this);
+ connect(timer, SIGNAL(timeout()), this, SLOT(updateGL()));
+ timer->start(30);
+}
+
+OpenGLWidget::~OpenGLWidget()
+{
+
+}
+
+void OpenGLWidget::initializeGL()
+{
+// qDebug("*initializeGL*");
+ d->initialize();
+}
+
+void OpenGLWidget::resizeGL(int w, int h)
+{
+// qDebug("*resizeGL*");
+ d->w = w;
+ d->h = h;
+}
+void OpenGLWidget::paintGL()
+{
+// qDebug("*paintGL* %d", d->m_frame);
+ d->render();
+}
+
+
+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";
+
+void OpenGLWidgetPrivate::initialize()
+{
+ m_program = new QOpenGLShaderProgram;
+ m_program->addShaderFromSourceCode(QOpenGLShader::Vertex, vertexShaderSource);
+ m_program->addShaderFromSourceCode(QOpenGLShader::Fragment, fragmentShaderSource);
+ m_program->link();
+ m_posAttr = m_program->attributeLocation("posAttr");
+ m_colAttr = m_program->attributeLocation("colAttr");
+ m_matrixUniform = m_program->uniformLocation("matrix");
+}
+
+void OpenGLWidgetPrivate::render()
+{
+ const qreal retinaScale = 1.0;//devicePixelRatio();
+ glViewport(0, 0, width() * retinaScale, height() * retinaScale);
+
+ glClearColor(0.0, 0.0, 0.0, 1.0);
+ glClear(GL_COLOR_BUFFER_BIT);
+
+ m_program->bind();
+
+ QMatrix4x4 matrix;
+ matrix.perspective(60, 4.0/3.0, 0.1, 100.0);
+ matrix.translate(0, 0, -2);
+ matrix.rotate(100.0f * m_frame / 30/*screen()->refreshRate()*/, 0, 1, 0);
+
+ m_program->setUniformValue(m_matrixUniform, matrix);
+
+ GLfloat vertices[] = {
+ 0.0f, 0.707f,
+ -0.5f, -0.5f,
+ 0.5f, -0.5f
+ };
+
+ GLfloat colors[] = {
+ 1.0f, 0.0f, 0.0f,
+ 0.0f, 1.0f, 0.0f,
+ 0.0f, 0.0f, 1.0f
+ };
+
+ glVertexAttribPointer(m_posAttr, 2, GL_FLOAT, GL_FALSE, 0, vertices);
+ glVertexAttribPointer(m_colAttr, 3, GL_FLOAT, GL_FALSE, 0, colors);
+
+ glEnableVertexAttribArray(0);
+ glEnableVertexAttribArray(1);
+
+ glDrawArrays(GL_TRIANGLES, 0, 3);
+
+ glDisableVertexAttribArray(1);
+ glDisableVertexAttribArray(0);
+
+ m_program->release();
+
+ ++m_frame;
+}
diff --git a/tests/manual/qopenglwidget/openglwidget/openglwidget.h b/tests/manual/qopenglwidget/openglwidget/openglwidget.h
new file mode 100644
index 0000000000..eaba27df26
--- /dev/null
+++ b/tests/manual/qopenglwidget/openglwidget/openglwidget.h
@@ -0,0 +1,63 @@
+/****************************************************************************
+**
+** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/legal
+**
+** This file is part of the test suite of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** 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 Digia. For licensing terms and
+** conditions see http://qt.digia.com/licensing. For further information
+** use the contact form at http://qt.digia.com/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Digia gives you certain additional
+** rights. These rights are described in the Digia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef OPENGLWIDGET_H
+#define OPENGLWIDGET_H
+
+#include <QtWidgets/private/qopenglwidget_p.h>
+
+class OpenGLWidgetPrivate;
+class OpenGLWidget : public QOpenGLWidget
+{
+ Q_OBJECT
+public:
+ OpenGLWidget(QWidget *parent = 0);
+ ~OpenGLWidget();
+
+ void initializeGL();
+ void resizeGL(int w, int h);
+ void paintGL();
+
+private:
+ OpenGLWidgetPrivate *d;
+};
+
+#endif // OPENGLWIDGET_H
diff --git a/tests/manual/qopenglwidget/openglwidget/openglwidget.pro b/tests/manual/qopenglwidget/openglwidget/openglwidget.pro
new file mode 100644
index 0000000000..63d877e7b0
--- /dev/null
+++ b/tests/manual/qopenglwidget/openglwidget/openglwidget.pro
@@ -0,0 +1,9 @@
+QT += widgets widgets-private gui-private core-private
+
+TARGET = openglwidget
+TEMPLATE = app
+
+SOURCES += main.cpp \
+ openglwidget.cpp
+
+HEADERS += openglwidget.h