Important: Please read the Qt Code of Conduct -

Problem createTextureFromNativeObject

  • Hi,

    I want to transform an OPENGL texture into QSGTexture.
    I want to do this because I use an external library to do.

    But using "createTextureFromNativeObject" always gives me a "black" texture while using "createTextureFromImage" of the same texture it works do you have any idea ?

    Test project :

        m_renderTexture->getTexture().copyToImage().saveToFile("/home/anthony/try.png"); // WORKS !!
        GLuint texture = static_cast<GLuint>(m_renderTexture->getTexture().getNativeHandle());
        qDebug() << "NATIVE HANDLE " << texture;
        GLenum error = glGetError();
        qDebug() << "GL ERROR " << error; // NO ERROR
        QImage image(m_renderTexture->getTexture().copyToImage().getPixelsPtr(), 800, 600, QImage::Format_RGBA8888);
        QSGTexture *wrapper = window()->createTextureFromImage(image);//WORKS !!
        QQuickWindow::CreateTextureOptions opts;
        wrapper =   window()->createTextureFromNativeObject(QQuickWindow::NativeObjectTexture,
                                                       QSize(800, 600), opts); //BLACK TEXTURE

  • The simple texture node class must have a texture before being added to the scene graph to be rendered. You may find some tips here and I think it could be helpful

Log in to reply