GlReadPixels - what am I missing?
-
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[720576*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,720576*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();
}
@ -
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