Verified Commit 9928e18f authored by Artem Sidyakin's avatar Artem Sidyakin
Browse files

New demos

 2D/3D in QML
 QML screenshot
- qputenv examples in DI demo
- feng-shui
parent 0912a4e6
Pipeline #1150 canceled with stages
......@@ -70,3 +70,15 @@ Qt Sensors API on iOS with orientation sensor as an example.
## Application icon on Mac OS
<img src="/img/macos-app-icon-dock.png" width="800">
## QML screenshot
Making a screenshot of the application window:
<img src="/img/qml-screenshot.png" width="800">
## 2D and 3D in the same application
3D scene as a part of the 2D UI:
<img src="/img/qml-2d-3d.png" width="800">
unix:!android {
isEmpty(target.path) {
qnx {
target.path = /tmp/$${TARGET}/bin
} else {
target.path = /opt/$${TARGET}/bin
}
export(target.path)
}
INSTALLS += target
}
export(INSTALLS)
QT += qml #b2qtwifi
QT += qml
CONFIG += c++11
......@@ -10,11 +10,10 @@ RESOURCES += \
RC_ICONS = qt.ico
# Additional import path used to resolve QML modules in Qt Creator's code model
QML_IMPORT_PATH =
# Default rules for deployment.
include(deployment.pri)
HEADERS += \
backend.h
# Default rules for deployment.
qnx: target.path = /tmp/$${TARGET}/bin
else: unix:!android: target.path = /opt/$${TARGET}/bin
!isEmpty(target.path): INSTALLS += target
......@@ -8,8 +8,10 @@ int main(int argc, char *argv[])
{
QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
qputenv("QT_QPA_EGLFS_PHYSICAL_WIDTH", QByteArray("800"));
qputenv("QT_QPA_EGLFS_PHYSICAL_HEIGHT", QByteArray("480"));
//qputenv("QT_QPA_EGLFS_PHYSICAL_WIDTH", QByteArray("800"));
//qputenv("QT_QPA_EGLFS_PHYSICAL_HEIGHT", QByteArray("480"));
//qputenv("QSG_INFO", "1");
QGuiApplication app(argc, argv);
......
......@@ -9,6 +9,7 @@ ApplicationWindow {
//visibility: "FullScreen"
width: 900
height: 600
title: "Device Information"
Backend { id: backend }
......
import Qt3D.Core 2.0
import Qt3D.Render 2.0
import Qt3D.Extras 2.0
import Qt3D.Input 2.0
import QtQuick 2.11
Entity {
id: sceneRoot
Camera {
id: camera
projectionType: CameraLens.PerspectiveProjection
fieldOfView: 45
nearPlane: 0.1
farPlane: 1000.0
position: Qt.vector3d(0.0, 4.0, 15.0)
upVector: Qt.vector3d(0.0, 1.0, 0.0)
viewCenter: Qt.vector3d(0.0, -2.0, 0.0)
}
FirstPersonCameraController {
camera: camera
}
Entity {
DirectionalLight {
id: directional
worldDirection: Qt.vector3d(0.3, -1.0, 5.0).normalized();
color: "#fff2a3"
intensity: 0.01
}
Transform {
id: lightpostransform
translation: Qt.vector3d(0.0, 50.0, 60.0)
}
components: [lightpostransform, directional]
}
Entity {
PointLight {
id: pointL
color: "#fff2a3"
}
Transform{
id: plightpostransform
translation: Qt.vector3d(0.0, 4.0, 15.0)
}
components: [plightpostransform, pointL]
}
components: [
RenderSettings {
activeFrameGraph: ForwardRenderer {
id: renderer
clearColor: "black"
camera: camera
}
},
InputSettings { }
]
Water { }
}
import Qt3D.Core 2.0
import Qt3D.Render 2.0
import Qt3D.Input 2.0
import Qt3D.Extras 2.0
import QtQuick 2.11
Entity {
id: water
WaterMaterial {
id: watermaterial
property real tox: 0.0
property real toy: 0.0
property real vertY: 1.0
property real waveRandomAnim: 0.0
diffuse: "qrc:/textures/WaterDiffuse.jpg"
normal: "qrc:/textures/WaterNormal.jpg"
specular: "qrc:/textures/WaterSpecular.jpg"
wave: "qrc:/textures/Waterwave.jpg"
sky: "qrc:/textures/sky.jpg"
foam: "qrc:/textures/foam.jpg"
textureScale: 1.0
wavescale: vertY * 0.75
specularity: 1.0
offsetx: tox * 1.1
offsety: toy * 1.1
normalAmount: 2.2
waveheight: 0.2
waveStrenght: 0.015
shininess: 100
waveRandom: waveRandomAnim
}
Mesh {
id: watermesh
source: "qrc:/models/waterPlane.obj"
}
Transform {
id: waterTransform
property real scale: 0.9
property real rotx: 0.0
scale3D: Qt.vector3d(scale, scale, scale)
rotationY: 35.0
}
Entity {
id: waterEntity
components: [watermesh, watermaterial, waterTransform]
}
SequentialAnimation {
NumberAnimation {
target: watermaterial
property: "waveRandomAnim"
to: 3.0
duration: 4000
easing.type: Easing.Linear
}
NumberAnimation {
target: watermaterial
property: "waveRandomAnim"
to: 1.0
duration: 4000
easing.type: Easing.Linear
}
}
SequentialAnimation {
running: true
loops: Animation.Infinite
ParallelAnimation {
NumberAnimation {
target: watermaterial
property: "toy"
to: 10.0
duration: 100000
}
NumberAnimation {
target: watermaterial
property: "tox"
to: 10.0
duration: 100000
}
}
ParallelAnimation {
NumberAnimation {
target: watermaterial
property: "toy"
to: 0.0
duration: 0
}
NumberAnimation {
target: watermaterial
property: "tox"
to: 0.0
duration: 0
}
}
}
SequentialAnimation {
running: true
loops: Animation.Infinite
NumberAnimation {
target: watermaterial
property: "vertY"
to: 200
duration: 200000
easing.type: Easing.Linear
}
NumberAnimation {
target: watermaterial
property: "vertY"
to: 2
duration: 200000
easing.type: Easing.Linear
}
}
}
import Qt3D.Core 2.0
import Qt3D.Render 2.0
Material {
id: root
property color ambient: Qt.rgba(0.15, 0.35, 0.50, 1.0)
property alias diffuse: diffuseTextureImage.source
property alias normal: normalTextureImage.source
property alias wave: waveTextureImage.source
property alias specular: specularTextureImage.source
property alias sky: skyTextureImage.source
property alias foam: foamTextureImage.source
property color specularColor: Qt.rgba(0.2, 0.2, 0.2, 1.0)
property real shininess: 150.0
property real textureScale: 1.0
property real offsetx: 0.0
property real offsety: 0.0
property real wavescale: 0.0
property real specularity: 1.0
property real waveheight: 0.1
property real waveStrenght: 0.1
property real normalAmount: 2.0
property real waveRandom: 1.0
parameters: [
Parameter { name: "ka"; value: Qt.vector3d(root.ambient.r, root.ambient.g, root.ambient.b) },
Parameter {
name: "foamTexture"
value: Texture2D {
id: foamTexture
minificationFilter: Texture.LinearMipMapLinear
magnificationFilter: Texture.Linear
wrapMode {
x: WrapMode.Repeat
y: WrapMode.Repeat
}
generateMipMaps: true
maximumAnisotropy: 16.0
TextureImage { id: foamTextureImage }
}
},
Parameter {
name: "skyTexture"
value: Texture2D {
id: skyTexture
minificationFilter: Texture.LinearMipMapLinear
magnificationFilter: Texture.Linear
wrapMode {
x: WrapMode.Repeat
y: WrapMode.Repeat
}
generateMipMaps: true
maximumAnisotropy: 16.0
TextureImage { id: skyTextureImage }
}
},
Parameter {
name: "waveTexture"
value: Texture2D {
id: waveTexture
minificationFilter: Texture.LinearMipMapLinear
magnificationFilter: Texture.Linear
wrapMode {
x: WrapMode.Repeat
y: WrapMode.Repeat
}
generateMipMaps: true
maximumAnisotropy: 16.0
TextureImage { id: waveTextureImage }
}
},
Parameter {
name: "specularTexture"
value: Texture2D {
id: specularTexture
minificationFilter: Texture.LinearMipMapLinear
magnificationFilter: Texture.Linear
wrapMode {
x: WrapMode.Repeat
y: WrapMode.Repeat
}
generateMipMaps: true
maximumAnisotropy: 16.0
TextureImage { id: specularTextureImage }
}
},
Parameter {
name: "diffuseTexture"
value: Texture2D {
id: diffuseTexture
minificationFilter: Texture.LinearMipMapLinear
magnificationFilter: Texture.Linear
wrapMode {
x: WrapMode.Repeat
y: WrapMode.Repeat
}
generateMipMaps: true
maximumAnisotropy: 16.0
TextureImage { id: diffuseTextureImage }
}
},
Parameter {
name: "normalTexture"
value: Texture2D {
id: normalTexture
minificationFilter: Texture.LinearMipMapLinear
magnificationFilter: Texture.Linear
wrapMode {
x: WrapMode.Repeat
y: WrapMode.Repeat
}
generateMipMaps: true
maximumAnisotropy: 16.0
TextureImage { id: normalTextureImage }
}
},
Parameter {
name: "specularColor"
value: Qt.vector3d(root.specularColor.r, root.specularColor.g, root.specularColor.b)
},
Parameter { name: "shininess"; value: root.shininess },
Parameter { name: "texCoordScale"; value: textureScale },
Parameter { name: "offsetx"; value: root.offsetx },
Parameter { name: "offsety"; value: root.offsety },
Parameter { name: "vertYpos"; value: root.wavescale },
Parameter { name: "specularity"; value: root.specularity },
Parameter { name: "waveheight"; value: root.waveheight },
Parameter { name: "waveStrenght"; value: root.waveStrenght },
Parameter { name: "waveRandom"; value: root.waveRandom },
Parameter { name: "normalAmount"; value: root.normalAmount }
]
effect: Effect {
property string vertex: "qrc:/shaders/gl3/water.vert"
property string fragment: "qrc:/shaders/gl3/water.frag"
property string vertexES: "qrc:/shaders/es2/water.vert"
property string fragmentES: "qrc:/shaders/es2/water.frag"
FilterKey {
id: forward
name: "renderingStyle"
value: "forward"
}
ShaderProgram {
id: gl3Shader
vertexShaderCode: loadSource(parent.vertex)
fragmentShaderCode: loadSource(parent.fragment)
}
ShaderProgram {
id: esShader
vertexShaderCode: loadSource(parent.vertexES)
fragmentShaderCode: loadSource(parent.fragmentES)
}
AlphaCoverage { id: alphaCoverage }
DepthTest {
id: depth
depthFunction: DepthTest.Less }
techniques: [
// OpenGL 3.1
Technique {
filterKeys: [ forward ]
graphicsApiFilter {
api: GraphicsApiFilter.OpenGL
profile: GraphicsApiFilter.CoreProfile
majorVersion: 3
minorVersion: 1
}
renderPasses: RenderPass {
shaderProgram: gl3Shader
renderStates: [alphaCoverage ]
}
},
// OpenGLES 2.0
Technique {
filterKeys: [ forward ]
graphicsApiFilter {
api: GraphicsApiFilter.OpenGLES
majorVersion: 2
minorVersion: 0
}
renderPasses: RenderPass {
shaderProgram: esShader
renderStates: [ alphaCoverage ]
}
},
// OpenGL ES 2
Technique {
filterKeys: [ forward ]
graphicsApiFilter {
api: GraphicsApiFilter.OpenGLES
profile: GraphicsApiFilter.NoProfile
majorVersion: 2
minorVersion: 0
}
renderPasses: RenderPass {
shaderProgram: esShader
renderStates: [ alphaCoverage ]
}
}
]
}
}
#include <QGuiApplication>
#include <QQmlApplicationEngine>
#include <QOpenGLContext>
void setSurfaceFormat()
{
QSurfaceFormat format;
#ifdef QT_OPENGL_ES_2
format.setRenderableType(QSurfaceFormat::OpenGLES);
#else
if (QOpenGLContext::openGLModuleType() == QOpenGLContext::LibGL) {
format.setVersion(4, 3);
format.setProfile(QSurfaceFormat::CoreProfile);
}
#endif
format.setDepthBufferSize(24);
format.setSamples(4);
format.setStencilBufferSize(8);
QSurfaceFormat::setDefaultFormat(format);
}
int main(int argc, char **argv)
{
QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
QGuiApplication app(argc, argv);
setSurfaceFormat();
QQmlApplicationEngine engine;
engine.load(QUrl(QLatin1String("qrc:/main.qml")));
return app.exec();
}
import QtQuick 2.11
import QtQuick.Scene3D 2.0
import Qt3D.Render 2.1
import QtQuick.Controls 2.4
import QtQuick.Layouts 1.11
ApplicationWindow {
visible: true
width: 1100
minimumWidth: 700
height: 350
minimumHeight: 300
title: "2D and 3D in the same application"
RowLayout {
anchors.fill: parent
spacing: 0
Rectangle {
Layout.preferredWidth: parent.width * 0.3
Layout.fillHeight: true
color: "lightyellow"
border.width: 5
border.color: "green"
Text {
anchors.centerIn: parent
width: parent.width
horizontalAlignment: Text.AlignHCenter
verticalAlignment: Text.AlignHCenter
text: "Some 2D part"
font.pixelSize: 50
wrapMode: Text.WordWrap
}
}
Rectangle {
id: scene
Layout.fillWidth: true
Layout.fillHeight: true
property bool colorChange: true
color: "#2d2d2d"
border.width: 5
border.color: "red"
transform: Rotation {
id: sceneRotation
axis.x: 1
axis.y: 0
axis.z: 0
origin.x: scene.width / 2
origin.y: scene.height / 2
}
Scene3D {
id: scene3d
anchors.fill: parent
anchors.margins: 5
focus: true
aspects: ["input", "logic"]
cameraAspectRatioMode: Scene3D.AutomaticAspectRatio
SceneRoot {
id: root
}
}
}
Rectangle {
Layout.preferredWidth: parent.width * 0.3
Layout.fillHeight: true
color: "lightyellow"
border.width: 5
border.color: "green"
Text {
anchors.centerIn: parent
width: parent.width
horizontalAlignment: Text.AlignHCenter
verticalAlignment: Text.AlignHCenter
text: "Another 2D part"
font.pixelSize: 50
wrapMode: Text.WordWrap
}
}
}
}
<RCC>
<qresource prefix="/">
<file>models/waterPlane.obj</file>
</qresource>
</RC