Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. Render QML as a texture/material inside another QML

Render QML as a texture/material inside another QML

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
6 Posts 3 Posters 822 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • R Offline
    R Offline
    RobertB
    wrote on last edited by RobertB
    #1

    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:

    1. Create a QQmlApplicationEngine or QQmlEngine or QQmlContext and load some simple .qml
    2. Render this to a framebuffer (how?)
    3. Get a texture from this framebuffer (how?)
    4. Pass this texture to a totally new QML instance that loads some .qml (how?)
    5. Use this texture as a material on a 3D Model

    Any tips / links to documentation welcome.

    johngodJ 1 Reply Last reply
    0
    • R RobertB

      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:

      1. Create a QQmlApplicationEngine or QQmlEngine or QQmlContext and load some simple .qml
      2. Render this to a framebuffer (how?)
      3. Get a texture from this framebuffer (how?)
      4. Pass this texture to a totally new QML instance that loads some .qml (how?)
      5. Use this texture as a material on a 3D Model

      Any tips / links to documentation welcome.

      johngodJ Offline
      johngodJ Offline
      johngod
      wrote on last edited by
      #2

      @RobertB Hi
      You can do that with grabToImage, see here https://doc.qt.io/qt-6/qml-qtquick-item.html#grabToImage-method

      R 1 Reply Last reply
      0
      • johngodJ johngod

        @RobertB Hi
        You can do that with grabToImage, see here https://doc.qt.io/qt-6/qml-qtquick-item.html#grabToImage-method

        R Offline
        R Offline
        RobertB
        wrote on last edited by RobertB
        #3

        @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 the materials property of Model test. Is it possible? Or perhaps, how to use a fbo as a material?

        1 Reply Last reply
        0
        • KH-219DesignK Offline
          KH-219DesignK Offline
          KH-219Design
          wrote on last edited by
          #4

          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

          www.219design.com
          Software | Electrical | Mechanical | Product Design

          1 Reply Last reply
          1
          • KH-219DesignK Offline
            KH-219DesignK Offline
            KH-219Design
            wrote on last edited by
            #5

            The link to the example also exists for Qt6. https://doc.qt.io/qt-6.2/qt3d-scene2d-example.html

            www.219design.com
            Software | Electrical | Mechanical | Product Design

            R 1 Reply Last reply
            1
            • KH-219DesignK KH-219Design

              The link to the example also exists for Qt6. https://doc.qt.io/qt-6.2/qt3d-scene2d-example.html

              R Offline
              R Offline
              RobertB
              wrote on last edited by
              #6

              @KH-219Design that actually looks like what I want, ill check it out, thanks!

              1 Reply Last reply
              0

              • Login

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • Users
              • Groups
              • Search
              • Get Qt Extensions
              • Unsolved