Flickering dispaly when using drawImageAt


#1

Hi,
I’m trying to implement a “sound wave” animation - sound wave that is smoothly going from right to left.
something like this -

So, i’ve created an Image, and doing the following steps -
on new wave data received -

  1. draw vertical line at the right side of the image (line length is received wave amplitide) . I’m using Image::setPixelAt for this
  2. move image to the left by one pixel : Image::moveImageSection

repaint() is called on timer (30 times per second),
image is drawn in paint(). ( Image::g.drawImageAt(m_image, 0, 0, false); is used )

PS
I’ve tried setBufferedToImage(true); - no changes.
I’ve tried to use critical section to divide image content update and image drawing in time.
Image size is somethig about 300 x 150

Could you please propose something.


#2

Not a good design. Don’t do any drawing on other threads - just store the raw data and draw it in your paint method. The juce demo does something almost identical - you should look at how that does it.


#3

Just chaged it so that all drawing is done in ::paint() ,
and data to draw is generated locally (so all is now in the same thread and in one method)

only repaint() is called from timerCallback()

And I see the same, my image is redrawn like it was in old times when you drawing directly to VGA buffer without waiting for vertical retrace.

BTW, I just tried precompiled juce demo, and in multithreading demo I see the same - flying circles are drawn with the same artifacts. Looks like I see old part of image on the upper half of circle and newly drawn part on the bottom half of circle.

My image is much bigger in size - so it looks bad…


#4

All the drawing is double-buffered and done correctly - it’s up to the OS when it chooses to perform the paint callback, and if that doesn’t sync with the monitor, well, that’s just tough, really. The days of being able to wait for the vblank are long gone…


#5

Thanks!