QGLWidget and grabFrameBuffer() problem in software Raycaster

  • Hello.

    Im working on a Qt raycaster (software-based for now).
    Something like this;

    For that i need to draw an opengl color cube, and use culling to get the front and back faces.
    My idea is to draw the cube with regular culling, grab the framebuffer to a QImage, draw with opposite culling and fetch the buffer again as backBuffer.

    These images will be used in the actual raycasting.

    The drawing seems okay, meaning that if i comment out backface the frontface is drawn correctly -- and vice versa, the cubes are drawn as intended.
    The problem is when i look at the grabbed images, they are always are identical. (one should be the frontface, the other the backface)

    Any tips/hints/aid would be most appreciated.

    Some code..
    void GLWidget::paintGL()
    frontBuffer = grabFrameBuffer();

    backBuffer = grabFrameBuffer();


    void GLWidget::drawFrontFace()
    glTranslatef(0.0f, 0.0f, -5.0f);
    glScalef(zoom, zoom, zoom); // any zooming
    glTranslatef(offset.x(), offset.y(), offset.z());

    QVector4D vec4 = rotation.toVector4D();
    float m_x = vec4.x();
    float m_y = vec4.y();
    float m_z = vec4.z();
    float m_w = vec4.w();
    GLfloat pMatrix[16];
    // create matrix of quaternion rotation
    // First row
    pMatrix[0] = 1.0f - 2.0f * (m_y * m_y + m_z * m_z);
    pMatrix[1] = 2.0f * (m_x * m_y + m_z * m_w);
    pMatrix[2] = 2.0f * (m_x * m_z - m_y * m_w);
    pMatrix[3] = 0.0f;
    // Second row
    pMatrix[4] = 2.0f * (m_x * m_y - m_z * m_w);
    pMatrix[5] = 1.0f - 2.0f * (m_x * m_x + m_z * m_z);
    pMatrix[6] = 2.0f * (m_z * m_y + m_x * m_w);
    pMatrix[7] = 0.0f;
    // Third row
    pMatrix[8] = 2.0f * (m_x * m_z + m_y * m_w);
    pMatrix[9] = 2.0f * (m_y * m_z - m_x * m_w);
    pMatrix[10] = 1.0f - 2.0f * (m_x * m_x + m_y * m_y);
    pMatrix[11] = 0.0f;
    // Fourth row
    pMatrix[12] = 0;
    pMatrix[13] = 0;
    pMatrix[14] = 0;
    pMatrix[15] = 1.0f;
    // any rotation
    // choose culling (CW for front, CCW for backface)
    // draw the cube
    // flush


  • Problem solved.

    The issue was not caused by the grabFrameBuffer()-function as suspected, but by re-use of a QPixmap the data was passed to.
    After creating a new QPixmap (one for each texture) everything worked as it should.

    Thanks for everyone who took their time reading this!

Log in to reply

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.