qtとQOpenGLFunctionsを使ってスクリーングラバーを作ろうとしています。私のコードはfuncs = context-> functions();のseg faultsです。このコードは実際には素晴らしいものではなく、スレッド化されているわけではありません。タイマーはそのような小さな間隔では正確ではありませんが、私が使用しようとしているコードよりもコンセプトの証拠です。私が理解しているように、ウィンドウ上でANGLEを使用できるようにするには、これらのQOpenGLFunctionsを使用する必要があります。 Windowsはopengl 1.0と一緒にしか出荷されず、むしろそれを使用せず、代わりにANGLEを使ってdirectxを使用するので役に立ちます。私はすべてのキットでQT 5.5.1から5.7を使ってUbuntu 16.04 LTSとWindows 10をテストしました。Qt OpenGLFunctions seg fault
コンストラクタ:
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
//QOpenGLContext *context = new QOpenGLContext();
QOpenGLContext *context = QOpenGLContext::CurrentContext();
//I only want to use glreadpixels. I don't need the rest of opengl. This may not be necessary.
QSurfaceFormat format;
format.setRenderableType(QSurfaceFormat::OpenGL);
format.setDepthBufferSize(32);
format.setVersion(4,5);
format.setSamples(4);
format.setProfile(QSurfaceFormat::CompatibilityProfile);
context->setFormat(format);
context->create();
funcs = context->functions(); //seg faults here
funcs->initializeOpenGLFunctions();
connect(timer, SIGNAL(timeout()), this, SLOT(grabScreen()));
connect(timer2, SIGNAL(timeout()),this, SLOT(quit()));
timer->setTimerType(Qt::PreciseTimer);
timer2->setTimerType(Qt::PreciseTimer);
timer2->start(10000); //10 sec
timer->start(1000/60); //60 fps
}
grabScreen:
void MainWindow::grabScreen()
{
//this method it too slow for anything more than one Monitor at 60 fps.
//this->originalPixmap = this->primary->grabWindow(0,0,0,1920,1080);
//this method is fast. Did 120 FPS no problem. It doesn't use the QtOpenGLFunctions. Less portable?
//QImage image(1920,1080,QImage::Format_RGBA8888);
//glReadPixels(0,0,1920,1080,GL_RGBA,GL_UNSIGNED_BYTE, image.bits());//not writing to the image bits
QImage image(1920,1080,QImage::Format_RGBA8888);
funcs->glReadPixels(0,0,1920,1080,GL_RGBA,GL_UNSIGNED_BYTE, image.bits());
frameCount++;
if(frameCount % 10 == 0) //update preview label
{
//ui->label->setPixmap(QPixmap::fromImage(image.scaled(ui->label->size())));
ui->label->setPixmap(originalPixmap.scaled(ui->label->size()));
//qDebug() << QString("Frame: " + frameCount);
}
}
このコードで私の他の問題は、何らかの理由で非QT glreadpixelsは書かないということですqimage.bits()に渡します。
'context-> create();'はtrueまたはfalseを返しますか? – PeterT
「My code seg faults」もちろん、次はデバッガを開いてクラッシュを呼び出し、デバッグモードでスタックトレースを実行することです。何をあなたに示しましたか? –
context.create()はfalseを返します。それが問題になるかもしれません。 segフォールトが発生し、命令キューにコンパイルされたコードの位置が示されます。それを引き起こした指示のアドレスだけを伝えてください。 –