Ho modificato il progetto di esempio OpenGLunderQML ( http://doc.qt.io/qt-5/qtquick-scenegrap ... ample.html ) per renderlo più interattivo.
La versione non modificata: se la avviate vi mostra una animazione in loop gestita ad un parametro t con valore compreso tra 0 ed 1 che influenza il comportamento del programma shader definito all'interno della classe squircle.cpp.
Per sperimentare il nuovo linguaggio QML e fare delle prove con i shader avendo più controllo ho legato l'animazione ad un slider. Modificando la posizione dello slider si modifica il valore del parametro e si possono verificare immediatamente gli effetti a video.
Qui di seguito il codice del file main.qml modificato:
- Codice: Seleziona tutto
/****************************************************************************
**
** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
** Contact: http://www.qt-project.org/legal
**
** This file is part of the demonstration applications of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:LGPL21$
** 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 or version 3 as published by the Free
** Software Foundation and appearing in the file LICENSE.LGPLv21 and
** LICENSE.LGPLv3 included in the packaging of this file. Please review the
** following information to ensure the GNU Lesser General Public License
** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
** 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.
**
** $QT_END_LICENSE$
**
****************************************************************************/
//! [1]
import QtQuick 2.0
import OpenGLUnderQML 1.0
import QtQuick.Controls 1.3
Item {
width: 320
height: 480
Squircle {
id: mysqrl
SequentialAnimation on t {
NumberAnimation { to: 1; duration: 2500; easing.type: Easing.InQuad }
NumberAnimation { to: 0; duration: 2500; easing.type: Easing.OutQuad }
loops: Animation.Infinite
running: false
}
}
//! [1] //! [2]
Rectangle {
color: Qt.rgba(1, 1, 1, 0.4)
radius: 10
border.width: 1
border.color: "white"
anchors.fill: label
anchors.margins: -10
Slider {
id: slider
width: parent.width
maximumValue: 1.0
stepSize: 0.05
onValueChanged: { mysqrl.t = slider.value; }
}
}
Text {
id: label
color: "black"
wrapMode: Text.WordWrap
text: "The background here is a squircle rendered with raw OpenGL using the 'beforeRender()' signal in QQuickWindow. This text label and its border is rendered using QML"
anchors.right: parent.right
anchors.left: parent.left
anchors.bottom: parent.bottom
anchors.margins: 20
}
}
//! [2]
Gli altri file del progetto potete lasciarli così come sono.
Have fun!
