PDA

View Full Version : QPainter to QImage , crazy alpha channel



firnafin
10th March 2012, 14:14
Hello everyone,

I start learning Qt for scholar work, not without pains :p
My goal is to pass a QLinearGradient to opengl texture.

Here is my issue : when I try to paint into image a gradient with alpha channel i get a strange render.
The code where I render gradient to image :


QImage painter_image( 256 , 1 , QImage::Format_ARGB32);
QPainter painter( &painter_image );
painter.setPen(Qt::NoPen);
painter.setBrush( *gradient ); // the gradient came form gradient editor see picture
painter.drawRect( painter_image.rect() );
painter.end();

QImage gradient_image = QGLWidget::convertToGLFormat( painter_image );
// use this image to render with opengl ....
// later in code :
glTexImage1D( GL_TEXTURE_1D, 0, GL_RGBA8 , 256 ,0 ,GL_RGBA, GL_UNSIGNED_BYTE, gradient_image.bits() );


2 pictures to show up what going wrong :
this one all it's ok because alpha is 255 to all gradient.
7479
when I change the alpha of blue gradient composante some artefacts appear ( verticals lines with random color ).
7481
Like you can see, when gradient is paint in the gradient widget the alpha channel is good.
I check image colors RGBA values with
qDebug()<<qRed( image.pixel( x,0 ) ).... to ensure that effect dont came from opengl Render. Artefact appear in both gradient_image and painter_image.
If someone has an idea ...