QT QML Shader

Hello world!

QT QML Shader

Messaggioda scusscus » mar gen 13, 2015 2:51 pm

In questi giorni sto eseguendo prove con il nuovo ambiente QT (5.4.0) ed in particolare sul uso degli Shader e del linguaggio QML.
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! :eheh2:
Puoi alzarti molto presto al mattino, anche all'alba... ma il tuo destino si alza sempre mezzora prima di te. -proverbio africano-

"Stampando una notizia a grandi lettere, la gente pensa che sia indiscutibilmente vera" (J.L. Borges)

Android Software Developer & iOS Developer

Packard Bell and Amiga Enter Android Tablet Fray 9-4-2011
Avatar utente
scusscus

Eroe
 
Messaggi: 1087
Iscritto il: dom apr 18, 2004 5:54 pm
Località: Alpe Adria

Re: QT QML Shader

Messaggioda TheKaneB » mar gen 13, 2015 5:14 pm

Ottimo!

Domanda 1: conosci già C++ e Qt o stai imparando adesso?
Domanda 2: mi pare di capire che Vertex e Fragment shaders sono già pienamente supportati su AmigaOS, corretto? Se sì, a quale versione di OpenGL si fa riferimento?

Thanks!
Immagine
Avatar utente
TheKaneB

Eroe
 
Messaggi: 2218
Iscritto il: sab mar 27, 2010 2:17 am
Località: Milano

Re: QT QML Shader

Messaggioda scusscus » mer gen 14, 2015 8:00 pm

1: conosco poco il c++, solo le basi come pure di qt.
2: non so se sono supportati, io uso QtCreator da Windows7. :wow:
Puoi alzarti molto presto al mattino, anche all'alba... ma il tuo destino si alza sempre mezzora prima di te. -proverbio africano-

"Stampando una notizia a grandi lettere, la gente pensa che sia indiscutibilmente vera" (J.L. Borges)

Android Software Developer & iOS Developer

Packard Bell and Amiga Enter Android Tablet Fray 9-4-2011
Avatar utente
scusscus

Eroe
 
Messaggi: 1087
Iscritto il: dom apr 18, 2004 5:54 pm
Località: Alpe Adria

Re: QT QML Shader

Messaggioda TheKaneB » ven gen 16, 2015 11:42 am

Ah ok, pensavo che l'esempio dello shader l'avessi provato su AmigaOS :)

PS: Ti ho mandato un PM.
Immagine
Avatar utente
TheKaneB

Eroe
 
Messaggi: 2218
Iscritto il: sab mar 27, 2010 2:17 am
Località: Milano


Torna a Programmazione su Amiga

Chi c’è in linea

Visitano il forum: Nessuno e 1 ospite

cron