Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

[SOLVED] QImage and glTexImage2D()



  • Hi there,

    I am using Qt 5 and want to know what the current approach to use glTexImage2D() with QImage or QPixmap is. I used to do it like this:

    @QImage tmpImage("someTex.jpg");
    QImage image = QGLWidget::convertToGLFormat(tmpImage);

    glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, image.width(), image.height(), 0, GL_RGBA, GL_UNSIGNED_BYTE, image.bits());@

    Since QGLWidget is or will be deprecated (i at least do believe so), i want to get rid of this approach.
    I also do not want to use QOpenGLTexture because the software i am writing is for learning OpenGL.

    Thanks in advance.
    Happy new year!



  • Starting with Qt 5.2 you can use image.convertToFormat(QImage::Format_RGBA8888) instead.



  • Also, deprecated does not mean that QGLWidget will go away. Also look at the implementation of QOpenGLTexture and it's helpers to see what it does.



  • OK thanks,

    It can also be done like this:
    @
    QImage tmpImage("someTex.jpg");
    QImage image = tmpImage.mirrored();

    glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, image.width(), image.height(), 0, GL_BGRA, GL_UNSIGNED_BYTE, image.bits());
    @


Log in to reply