RobotRock
RobotRock

Reputation: 4449

Qt OpenGL framebuffer to image

I'm drawing the framebuffer to an image, it used to work fine, however something broke and I have no idea what..

Any help would be great.

I get the error "QGLFramebufferObject: Framebuffer incomplete, missing attachment."

It seems to work intermittently.

VoxelEditor::VoxelEditor(QWidget *parent)
    : QGLWidget(QGLFormat(QGL::SampleBuffers), parent)
{

    makeCurrent();
    catchFbo = new QGLFramebufferObject(PICTURE_SIZE, PICTURE_SIZE);




void VoxelEditor::renderToImage() {
    saveGLState();
    const int nrPics = 360 / DEGREES_BETWEEN_PICTURES;
    for (int i = 0; i < nrPics; i++) {
        catchFbo->bind();
        glColorMask(true, true, true, true);
        glClearColor(0,0,0,0);
        glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
        glEnable(GL_DEPTH_TEST);
        glDepthFunc(GL_LESS);
        glEnable(GL_MULTISAMPLE);
        glLoadIdentity();

        GLfloat x = GLfloat(PICTURE_SIZE) / PICTURE_SIZE;
        glFrustum(-x, +x, -1.0, +1.0, 1.0, 1000.0);
        glViewport(0, 0, PICTURE_SIZE, PICTURE_SIZE);

        drawScreenshot(i);
        catchFbo->release();

        QImage catchImage = catchFbo->toImage();
        catchImage.save("object/test" + QString::number(i) + ".png");
    }
    glDisable(GL_MULTISAMPLE);

    restoreGLState();
}

Upvotes: 1

Views: 4476

Answers (2)

RobotRock
RobotRock

Reputation: 4449

I solved this by putting the creation of the fbo in the rendertoimage call.

It seemed at creation it was valid and had the appropriate attachment, but at execution it failed..

Perhaps creating the fbo in the initializeGL call would work as well.

Upvotes: 2

Jeka
Jeka

Reputation: 1374

Have you check you buffer with isValid() method? Try to release buffer after call toImage() method.

Upvotes: 0

Related Questions