QGLWidget or OpenGL glitch

i am reading Programming with Qt:2nd edition. in it is this code which uses QGLWidget for OpenGL drawing. i have compiled and run this same exact code with no problem. i must say that back then i had KDE installed. now when i try to run the same code i get some opengl drawing artifacts when resizing the window. i don’t think it should have anything to do with KDE, however, the code is the same as it was. Does anyone know why this happens?

#include <qapplication.h>
#include <stdlib.h>
#include <qgl.h>

class SierpinskiWidget : public QGLWidget
virtual void paintGL();
virtual void initializeGL();
virtual void resizeGL( int w, int h );

void SierpinskiWidget::paintGL()
typedef GLfloat point2[2];
point2 vertices[3] = {{ 0.0,.0},{200.0,175.00},{400.0,0.0}}; // triangle
point2 p = { width()/2.0, height()/2.0 }; // initial point


/* Compute and plot 5000 new points */
for( int k = 0; k < 5000; k++ ) {
int j = rand() % 3; // pick a random vertex

// Compute the point between the vertex and the old point
p[0] = ( p[0] + vertices[j][0] ) / 2.0;
p[1] = ( p[1] + vertices[j][1] ) / 2.0;

// Plot new point
glBegin( GL_POINTS );
glVertex2fv( p );



void SierpinskiWidget::initializeGL()
glClearColor( 1.0, 1.0, 1.0, 1.0 );
glColor3f( 1.0, 0.0, 0.0 );

void SierpinskiWidget::resizeGL( int w, int h )
glMatrixMode( GL_PROJECTION );
gluOrtho2D( 0.0, w, 0.0, h );
glMatrixMode( GL_MODELVIEW );


int main( int argc, char* argv[] )
QApplication::setColorSpec( QApplication::CustomColor );
QApplication a(argc,argv);

SierpinskiWidget* w = new SierpinskiWidget();
w-&gt;resize( 400, 350 );
a.setMainWidget( w );
return a.exec();


What card/driver are you using?

I have been using the NVidia cards for a few years now, and I remember resizing working much smoother, with little drawing artifacts in the older drivers. I don’t know the Rev. of the driver, but it was about 1.5 years ago. Since then the driver has gotten much better with speed, and stability, but resizing gives strange artifacts (although they clear up after a second or so). Given the choice, I would opt for the speed and stability.


This topic was automatically closed 183 days after the last reply. New replies are no longer allowed.