QGLWidget and grabFrameBuffer() problem in software Raycaster
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.
frontBuffer = grabFrameBuffer();
drawBackFace(); backBuffer = grabFrameBuffer();
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
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; // create matrix of quaternion rotation // First row pMatrix = 1.0f - 2.0f * (m_y * m_y + m_z * m_z); pMatrix = 2.0f * (m_x * m_y + m_z * m_w); pMatrix = 2.0f * (m_x * m_z - m_y * m_w); pMatrix = 0.0f; // Second row pMatrix = 2.0f * (m_x * m_y - m_z * m_w); pMatrix = 1.0f - 2.0f * (m_x * m_x + m_z * m_z); pMatrix = 2.0f * (m_z * m_y + m_x * m_w); pMatrix = 0.0f; // Third row pMatrix = 2.0f * (m_x * m_z + m_y * m_w); pMatrix = 2.0f * (m_y * m_z - m_x * m_w); pMatrix = 1.0f - 2.0f * (m_x * m_x + m_y * m_y); pMatrix = 0.0f; // Fourth row pMatrix = 0; pMatrix = 0; pMatrix = 0; pMatrix = 1.0f; glEnable(GL_CULL_FACE); glCullFace(GL_FRONT); glCullFace(GL_BACK); // any rotation glMultMatrixf(pMatrix); glDisable(GL_LIGHTING); // choose culling (CW for front, CCW for backface) glFrontFace(GL_CW); // draw the cube drawCube(); // flush glFlush();
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!