opengl 3.3做底层 QML做UI渲染

本文参照官方openglunderqml改写,基本框架不变,若用opengl3.3 只需在main函数中设置format即可,如下

<span style="font-family:Courier New;"> QSurfaceFormat format;
    format.setVersion(3,3);
    format.setProfile(QSurfaceFormat::CoreProfile);
    qmlRegisterType<RenderWindow>("OpenGLUnderQML", 1, 0, "RenderWindow");
    view1.setFormat(format);</span>
还有个问题是官方在此例中并没有提供鼠标交互功能,在本例中简单实现了下。在 openglunderqml这个例子中如果添加item继承而来的mouseEvent事件,并不起作用,当在QML中在该注册类里面添加mousearea也不起作用,所以,只能把鼠标作用区放在全局下面,代码如下:

import QtQuick 2.0

import QtQuick 2.0
import OpenGLUnderQML 1.0
import QtQuick.Controls 1.2

Item {

    width: 300
    height: 400

    RenderWindow {
        id:rw
        width:200
        height:100
        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: true
        }


    }

    MouseArea
    {
        anchors.fill: parent
        acceptedButtons: Qt.LeftButton | Qt.RightButton
        onPressed:  { rw.point = Qt.vector2d(mouseX,mouseY); }
        onPositionChanged:
        {
            rw.nPoint = Qt.vector2d(mouseX,mouseY);
            rw.point = Qt.vector2d(mouseX,mouseY);

        }
    }
    //! [1] //! [2]
    Rectangle {
        color: Qt.rgba(1, 1, 1, 0.7)
        radius: 10
        border.width: 1
        border.color: "white"
        anchors.fill: label
        anchors.margins: -10


    }

    Text {
        id: label
        color: "black"
        wrapMode: Text.WordWrap
        text: "lable"
        anchors.right: parent.right
        anchors.left: parent.left
        anchors.bottom: parent.bottom
        anchors.margins: 20
    }

    Button{
        id:button1
        text: "set pos"
        x:50
        y:60

        // activeFocusOnPress : bool
        onClicked: {

            label.text = "ds" ;
        }


    }


}

源码在此


  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值