Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Rendering a QImage on openGL
QtWS25 Last Chance

Rendering a QImage on openGL

Scheduled Pinned Locked Moved Unsolved General and Desktop
openglqopengltextureqimage
1 Posts 1 Posters 1.6k 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.
  • M Offline
    M Offline
    maitai_vw
    wrote on last edited by
    #1

    Hello,
    I am trying to render a QImage on an openGL surface. I have read/studied many tutorials but no luck so far. If someone could point me where my mistake is...

        QOpenGLContext context;
        context.create();
        QOffscreenSurface surface;
        surface.setFormat(QSurfaceFormat::defaultFormat());
        surface.create();
        context.makeCurrent(&surface);
        QOpenGLFramebufferObjectFormat fboFormat;
        fboFormat.setSamples(16);
        fboFormat.setAttachment(QOpenGLFramebufferObject::CombinedDepthStencil);
        const int w = 800;
        const int h = 600;
        QOpenGLFramebufferObject fbo(w, h, fboFormat);
        fbo.bind();
        QOpenGLPaintDevice device(QSize(w, h));
        QPainter pnt(&device);
        pnt.setRenderHint(QPainter::Antialiasing);
        pnt.setRenderHint(QPainter::TextAntialiasing);
        pnt.setRenderHint(QPainter::SmoothPixmapTransform);
        pnt.fillRect(QRect(0, 0, w, h), Qt::green);
        pnt.end();
        QImage pix(50, 100, QImage::Format_ARGB32_Premultiplied);
        pix.fill(Qt::red);
        glEnable(GL_TEXTURE_2D);
        QOpenGLTexture *texture = new QOpenGLTexture(pix.mirrored(), QOpenGLTexture::DontGenerateMipMaps);
        texture->bind();
        glEnable(GL_DEPTH_TEST);
        glPushMatrix();
        glTranslatef(10, 10, 0);
        glBegin(GL_QUADS);
        glTexCoord2i(0, 0); glVertex3f(0, 0, 0);
        glTexCoord2i(1, 0); glVertex3f(pix.width(), 0, 0);
        glTexCoord2i(1, 1); glVertex3f(pix.width(), pix.height(), 0);
        glTexCoord2i(0, 1); glVertex3f(0, pix.height(), 0);
        glEnd();
        glPopMatrix();
        glFlush();
        texture->release();
        glDisable(GL_TEXTURE_2D);
        delete texture;
        fbo.release();
        fbo.toImage().save("opengl.png");
    

    All I get is a plain green image... I have tried many other things and options, this version seems to me the more logical, yet it does not work.

    Thanks in advance for unlocking me...

    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