Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: SFML + QML  (Read 2322 times)

0 Members and 1 Guest are viewing this topic.

Eray

  • Newbie
  • *
  • Posts: 3
    • View Profile
    • Email
SFML + QML
« on: November 22, 2020, 10:47:48 pm »
Hello,

I would like to use SFML with Qt.
More precisely I would like to create a QML component which is an instance of the SFML renderer.

Has anyone ever done this manipulation?

I tried to do something quickly with an object that inherits from QQuickItem and sf :: RenderWindow but the create doesn't work
and I'm not sure that's the right method.

My goal being to make an iOS / Android / Linux / Window game.

Thanks for your help

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: SFML + QML
« Reply #1 on: November 23, 2020, 08:39:15 am »
Not sure if that's possible at all. To be more specific, I don't think you can make SFML use the OpenGL context that Qt uses behind the scenes -- especially since it now uses an abstract rendering API which can use non-OpenGL back-ends (D3D, Vulkan, Metal).

The easiest solution, though not optimal, could be to draw your SFML scene to a render-texture, retrieve its pixels and upload them to something that QtQuick can display: ideally a QSGTexture + QSGSimpleTextureNode, or anything else that you're more familiar with (like QQuickPaintedItem + QImage).

If you've got the QSGTexture solution working, it may be worth investigating into directly transfering the pixels between the SFML render-texture and the QSGTexture's internal texture, without downloading the pixels in system RAM. I have no idea if this is possible.
Laurent Gomila - SFML developer

Eray

  • Newbie
  • *
  • Posts: 3
    • View Profile
    • Email
Re: SFML + QML
« Reply #2 on: November 24, 2020, 10:27:56 am »
Thank you for your help.

I use QSG quite often.
So I managed to display my RenderTexture in my SFML through an image no problem.

Now I would like to improve it by going directly from the opengl sfml texture to the QSGTexture texture.

In its Qt interface allows you to transform an opengl texture into a qt texture.
https://doc.qt.io/qt-5/qquickwindow.html#createTextureFromNativeObject

But it doesn't work as is, I just have a black texture.
After digging a little deeper, I think my textures are not shared between the sfml and Qt contexts, do you think this is a possible lead and do you have any solutions?

Thanks

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: SFML + QML
« Reply #3 on: November 24, 2020, 07:59:58 pm »
Nop, I'm afraid you won't be able to do this since SFML and Qt use different contexts, that are not shared.
Laurent Gomila - SFML developer

Eray

  • Newbie
  • *
  • Posts: 3
    • View Profile
    • Email
Re: SFML + QML
« Reply #4 on: November 24, 2020, 08:36:50 pm »
Thanks again for your reply !

I still have a small question with Qt, it is possible to share data from opengl contexts.

But I need to "link" my native context to a Qt context.

For that, I need to get the "GLXContext" of my SFML texture render, is it possible ?

Sources :
https://doc.qt.io/qt-5/qopenglcontext.html#setNativeHandle
https://doc.qt.io/qt-5/qglxnativecontext.html -> class I want to instantiate
https://doc.qt.io/qt-5/qopenglcontext.html#setShareContext

I do not despair yet ^^

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: SFML + QML
« Reply #5 on: November 25, 2020, 08:52:15 am »
After drawing to the SFML render-texture, its OpenGL context should be active, therefore a call to glXGetCurrentContext should do the trick.
Laurent Gomila - SFML developer