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

Author Topic: How to make a sf::RenderTexture and a Qt 6 widget share their OpenGL contexts?  (Read 1202 times)

0 Members and 1 Guest are viewing this topic.

mhn2

  • Newbie
  • *
  • Posts: 3
    • View Profile
Hi, after reading this topic on this forum, it seems like connecting an sf::RenderWindow to a QWidget will not work reliably anymore. But "binary1248" also stated:
Quote
If you are willing to pull off some really weird looking (platform-specific) stuff, you can get SFML and Qt to share their OpenGL contexts with each other. This would let you use an sf::RenderTexture's texture to draw a "full-screen" textured quad in Qt and do the actual drawing in SFML itself. This is a bit tricky to pull off, but entirely possible.
I lack enough knowledge about SFML, Qt and OpenGL to be able to figure out how to do this myself.
Can anyone help me find a way to make an sf::RenderTexture and a Qt 6 widget share their OpenGL contexts?
Qt also has a widget called QOpenGLWidget which might be able to help with the problem, but I don't know how.
I will appreciate any help.

mhn2

  • Newbie
  • *
  • Posts: 3
    • View Profile
I found that the QOpenGLWidget has a function called defaultFramebufferObject that returns the FBO of the widget, if there is a way to connect this to a sf::RenderTexture the problem should be mostly solved. The event handling will be able to be done using QtEvents.

So currently the question is, how can I draw on a OpenGL framebuffer object using SFML?

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11030
    • View Profile
    • development blog
    • Email
It's a pretty advanced and complicated topic, as one would need good knowledge of both Qt and SFML, and additionally understanding OpenGL and the different OS event processing. As such, don't be surprised, if nobody can really provide some additional insights.

So currently the question is, how can I draw on a OpenGL framebuffer object using SFML?
I don't think that's really possible as SFML handles its own framebuffers.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11030
    • View Profile
    • development blog
    • Email
Also as a side note, if you're already using Qt, then it IMHO doesn't really make sense to try and cram SFML into it, especially since Qt by itself provides already all the graphics capabilities you'd need, see Qt GUI: https://doc.qt.io/qt-5/qtgui-index.html
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/