QML and Qt Quick
2018.12.05 21:43

Qml에서 커튼효과 구현 예제 - Shader Effects

조회 수 6681 추천 수 0 댓글 0
?

단축키

Prev이전 문서

Next다음 문서

크게 작게 위로 아래로 댓글로 가기 인쇄 첨부
?

단축키

Prev이전 문서

Next다음 문서

크게 작게 위로 아래로 댓글로 가기 인쇄 첨부

OpenGL Shaders 커튼효과 예제

 

A Book about Qt5에서 소개된 예제이다.

https://qmlbook.github.io/en/ch09/index.html

 

CurtainEffect.qml

import QtQuick 2.6

ShaderEffect {
    anchors.fill: parent

    mesh: GridMesh {
        resolution: Qt.size(50, 50)
    }

    property real topWidth: open?width:20
    property real bottomWidth: topWidth
    property real amplitude: 0.1
    property bool open: false
    property variant source: effectSource

    Behavior on bottomWidth {
        SpringAnimation {
            easing.type: Easing.OutElastic;
            velocity: 250; mass: 1.5;
            spring: 0.5; damping: 0.05
        }
    }

    Behavior on topWidth {
        NumberAnimation { duration: 1000 }
    }


    ShaderEffectSource {
        id: effectSource
        sourceItem: effectImage;
        hideSource: true
    }

    Image {
        id: effectImage
        anchors.fill: parent
        source: "qrc:/assets/fabric.jpg"
        fillMode: Image.Tile
    }

    vertexShader: "
        attribute highp vec4 qt_Vertex;
        attribute highp vec2 qt_MultiTexCoord0;
        uniform highp mat4 qt_Matrix;
        varying highp vec2 qt_TexCoord0;
        varying lowp float shade;

        uniform highp float topWidth;
        uniform highp float bottomWidth;
        uniform highp float width;
        uniform highp float height;
        uniform highp float amplitude;

        void main() {
            qt_TexCoord0 = qt_MultiTexCoord0;

            highp vec4 shift = vec4(0.0, 0.0, 0.0, 0.0);
            highp float swing = (topWidth - bottomWidth) * (qt_Vertex.y / height);
            shift.x = qt_Vertex.x * (width - topWidth + swing) / width;

            shade = sin(21.9911486 * qt_Vertex.x / width);
            shift.y = amplitude * (width - topWidth + swing) * shade;

            gl_Position = qt_Matrix * (qt_Vertex - shift);

            shade = 0.2 * (2.0 - shade ) * ((width - topWidth + swing) / width);
        }"

    fragmentShader: "
        uniform sampler2D source;
        varying highp vec2 qt_TexCoord0;
        varying lowp float shade;
        void main() {
            highp vec4 color = texture2D(source, qt_TexCoord0);
            color.rgb *= 1.0 - shade;
            gl_FragColor = color;
        }"
}

 

main.qml에서 사용한 예제

import QtQuick 2.6
import QtQuick.Window 2.2

Item {
    id: root
    width: background.width;
    height: background.height

    Rectangle {
        id: background
        width: 480
        height: 240
        anchors.centerIn: parent
        color: "#cccccc"
    }

    Text {
        anchors.centerIn: parent
        font.pixelSize: 48
        color: '#efefef'
        text: 'Qt5 Cadaques'
    }

    CurtainEffect {
        id: curtain
        anchors.fill: parent
    }

    MouseArea {
        anchors.fill: parent
        onClicked: curtain.open = !curtain.open
    }
}

 

Shader Effects type은 다음과 같이 커튼효과를 낼 수 있다.

jwplayer


  1. No Image notice

    Qt프로그래밍(QtQuick) Beginner를 위한 글 읽는 순서

    Date2019.01.05 CategoryQML and Qt Quick By운영자 Views131086
    read more
  2. QtWayland와 ivi-compositor

    Date2018.12.27 CategoryMobile and Embedded Bymakersweb Views8460
    Read More
  3. Qml과 C++로 구현하는 GUI어플리케이션

    Date2018.12.25 CategoryQML and Qt Quick Bymakersweb Views20401
    Read More
  4. No Image

    싱글터치 스크린 및 임베디드 리눅스 기반에서 Qt 터치입력

    Date2018.12.24 CategoryMobile and Embedded Bymakersweb Views7390
    Read More
  5. ShaderEffect QML Type 을 이용한 그래픽효과

    Date2018.12.09 CategoryQML and Qt Quick Bymakersweb Views8812
    Read More
  6. No Image

    Qml에서 커튼효과 구현 예제 - Shader Effects

    Date2018.12.05 CategoryQML and Qt Quick By운영자 Views6681
    Read More
  7. 안드로이드 Qt 프로그래밍

    Date2018.11.30 CategoryMobile and Embedded Bymakersweb Views15641
    Read More
  8. 리눅스에서 Qt4.8기반 어플리케이션의 한글입력

    Date2018.11.29 CategoryInstallation and Deployment Bymakersweb Views9472
    Read More
  9. QML에서 동적으로 텍스트 다국어 처리

    Date2018.11.04 CategoryQML and Qt Quick Bymakersweb Views9712
    Read More
  10. Qt Installer Framework - 패키징, 설치프로그램 제작

    Date2018.10.14 CategoryInstallation and Deployment Bymakersweb Views20748
    Read More
  11. Qt 응용프로그램 배포(windows)

    Date2018.10.10 CategoryGeneral and Desktop Bymakersweb Views17175
    Read More
  12. No Image

    소스코드에서 환경변수 가져오기와 설정하기

    Date2018.10.08 CategoryGeneral and Desktop Bymakersweb Views7973
    Read More
  13. 표를 만들고 PDF문서로 출력하기

    Date2018.09.30 CategoryGeneral and Desktop Bymakersweb Views6213
    Read More
  14. Qml에서 키보드 입력 이벤트 핸들링

    Date2018.08.09 CategoryQML and Qt Quick Bymakersweb Views10565
    Read More
  15. Qml 어플리케이션 정적 빌드

    Date2018.07.27 CategoryInstallation and Deployment Bymakersweb Views7817
    Read More
  16. No Image

    Qt Bluetooth 관련 기능 확인 사항

    Date2018.07.10 CategoryInstallation and Deployment Bymakersweb Views6224
    Read More
  17. No Image

    Qml 및 C++개발시 유용한 팁

    Date2018.04.06 CategoryQML and Qt Quick Bymakersweb Views12974
    Read More
  18. No Image

    Qt Version확인 방법

    Date2018.03.29 CategoryGeneral and Desktop Bymakersweb Views9357
    Read More
  19. 초보자를 위한 첫번째 프로젝트 - QML로 만드는 Hello World

    Date2018.03.16 CategoryGeneral and Desktop Bymakersweb Views25281
    Read More
  20. Windows에서 라즈베리파이3 Qt 어플리케이션 개발 및 원격 실행

    Date2018.02.23 CategoryInstallation and Deployment Bymakersweb Views11219
    Read More
  21. Windows에서 라즈베리파이3용 Qt5.10.0 크로스컴파일

    Date2018.02.23 CategoryMobile and Embedded Bymakersweb Views19103
    Read More
Board Pagination Prev 1 ... 5 6 7 8 9 Next
/ 9