Render QML as a texture/material inside another QML
-
Hello,
I am using Qt 6.6.0 with OpenGL.
Is it possible to render a QML instance to a texture, and expose that texture to a totally different QML instance that uses Quick3D. Because then I can use the texture as a material on a Model inside View3D.
Something like this:
- Create a
QQmlApplicationEngine
orQQmlEngine
orQQmlContext
and load some simple.qml
- Render this to a framebuffer (how?)
- Get a texture from this framebuffer (how?)
- Pass this texture to a totally new QML instance that loads some
.qml
(how?) - Use this texture as a material on a 3D Model
Any tips / links to documentation welcome.
- Create a
-
@johngod Thanks. I was thinking about doing something with a framebuffer because I suspect
grabToImage()
is slow if it is repeatedly called at the monitor's vsync.Perhaps an easier question is "how to apply a
QOffscreenSurface
to a Model" (in combination with QQuickRenderControl).For example, given this QML code:
View3D { id: view anchors.fill: parent Model { id: test position: Qt.vector3d(0, 0, 0) scale: Qt.vector3d(1, 1, 1) source: "#Rectangle" materials: [ DefaultMaterial { diffuseColor: "red" } ] } PerspectiveCamera { position: Qt.vector3d(0, 0, 250) eulerRotation.x: 0 } DirectionalLight { eulerRotation.x: -30 eulerRotation.y: -70 } environment: SceneEnvironment { backgroundMode: SceneEnvironment.Color clearColor: "skyblue" } }
How to apply a
QOffscreenSurface
to thematerials
property of Modeltest
. Is it possible? Or perhaps, how to use a fbo as a material? -
Caveat: I have never done any 3d coding work beyond compiling the Qt3d samples! So I probably won't have much more to say after this post.
My post to you, is:
Does this example do what you want? I think this example might give some clues or point in the right direction: https://doc.qt.io/qt-5/qt3d-scene2d-example.html
-
The link to the example also exists for Qt6. https://doc.qt.io/qt-6.2/qt3d-scene2d-example.html
-
@KH-219Design that actually looks like what I want, ill check it out, thanks!