0

I was able to create OpenGL texture from QImage with a code like this:

    QImage qImage(file_name);

    qImage = qImage.mirrored().convertToFormat(QImage::Format_ARGB32);

    GLuint Id;
    glGenTextures(1, &id);
    glBindTexture(GL_TEXTURE_2D, id);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);

    glTexImage2D(target, level, GL_RGBA, qImage.width(), qImage.height(), 0, GL_RGBA, GL_UNSIGNED_BYTE, qImage.bits());

where file_name is a JPG or PNG file.

And now I am looking for way to create QImage from a texture so I will be able to save it to a PNG file with QImage::save.

Theoretically I can crate QImage with its constructor

QImage::QImage(const uchar *data, int width, int height, QImage::Format format, QImageCleanupFunction cleanupFunction = nullptr, void *cleanupInfo = nullptr)

but it is not clear how do I access texture data.

Dmitriano
  • 1,878
  • 13
  • 29
  • There is `glGetTexImage` in OpenGL (but not in GLES), see https://stackoverflow.com/questions/32149512/opengl-how-to-read-back-texture-buffer and https://stackoverflow.com/questions/53993820/opengl-es-2-0-android-c-glgetteximage-alternative – Dmitriano Nov 29 '21 at 20:25
  • Theoretically this can be a solution https://stackoverflow.com/questions/59338015/minimal-opengl-offscreen-rendering-using-qt – Dmitriano Nov 29 '21 at 20:49

0 Answers0