diff options
Diffstat (limited to 'examples/opengl/hellowindow')
-rw-r--r-- | examples/opengl/hellowindow/hellowindow.cpp | 46 | ||||
-rw-r--r-- | examples/opengl/hellowindow/hellowindow.h | 10 | ||||
-rw-r--r-- | examples/opengl/hellowindow/main.cpp | 6 |
3 files changed, 29 insertions, 33 deletions
diff --git a/examples/opengl/hellowindow/hellowindow.cpp b/examples/opengl/hellowindow/hellowindow.cpp index b4dc4464ba..da31fee920 100644 --- a/examples/opengl/hellowindow/hellowindow.cpp +++ b/examples/opengl/hellowindow/hellowindow.cpp @@ -1,6 +1,6 @@ /**************************************************************************** ** -** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). +** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies). ** Contact: http://www.qt-project.org/legal ** ** This file is part of the examples of the Qt Toolkit. @@ -145,29 +145,18 @@ void Renderer::render() QOpenGLFunctions *f = m_context->functions(); f->glViewport(0, 0, viewSize.width() * surface->devicePixelRatio(), viewSize.height() * surface->devicePixelRatio()); - - f->glClearColor(0.1f, 0.1f, 0.2f, 1.0f); f->glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); - f->glFrontFace(GL_CW); - f->glCullFace(GL_FRONT); - f->glEnable(GL_CULL_FACE); - f->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.translate(0.0f, -0.2f, 0.0f); - m_program->bind(); m_program->setUniformValue(matrixUniform, modelview); m_program->setUniformValue(colorUniform, color); - paintQtLogo(); - m_program->release(); - f->glDisable(GL_DEPTH_TEST); - f->glDisable(GL_CULL_FACE); + m_context->functions()->glDrawArrays(GL_TRIANGLES, 0, vertices.size()); m_context->swapBuffers(surface); @@ -176,17 +165,6 @@ void Renderer::render() QTimer::singleShot(0, this, SLOT(render())); } -void Renderer::paintQtLogo() -{ - m_program->enableAttributeArray(normalAttr); - m_program->enableAttributeArray(vertexAttr); - m_program->setAttributeArray(vertexAttr, vertices.constData()); - m_program->setAttributeArray(normalAttr, normals.constData()); - m_context->functions()->glDrawArrays(GL_TRIANGLES, 0, vertices.size()); - m_program->disableAttributeArray(normalAttr); - m_program->disableAttributeArray(vertexAttr); -} - void Renderer::initialize() { QOpenGLShader *vshader = new QOpenGLShader(QOpenGLShader::Vertex, this); @@ -218,6 +196,7 @@ void Renderer::initialize() m_program->addShader(vshader); m_program->addShader(fshader); m_program->link(); + m_program->bind(); vertexAttr = m_program->attributeLocation("vertex"); normalAttr = m_program->attributeLocation("normal"); @@ -226,6 +205,25 @@ void Renderer::initialize() 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); + + QOpenGLFunctions *f = m_context->functions(); + f->glClearColor(0.1f, 0.1f, 0.2f, 1.0f); + f->glFrontFace(GL_CW); + f->glCullFace(GL_FRONT); + f->glEnable(GL_CULL_FACE); + f->glEnable(GL_DEPTH_TEST); + + m_program->enableAttributeArray(vertexAttr); + m_program->enableAttributeArray(normalAttr); + m_program->setAttributeBuffer(vertexAttr, GL_FLOAT, 0, 3); + m_program->setAttributeBuffer(normalAttr, GL_FLOAT, verticesSize, 3); } void Renderer::createGeometry() diff --git a/examples/opengl/hellowindow/hellowindow.h b/examples/opengl/hellowindow/hellowindow.h index 9fb7d109b9..6a6fa275e2 100644 --- a/examples/opengl/hellowindow/hellowindow.h +++ b/examples/opengl/hellowindow/hellowindow.h @@ -1,6 +1,6 @@ /**************************************************************************** ** -** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). +** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies). ** Contact: http://www.qt-project.org/legal ** ** This file is part of the examples of the Qt Toolkit. @@ -43,6 +43,7 @@ #include <QColor> #include <QMutex> #include <QOpenGLShaderProgram> +#include <QOpenGLBuffer> #include <QSharedPointer> #include <QTimer> @@ -65,13 +66,13 @@ private slots: private: void initialize(); - qreal m_fAngle; - bool m_showBubbles; - 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); + + qreal m_fAngle; + QVector<QVector3D> vertices; QVector<QVector3D> normals; int vertexAttr; @@ -83,6 +84,7 @@ private: QSurfaceFormat m_format; QOpenGLContext *m_context; QOpenGLShaderProgram *m_program; + QOpenGLBuffer m_vbo; QList<HelloWindow *> m_windows; int m_currentWindow; diff --git a/examples/opengl/hellowindow/main.cpp b/examples/opengl/hellowindow/main.cpp index 5b2552ee3e..62b6bfca3f 100644 --- a/examples/opengl/hellowindow/main.cpp +++ b/examples/opengl/hellowindow/main.cpp @@ -41,7 +41,6 @@ #include "hellowindow.h" #include <qpa/qplatformintegration.h> -#include <private/qguiapplication_p.h> #include <QGuiApplication> #include <QScreen> @@ -51,10 +50,7 @@ int main(int argc, char *argv[]) { QGuiApplication app(argc, argv); - QPlatformIntegration *integ = QGuiApplicationPrivate::platformIntegration(); - const bool multipleWindows = integ->hasCapability(QPlatformIntegration::ThreadedOpenGL) - && integ->hasCapability(QPlatformIntegration::WindowManagement) - && !QGuiApplication::arguments().contains(QStringLiteral("--single")); + const bool multipleWindows = QGuiApplication::arguments().contains(QStringLiteral("--multiple")); QScreen *screen = QGuiApplication::primaryScreen(); |