在 qt5 的 qtquick 2.0 中渲染自定义 opengl [英] Rendering custom opengl in qt5's qtquick 2.0

查看:66
本文介绍了在 qt5 的 qtquick 2.0 中渲染自定义 opengl的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在寻找一种方法来在 qtquick 2.0 项目中呈现我的自定义 opengl 调用.给你一些背景信息:我有一个使用 opengl 进行渲染的 C++ 3d 引擎.目标是让它在 qtquick 2.0 UI 中呈现.

I'm looking for a way to render my custom opengl calls inside a qtquick 2.0 item. To give you some context: I have a C++ 3d engine that uses opengl for rendering. The goal is to have it rendering inside a qtquick 2.0 UI.

我发现在 qt 5.0 (qtquick 2.0) 之前,您将使用 QtGlWidget 并将其嵌入到 QDeclarativeView 中.我发现的另一种方法是使用 QtDeclarativeItem 并覆盖 void QDeclarativeItem::paint(QPainter *p, const QStyleOptionGraphicsItem *o, QWidget *w) 方法.

What I found out is that pre qt 5.0 (qtquick 2.0) you would use a QtGlWidget and embed that into the QDeclarativeView. Another way I found would be to use a QtDeclarativeItem and override the void QDeclarativeItem::paint(QPainter *p, const QStyleOptionGraphicsItem *o, QWidget *w) method.

据我所知,这不再可能,因为 QtQuick 2.0 使用基于 OpenGl 的新渲染器.因此,它似乎不像重写一个绘制方法那么容易.

As I understand it this is not possible anymore as QtQuick 2.0 uses a new renderer which is based on OpenGl. It is therefore as it seems not as easy as overriding a paint method.

有人知道我将如何实现允许渲染我的 opengl 调用的 QQuickItem 吗?

Does anybody know how I would go about implementing a QQuickItem that allows rendering of my opengl calls?

推荐答案

您可以执行以下两项操作之一.通过使用 QQuickWindow::beforeRenderingQQuickWindow::afterRendering 信号挂钩,将您的内容渲染为纹理或在场景图的 OpenGL 上下文中渲染.

You can do one of two things. Either render your content into a texture or render in the OpenGL context of the scene graph by hooking using the QQuickWindow::beforeRendering or QQuickWindow::afterRendering signals.

可以在此处找到有关如何使用 FBO 和纹理的示例:http://doc.qt.io/qt-5/qtquick-scenegraph-textureinsgnode-example.html

An example on how to use FBO and texture can be found here: http://doc.qt.io/qt-5/qtquick-scenegraph-textureinsgnode-example.html

可以在此处找到有关如何直接渲染到场景图的 OpenGL 上下文的示例:http://doc.qt.io/qt-5/qtquick-scenegraph-openglunderqml-example.html

An example on how to render directly to the OpenGL context of the scene graph can be found here: http://doc.qt.io/qt-5/qtquick-scenegraph-openglunderqml-example.html

这篇关于在 qt5 的 qtquick 2.0 中渲染自定义 opengl的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆