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. Use QML runtime inside a game engine
Forum Updated to NodeBB v4.3 + New Features

Use QML runtime inside a game engine

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
4 Posts 2 Posters 552 Views 2 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.
  • S Offline
    S Offline
    Simmania
    wrote on 3 Jan 2021, 14:44 last edited by
    #1

    Hi,
    I would like to create a GUI inside a game engine. I think using a QML based GUI would be best. How can I run a QML runtime synchronous with the rendered frames of my game engine? And how to render to an image?

    So inside the game engine I have a loop to render my frames. I would like to call the QML runtime here to render the next GUI frame into a image so that I can use this image as the texture for some control display inside the virtual world.
    Is that possible? How can I do that?

    And if my QML GUI is controlled by some C++ code, will that still work?

    1 Reply Last reply
    0
    • J Offline
      J Offline
      Jakob Weiss
      wrote on 4 Jan 2021, 09:01 last edited by
      #2

      Hi Simmania,

      I have been looking at a similar problem (integrating Qt Quick with existing/custom 3D rendering code), and I found the two general approaches possible:
      Either you integrate your engine into qt, or or you integrate qt into your engine.

      For the first, you would basically render your 3D world "behind" the 3D UI, i.e. you have a bunch of custom render calls to render things and then Qt renders on top. There is a basic example here https://doc.qt.io/qt-5/qtquick-scenegraph-openglunderqml-example.html. However, with this variant Qt will still control the overall render/event loop, which might not be what you want.

      Alternatively, you can use QQuickRenderControl to use your own render loop, which seems more along the lines of what you want. In this variant, you supply Qt with a framebuffer to draw to, and then QtQuick simply renders to this framebuffer which you may use in any way in your own 3D code. This is a little more complicated but there is another example to get you started: https://doc.qt.io/qt-5/qtquick-rendercontrol-example.html

      Both of these methods should still work with Qt 6.0.

      Hope this gets you started!

      1 Reply Last reply
      2
      • S Offline
        S Offline
        Simmania
        wrote on 4 Jan 2021, 14:02 last edited by
        #3

        Thx a lot. I think the second option with the example is exactly what we need! But one thing is not clear to me. How can our game engine in this case communicate with the QML based GUI?

        1 Reply Last reply
        0
        • J Offline
          J Offline
          Jakob Weiss
          wrote on 5 Jan 2021, 11:45 last edited by
          #4

          Using the loaded qml GUI, you can get access to the individual subobjects and modify the qml properties, and even attach C++ code to the signals. This here should get you started in that direction: https://doc.qt.io/qt-5/qtqml-cppintegration-interactqmlfromcpp.html

          Otherwise, you could also think about implementing your own C++-based qml components, where you have full control on how they behave on the C++ side. This of course only makes sense for some specific components and not for every button, only for things that probably need heavy customization from C++.

          1 Reply Last reply
          0

          1/4

          3 Jan 2021, 14:44

          • Login

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