[Qt-interest] fastest way to draw everchanging pixels

Reto Glauser qt at blinkeye.ch
Mon Mar 23 20:03:03 CET 2009


On 03/23/2009 04:26 PM,  Oliver.Knoll at comit.ch wrote:
> 
> As it seems you have already been given a blazing-fast solution for your problem: indeed, by calling one single method like "drawPoints" (which takes an *array* of pre-calculated points) it largely reduces the method-call overhead (with high level languages such as Java and C++/Qt people tend to blend out that function/method calls *are* expensive, even today - especially when it comes to calling methods 1000s of times, such as in your nested loop above ;)
> 
> Still, I would like to give you another approach which is still pixel-based and similar to your approach. But instead of callling a method for (potentially) each pixel, you do your own address arithmetic and calculate the pixel values. The basic idea is that you first draw into a QImage which gives you direct pixel access, using some easy pointer arithmetic, and then let the QPainter draw this QImage (which will automatically be converted to a QPixmap for fast drawing).
> 
> Note that I don't know which approach - QImage vs "drawPoints()" - is faster. I guess it also depends on the "atom/wall density". You have to find out for yourself.
> 

Thanks, I will certainly try this approach and compare the results.



More information about the Qt-interest-old mailing list