diff options
-rw-r--r-- | main.cpp | 14 | ||||
-rw-r--r-- | ogreitem.cpp | 18 | ||||
-rw-r--r-- | ogreitem.h | 9 | ||||
-rw-r--r-- | ogrenode.cpp | 4 | ||||
-rw-r--r-- | ogrenode.h | 6 | ||||
-rw-r--r-- | qmlogre.pro | 2 | ||||
-rw-r--r-- | resources/GrassandSky.jpg | bin | 345001 -> 0 bytes | |||
-rw-r--r-- | resources/GrassandSky.png | bin | 0 -> 759660 bytes | |||
-rw-r--r-- | resources/example.qml | 38 |
9 files changed, 62 insertions, 29 deletions
@@ -35,20 +35,18 @@ **************************************************************************/ #include "ogreitem.h" -#include <QtGui/QApplication> -#include <QSGView> -#include <QDeclarativeContext> +#include <QtGui/QGuiApplication> +#include <QtQuick/QQuickView> +#include <QtQml/QQmlContext> int main(int argc, char **argv) { - QApplication app(argc, argv); + QGuiApplication app(argc, argv); qmlRegisterType<OgreItem>("Ogre", 1, 0, "OgreItem"); - QGLFormat f = QGLFormat::defaultFormat(); - f.setSampleBuffers(true); - QSGView view(f); - view.setResizeMode(QSGView::SizeRootObjectToView); + QQuickView view; + view.setResizeMode(QQuickView::SizeRootObjectToView); view.setSource(QUrl::fromLocalFile("resources/example.qml")); view.rootContext()->setContextProperty("Window", &view); view.show(); diff --git a/ogreitem.cpp b/ogreitem.cpp index c91fd54..7adb32f 100644 --- a/ogreitem.cpp +++ b/ogreitem.cpp @@ -40,19 +40,14 @@ #include <QtCore/QPropertyAnimation> -OgreItem::OgreItem(QSGItem *parent) - : QSGItem(parent) +OgreItem::OgreItem(QQuickItem *parent) + : QQuickItem(parent) , m_timerID(0) - , m_fakeAnim(this, "") { setFlag(ItemHasContents); + setSmooth(false); - // Hack to get continuous updates - m_fakeAnim.setDuration(10000); - m_fakeAnim.setStartValue(0); - m_fakeAnim.setEndValue(1); - m_fakeAnim.setLoopCount(-1); - m_fakeAnim.start(); + startTimer(16); } QSGNode *OgreItem::updatePaintNode(QSGNode *oldNode, UpdatePaintNodeData *) @@ -74,3 +69,8 @@ QSGNode *OgreItem::updatePaintNode(QSGNode *oldNode, UpdatePaintNodeData *) return node; } + +void OgreItem::timerEvent(QTimerEvent *) +{ + update(); +} @@ -37,28 +37,29 @@ #ifndef OGREITEM_H #define OGREITEM_H -#include <QSGItem> +#include <QtQuick/QQuickItem> #include <QtCore/QPropertyAnimation> class CameraNodeObject; -class OgreItem : public QSGItem +class OgreItem : public QQuickItem { Q_OBJECT Q_PROPERTY(QObject *camera READ camera) public: - OgreItem(QSGItem *parent = 0); + OgreItem(QQuickItem *parent = 0); QObject *camera() const { return m_camera; } protected: virtual QSGNode *updatePaintNode(QSGNode *, UpdatePaintNodeData *); + void timerEvent(QTimerEvent *); + private: int m_timerID; - QPropertyAnimation m_fakeAnim; QObject *m_camera; }; diff --git a/ogrenode.cpp b/ogrenode.cpp index 33bc040..2a09445 100644 --- a/ogrenode.cpp +++ b/ogrenode.cpp @@ -72,8 +72,8 @@ OgreNode::OgreNode() , m_initialized(false) , m_dirtyFBO(false) { - setMaterial(&m_materialO); - setOpaqueMaterial(&m_material); + setMaterial(&m_material); + setOpaqueMaterial(&m_materialO); setGeometry(&m_geometry); setFlag(UsePreprocess); } @@ -37,8 +37,8 @@ #ifndef OGRENODE_H #define OGRENODE_H -#include <QSGGeometryNode> -#include "qsgtexturematerial.h" +#include <QtQuick/QSGGeometryNode> +#include <QtQuick/qsgtexturematerial.h> #include <private/qsgtexture_p.h> #include <OgreTexture.h> @@ -85,7 +85,7 @@ public: private: QSGTextureMaterial m_material; - QSGTextureMaterialWithOpacity m_materialO; + QSGOpaqueTextureMaterial m_materialO; QSGGeometry m_geometry; QSGPlainTexture *m_texture; diff --git a/qmlogre.pro b/qmlogre.pro index 25a10e7..e848a4e 100644 --- a/qmlogre.pro +++ b/qmlogre.pro @@ -1,5 +1,5 @@ CONFIG += qt -QT += opengl declarative +QT += core-private gui-private opengl qml quick-private TEMPLATE = app TARGET = qmlogre diff --git a/resources/GrassandSky.jpg b/resources/GrassandSky.jpg Binary files differdeleted file mode 100644 index 95f7991..0000000 --- a/resources/GrassandSky.jpg +++ /dev/null diff --git a/resources/GrassandSky.png b/resources/GrassandSky.png Binary files differnew file mode 100644 index 0000000..bb219e5 --- /dev/null +++ b/resources/GrassandSky.png diff --git a/resources/example.qml b/resources/example.qml index 6091358..9dd4f7f 100644 --- a/resources/example.qml +++ b/resources/example.qml @@ -46,10 +46,11 @@ Rectangle { Image { id: back anchors.fill: parent - source: "GrassandSky.jpg" + source: "GrassandSky.png" Behavior on opacity { NumberAnimation { } } } + OgreItem { id: ogreitem width: 600; height: 400 @@ -58,6 +59,7 @@ Rectangle { anchors.top: toolbar1.bottom anchors.topMargin: 6 + Behavior on opacity { NumberAnimation { } } Behavior on width { NumberAnimation { } } Behavior on height { NumberAnimation { } } @@ -93,6 +95,31 @@ Rectangle { } } ] + + MouseArea { + anchors.fill: parent + acceptedButtons: Qt.LeftButton | Qt.RightButton + + property int prevX: -1 + property int prevY: -1 + + onPositionChanged: { + if (pressedButtons & Qt.LeftButton) { + if (prevX > -1) + ogreitem.camera.yaw -= (mouse.x - prevX) / 2 + if (prevY > -1) + ogreitem.camera.pitch -= (mouse.y - prevY) / 2 + prevX = mouse.x + prevY = mouse.y + } + if (pressedButtons & Qt.RightButton) { + if (prevY > -1) + ogreitem.camera.zoom = Math.min(6, Math.max(0.1, ogreitem.camera.zoom - (mouse.y - prevY) / 100)); + prevY = mouse.y + } + } + onReleased: { prevX = -1; prevY = -1 } + } } Rectangle { @@ -658,8 +685,15 @@ Rectangle { border.color: "#1a1a1a" MouseArea { + property bool fullscreen: false anchors.fill: parent - onClicked: Window.fullScreen ? Window.showNormal() : Window.showFullScreen() + onClicked: { + if (fullscreen) + Window.showNormal(); + else + Window.showFullScreen(); + fullscreen = !fullscreen; + } } Rectangle { |