opengl 3.3做底层 QML做UI渲染
2015-09-12 22:17
585 查看
本文参照官方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" ; } } }
源码在此
相关文章推荐
- UGUI 音效
- iOS开发: UITableViewCell的自适应高度
- easyui之datagrid的使用
- java.sql.SQLException: Value'0000-00-00'异常解决
- UI设计 视图控制器
- EasyUI queryParams属性 在请求远程数据同时给action方法传参
- easyui的combobox控件进一步优化
- UI课程10 UITableView的编辑
- UIScrollView添加自动布局
- IOS上 关于状态栏的相关设置(UIStatusBar)
- 1101. Quick Sort (25)
- [iOS]给UILabel赋HTML数据。
- UISearchBar基本设置 和 代理方法
- 用NGUI显示图片鼠标点击的地方出现在屏幕上
- Java请求参数类QueryParameter
- EasyUI学习笔记_1
- 关于UI线程的阻塞问题以及处理方式
- Dynamic Programming实战一:Longest Increasing Subsequence算法分析及C代码实现
- POJ 1776 - Task Sequences(哈密顿图)
- UIStatusBarStyle的类型改变