I have encountered some problem with QGLFrameBufferObject, when I change my OS from win7 to Ubuntu 12.04 LTS. After recompiling the code in the new ubuntu system, the color goes wrong. So I made a minimal test. I just clear the color buffer with color (1.0, 0.0, 0.0, 0.8), and that's it.
I get the correct result when I render directly to the screen, with all pixels being (1.0, 0.0, 0.0, 0.8).
However, the result from offline rendering (with QGLFrameBufferObject) is wrong, as given by offline.png. This color is (0.3, 0.0, 0.0, 0.8).
This problem happens when alpha>0.0 and <1.0. For 0.0 and 1.0 it works fine.
I've compiled this test code on another computer (computer A) with win7 OS, everything works fine. Also tried on one more computer (computer B) with ubuntu OS, everything works fine.
I'm using a NVidia GeForce GTX 570 GPU, and have tried the latest stable driver (304.60) and an older version (290.10, used for computer B) for linux-64bit, but nothing changes.
Anyone knows why? Below is the code.
mywidget::mywidget(QWidget * parent) :
QGLWidget(parent)
{
}
void mywidget::resizeGL(int width, int height )
{
glViewport(0, 0, width, height);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluOrtho2D(0.0, 1.0, 0.0, 1.0);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
}
void mywidget::paintGL()
{
glClearColor(1.0, 0.0, 0.0, 0.8);
// DRAW ON THE SCREEN
{
glClear(GL_COLOR_BUFFER_BIT);
}
QGLFramebufferObject fbo(width(), height());
fbo.bind();
// DRAW ON THE FBO USING THE SAME CODE AND THE SAME CONTEXT
{
glClearColor(1.0, 0.0, 0.0, 0.8);
glClear(GL_COLOR_BUFFER_BIT);
}
fbo.release();
fbo.toImage().save("offline.png");
}
I have noticed that there are two similar posts, but with no answer or detailed answer: Wrong alpha blending when rendering on a QGLFramebufferObject; Alpha compositing wrong when rendering to QGLFrameBufferObject vs screen