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. QML and SFML
Forum Updated to NodeBB v4.3 + New Features

QML and SFML

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
1 Posts 1 Posters 422 Views
  • 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.
  • E Offline
    E Offline
    Eray
    wrote on last edited by Eray
    #1

    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 texture

    Here 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);
    
    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