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. GlReadPixels - what am I missing?
Forum Updated to NodeBB v4.3 + New Features

GlReadPixels - what am I missing?

Scheduled Pinned Locked Moved QML and Qt Quick
2 Posts 2 Posters 2.4k Views 1 Watching
  • 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.
  • S Offline
    S Offline
    sdrsdr
    wrote on last edited by
    #1

    I've created a QtQuick application then modified it to write into QOpenGLFramebufferObject, counted 30 afterRendering and then I try glReadPixels(0,0,720,576,GL_RGBA,GL_RGBA8,pixdata); but my app crashes. What am I missing? How can I handle OpenGL errors?

    Here is my relevant code:
    @
    #include <QtGui/QGuiApplication>
    #include <QOpenGLFramebufferObject>

    #include "qtquick2applicationviewer.h"

    QGuiApplication *app;

    class QtQuick2ApplicationViewerEx : public QtQuick2ApplicationViewer
    {
    private:
    QOpenGLFramebufferObject fbo;
    int numframes;
    public slots:
    void OnsceneGraphInitialized();
    void OnafterRendering();
    };
    void QtQuick2ApplicationViewerEx::OnafterRendering(){
    if (numframes>30) {
    char pixdata[720
    576*4];
    try {
    glReadPixels(0,0,720,576,GL_RGBA,GL_RGBA8,pixdata);
    } catch (...) {

    }
    //QFile f=new QFile(QString("pic.raw"));
    //f->open(QIODevice::WriteOnly);
    //f->write(pixdata,720
    576*4);
    //f->close();
    app->exit(22);
    }
    numframes++;
    }
    void QtQuick2ApplicationViewerEx::OnsceneGraphInitialized(){
    fbo=new QOpenGLFramebufferObject(720,576,QOpenGLFramebufferObject::CombinedDepthStencil, GL_TEXTURE_2D,GL_RGBA8);
    numframes=0;
    setRenderTarget(fbo);
    }

    int main(int argc, char *argv[])
    {
    app=new QGuiApplication (argc, argv);

    QtQuick2ApplicationViewerEx viewer;

    QObject::connect(&viewer,&QQuickWindow::sceneGraphInitialized,&viewer,&QtQuick2ApplicationViewerEx::OnsceneGraphInitialized,Qt::ConnectionType::DirectConnection);
    QObject::connect(&viewer,&QQuickWindow::afterRendering,&viewer,&QtQuick2ApplicationViewerEx::OnafterRendering,Qt::ConnectionType::DirectConnection);
    viewer.setMainQmlFile(QStringLiteral("qml/qq_pl/main.qml"));
    viewer.showExpanded();

    return app->exec();
    }
    @

    1 Reply Last reply
    0
    • A Offline
      A Offline
      agocs
      wrote on last edited by
      #2

      GL_RGBA8 is not a valid pixel data type. Try GL_UNSIGNED_BYTE instead.

      See http://www.khronos.org/opengles/sdk/docs/man/xhtml/glReadPixels.xml

      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