Unsolved QML and SFML
-
Hello,
I am trying to create a QML component that displays a rendering of SFML.
The problem being that the SFML generates textures in its own context, I would like to recover its textures in my context to create a QSGTexture.
I managed to create a context and share it with my qt context normally!
But the creation of the texture does not work, createTextureFromNativeObject simply returns me a black textureHere is my code, no "assert" ... no particular problem, my image which records my rendering is also good
QOpenGLContext *current = m_window->openglContext(); assert(current); sf::Context contextSFML; QSurfaceFormat surfaceFormat; surfaceFormat.setRenderableType(QSurfaceFormat::OpenGL); surfaceFormat.setProfile(QSurfaceFormat::CompatibilityProfile); assert(m_render.create(800, 600) == true); m_render.setActive(true); m_shape.setFillColor(sf::Color(150, 50, 250)); m_shape.setSize({20.f, 20.f}); m_shape.setPosition({20.f, 20.f}); GLXContext currentContext; currentContext = glXGetCurrentContext(); assert(currentContext); QOpenGLContext *context = new QOpenGLContext(); context->setFormat(surfaceFormat); context->setNativeHandle(QVariant::fromValue(QGLXNativeContext(currentContext))); context->setShareContext(current); context->create(); assert(context->isValid()); assert(QOpenGLContext::areSharing(current, context)); assert(QOpenGLContext::areSharing(context, current)); m_texture.create(800, 600); m_shape.setPosition({m_x, 20.f}); m_render.clear(sf::Color::Green); m_render.draw(m_shape); m_render.display(); sf::Texture tmpTexture(m_render.getTexture()); sf::Image img = tmpTexture.copyToImage(); m_texture.update(tmpTexture); img.saveToFile("~/tt.png"); m_frame = QImage(img.getPixelsPtr(), 800, 600, QImage::Format_ARGB32); assert(tmpTexture.getNativeHandle() != 0); qDebug() << "ID : " << tmpTexture.getNativeHandle() << " Size texture " << tmpTexture.getSize().x << " " << tmpTexture.getSize().y; GLuint texture = static_cast<GLuint>(tmpTexture.getNativeHandle()); assert(texture); m_textureQt = m_window->createTextureFromNativeObject(QQuickWindow::NativeObjectTexture, &texture, 0, QSize(800, 600)); assert(m_textureQt);