Vertical Sync

J

JoshVote

Hi,

Currently I am developing for Windows CE 5.0 using .NET CF 2.0.

I have a custom control that displays a subset of a long (vertically)
bitmap. The user is able to touch their stylus on this bitmap and drag up /
down to visually drag the image up / down so they can explore the length of
the image.

The problem is that as the image redraws onto the screen during a scroll, a
degree of visual tearing occurs and its quite visually distracting. Is there
anyway to counteract this? (Ie enabling VSync or equivalent using .NET or is
this something that should be done via the graphics driver?)

The drawing is done by overriding the OnPaint base method of the control
class and using the Graphics DrawImage function.

I'm quite new to .NET graphics so apologies in advance if I'm missing
anything glaringly obvious.
 
A

Alejandro Mezcua

Have you tried overriding OnPaintBackground and leaving that method blank?

protected override void OnPaint(PaintEventArgs e) {}

If you don't do this, on each paint the background is painted first with the
color set in the BackColor property, which causes a lot of flickering.

Hope this helps,

Cheers,

Alejandro Mezcua
MVP Device Application Development
http://www.byteabyte.net/
 
J

JoshVote

Alejandro Mezcua said:
Have you tried overriding OnPaintBackground and leaving that method blank?

protected override void OnPaint(PaintEventArgs e) {}

If you don't do this, on each paint the background is painted first with the
color set in the BackColor property, which causes a lot of flickering.

Hope this helps,

Cheers,

Alejandro Mezcua
MVP Device Application Development
http://www.byteabyte.net/

Thanks for the reply,

Unfortunately I've already done that, the issue isn't flickering its that
the image "Tears" when being redrawn rapidly. The cause of this is due to me
blitting the image to the display whilst the screen is currently in the
process of refreshing its pixels.

I'm starting to think that .NET won't have a solution and that I'll need to
P/Invoke a GDI function to wait until the screen has finished drawing itself.
Does anyone have any suggestions on where I might go with this?
 
D

diogoriba

Thanks for the reply,

Unfortunately I've already done that, the issue isn't flickering its that
the image "Tears" when being redrawn rapidly. The cause of this is due to me
blitting the image to the display whilst the screen is currently in the
process of refreshing its pixels.

I'm starting to think that .NET won't have a solution and that I'll need to
P/Invoke a GDI function to wait until the screen has finished drawing itself.
Does anyone have any suggestions on where I might go with this?

I think the best way to go is to implement double buffering. This
prevents the form to draw anything on the screen before the image is
loaded on an secondary buffer.
It's actually pretty simple, and very effective when it comes to
reducing flickering of the screen.
It will look like this:

public class DoubleBufferedForm : Form
{
protected override void OnPaint(PaintEventArgs e)
{
Bitmap buffer = new Bitmap(Width, Heigth);
PaintEventArgs subPaintEventArgs = new
PaintEventArgs(Graphics.FromImage(buffer), e.ClipRectangle);
base.OnPaint(subPaintEventArgs);
e.Graphics.DrawImage(buffer, 0, 0);
}
}

Hope this helps.
Good luck!
 
A

Alejandro Mezcua

Hi Josh.

The only way I know to sync with the vertical retrace is using DirectX.
There is a function called WaitForVerticalBlank
(http://msdn.microsoft.com/en-us/library/aa911354.aspx) that does just that,
but as the docs say I'm afraid it is only available on Windows Mobile or CE
6.0, but not on CE 5.0.

I haven't tried using it on mobile devices myself though, so I don't know
what extra problems you will find if you try to use it.

Cheers,

Alejandro Mezcua
 
J

JoshVote

Thanks again,

I saw that function but I'm limited to WinCE 5.0 unfortunately.

Even if I was able to use this, would it mean having to have DirectDraw /
Direct3D perform all my drawing which would entail me having to handle
drawing all controls myself?

Sorry if this is a bit silly but I've never used any DirectX.

Does anyone else know of an equivalent GDI function that I could P/Invoke?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top