BorlandTalk.com Forum Index BorlandTalk.com
Borland discussion newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

naive question - does screen refresh rate affect animation?

 
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> Delphi Graphics
View previous topic :: View next topic  
Author Message
Warrick Wilson
Guest





PostPosted: Wed Apr 26, 2006 4:03 pm    Post subject: naive question - does screen refresh rate affect animation? Reply with quote



I'm bouncing between a number of projects, and there's one case where we
have a text crawl going from right to left across the bottom of a screen.
It's actually a Java applet in a TWebBrowser control, but there's a
noticable "hesitation" that's periodic (or at least somewhat predictable).

I've tried doing something similar in a Delphi app a while ago - both in an
ActiveX control and just a plain Windows app - and I'd still see these
hesitations and some tearing on redraws. There were messages floating around
about how to do such graphics, and some helped, and I know I'll be revisting
that little project before the summer's over.

However, I've got a more fundamental question that may pertain to some
graphics and multimedia things I've been seeing:

Does the monitor's refresh rate have any bearing on flicker or tearing or
??? For example, if I want something to update at 30 frames per second, but
my monitor is updating at 75 Hz, do I have a built-in problem? Sort of like
how fluorescent lights can cause funny patterns on monitors when the refresh
rates don't match? Or is the problem I'm seeing with animation more likely
related to trying to update large areas of the screen in a poor fashion?

Thanks.
Back to top
Mike Williams (TeamB)
Guest





PostPosted: Wed Apr 26, 2006 6:03 pm    Post subject: Re: naive question - does screen refresh rate affect animati Reply with quote



Mike Williams (TeamB) wrote:

Quote:
which you would
see even if the screen had animation

Sorry, I meant to say:

which you would see even if the screen had *no* animation

--
-Mike (TeamB)
Back to top
Mike Williams (TeamB)
Guest





PostPosted: Wed Apr 26, 2006 6:03 pm    Post subject: Re: naive question - does screen refresh rate affect animati Reply with quote



Warrick Wilson wrote:

Quote:
Or is the problem I'm seeing with animation more likely related to
trying to update large areas of the screen in a poor fashion?

That's my guess. If your refresh rate is 75Hz that's really too fast
for you to see flicker caused by the refresh itself - which you would
see even if the screen had animation - and instead the flicker is from
the actual drawing code itself.

--
-Mike (TeamB)
Back to top
Jens Gruschel
Guest





PostPosted: Wed Apr 26, 2006 7:03 pm    Post subject: Re: naive question - does screen refresh rate affect animat Reply with quote

Quote:
Does the monitor's refresh rate have any bearing on flicker or tearing or
??? For example, if I want something to update at 30 frames per second, but
my monitor is updating at 75 Hz, do I have a built-in problem? Sort of like
how fluorescent lights can cause funny patterns on monitors when the refresh
rates don't match? Or is the problem I'm seeing with animation more likely
related to trying to update large areas of the screen in a poor fashion?

No, you can make your drawings whenever you want. But of course it's not
shown immediately, but when the cathode ray crosses your drawings, or
parts of it, the next time (it's similar for TFTs). This can result in
flickering. It's even possible that you don't see your drawings at all,
if you draw something, then delete it again (restoring the original
image), while the cathode ray is on its way back to the top of the
screen (there is a short vertical retrace pause where nothing is
refreshed at all).

So the best thing you could do is make your drawings during the vertical
retrace, or at least make sure you don't cross the ray while drawing (on
the C64 this was the trick to have more sprites on the screen than the
hardware did support, they were not there at the same time, only the
ones near the ray did exist).

In single task operating systems like MS DOS you can easily ask the
graphic card whether it's vertical retrace time or not (using port $3DA)
and wait a bit to sync your animation with the screen.

In multi task operating systems like Windows that's not possible.
Wasting CPU cycles is just one problem (but well, modern graphic cards
are signaling it by hardware interrupt AFAIK). And normally it's not
necessary. The worst thing which can happen is that you see a horizontal
line moving across the screen, if you refresh a smooth animation
periodically. That's because it can happen that the upper part is drawn
to a region just refreshed, and the lower part "outruns" the ray and is
shown immediately (it can be the other way round, too, but on modern
systems that's not very likely). So you see the old frame above that
line, and the new frame below that line. The line itself is not really
visible, we just think we see it, because we notice there is a
difference between the upper and the lower part.

While for most applications that doesn't matter, often you won't even
notice it, of course that's very bad for games and similar applications.
That's why DirectX allows you to synchronize your drawings with the
screen refresh rate. Of course now the frame rate cannot exceed the
refresh rate (that's why some gamers turn that feature off). It's only
possible if you have full control over the screen. DirectX has an
"exclusive" mode, not allowing other tasks to make drawings to the
screen at the same time. So this "exclusive" mode is a special full
screen mode. It also allows you to update the whole screen at once, by
drawing to a back buffer, which then is activated during the vertical
retrace - of course that's not possible if different applications share
the same screen.

--
Jens Gruschel
http://www.pegtop.net
Back to top
Roger Lascelles
Guest





PostPosted: Fri Apr 28, 2006 2:03 am    Post subject: Re: naive question - does screen refresh rate affect animat Reply with quote

"Warrick Wilson" <warrickw (AT) mercuryonline (DOT) com> wrote in message
news:444f9954$1 (AT) newsgroups (DOT) borland.com...
Quote:

Does the monitor's refresh rate have any bearing on flicker or tearing or
??? For example, if I want something to update at 30 frames per second,
but
my monitor is updating at 75 Hz, do I have a built-in problem? Sort of
like
how fluorescent lights can cause funny patterns on monitors when the
refresh
rates don't match? Or is the problem I'm seeing with animation more likely
related to trying to update large areas of the screen in a poor fashion?

If you go to http://www.trichview.com/vcllist/ and download the
TFlickerFreePaintbox, you get a nice demo program which shows two shapes
moving across the screen. One shows "tearing", the other does not. You
will be able to see if the tearing effect is the same as the trouble you
have. As well, you can see one way to solve the problem - you draw to an
offscreen bitmap which is then blitted to screen. Underneath, the API
BitBlt() function actually dumps the bitmap to screen.

Even if you don't use BitBlt(), the tearing effect can definitely be reduced
by drawing more cleverly. For example, if you let Windows or the VCL erase
the background at each step, then you paint a new color over it, you are
liable to see a burst of the erase color if the computer is "busy" for a
moment. Another trick is to only update the small area of the screen
which has changed and leave the rest untouched.

I think the "tearing" is actually a bar of another color briefly displayed,
and not a distortion of the image.

In the TFlickerFreePaintbox demo, the shapes move so slowly that the tearing
can't be a strobing effect - and is so pronounced that it can't be vertical
refresh related, so my guess is that the CPU has obeyed an interrupt and
gone off to do some other task - remember Windows is not a real time OS and
has a lot of processes running, some of which involve delays. It is just a
matter of time before a time consuming interrupt comes and takes away the
CPU in the middle of the drawing code. That would explain why the randomness
of the effect.

I produce a CAD program which uses straight TCanvas drawing functions and
the drawing is imperceptibly quick because minimal areas are redrawn and the
predominant background color only is always redrawn first. Once in a while
on a slow PC you catch a slight flicker - probably an interrupt during a
draw.

Roger Lascelles
Back to top
Warrick Wilson
Guest





PostPosted: Fri Apr 28, 2006 5:03 pm    Post subject: Re: naive question - does screen refresh rate affect animat Reply with quote

"Roger Lascelles" <rogerlasAToptusnet.com.au> wrote in message
news:44516acd$1 (AT) newsgroups (DOT) borland.com...
Quote:
"Warrick Wilson" <warrickw (AT) mercuryonline (DOT) com> wrote in message
news:444f9954$1 (AT) newsgroups (DOT) borland.com...

If you go to http://www.trichview.com/vcllist/ and download the
TFlickerFreePaintbox, you get a nice demo program which shows two shapes
moving across the screen. One shows "tearing", the other does not. You
will be able to see if the tearing effect is the same as the trouble you
have. As well, you can see one way to solve the problem - you draw to an
offscreen bitmap which is then blitted to screen. Underneath, the API
BitBlt() function actually dumps the bitmap to screen.

Even if you don't use BitBlt(), the tearing effect can definitely be
reduced
by drawing more cleverly. For example, if you let Windows or the VCL
erase
the background at each step, then you paint a new color over it, you are
liable to see a burst of the erase color if the computer is "busy" for a
moment. Another trick is to only update the small area of the screen
which has changed and leave the rest untouched.

I think the "tearing" is actually a bar of another color briefly
displayed,
and not a distortion of the image.

Thanks for the pointer. I looked at the program you mentioned, and it
suggests that it's out-dated due to DoubleBuffered being a parameter on new
panel implementations. I ran it, and there is an obvious difference in
appearance. But event with the bottom image, I was still getting an odd
effect on the redraw. It doesn't show up when I try and do a screen capture.
But what I see is something like this (where everything is against the left
margins below)

(original)
|
|
|
|

What I see part way thru
|
|
|
|

Doesn't happen every time. What I'm trying to get is a smooth
scroll/animation, and it seems that the larger the area to be drawn, the
worse off the effect becomes. And it doesn't happen every time the draw
takes place - it just happens "sometimes". My screen is set to 60 Hz
refresh, so it's probably not in the frequency of the redraw (I set the
timer to 16, and I realize there's some "slop" in how accurate that's going
to be).
Back to top
Jens Gruschel
Guest





PostPosted: Fri Apr 28, 2006 8:03 pm    Post subject: Re: naive question - does screen refresh rate affect animat Reply with quote

Quote:
(original)
|
|
|
|

What I see part way thru
|
|
|
|

That's what I meant in my post. It's no flickering but some kind of
"time moire effect". You cannot avoid it if you don't synchronize your
animation with the vertical retrace. In Windows 9x this can be done
since you can access the ports directly (but I don't recommend it). In
Windows NT/2K/XP using DirectX or OpenGL is the only solution AFAIK (or
maybe writing your own driver).

--
Jens Gruschel
http://www.pegtop.net
Back to top
Roger Lascelles
Guest





PostPosted: Sat Apr 29, 2006 4:04 am    Post subject: Re: naive question - does screen refresh rate affect animat Reply with quote

"Jens Gruschel" <nospam (AT) thisurldoesnotexist (DOT) com> wrote in message
news:44526d18$1 (AT) newsgroups (DOT) borland.com...
Quote:
That's what I meant in my post. It's no flickering but some kind of
"time moire effect". You cannot avoid it if you don't synchronize your
animation with the vertical retrace.

Warrick mentioned a timer set to "16" in his own program. If he means 16 ms
that is 62.5Hz - and strobing ("time moire") effects are possible against
the 60Hz vertical frequency. That is a very fast timer - about as fast a a
PC can handle. Most GDI animations are at somthing like 5Hz. If your
program is for commercial distribution, you can forget the fast timer.
DirectX will get this speed well up and synchronise your graphics card and
program.

As downloaded the program "TFlickerFreePaintBox" redraws its image at 1 Hz
rate and at that frequency looks perfect to me.

if you look at

http://planet-source-code.com/vb/scripts/BrowseCategoryOrSearchResults.asp?t
xtCriteria=flicker+free&blnWorldDropDownUsed=TRUE&txtMaxNumberOfEntriesPerPa
ge=10&blnResetAllVariables=TRUE&lngWId=7&B1=Quick+Search&optSort=Alphabetica
l

or

http://tinyurl.com/hn2og

you can see another BitBlt() animation which runs in a loop, pretty well as
fast as your PC can go. With my hardware and eyes, this looks perfect, with
no strobing.

Results may vary depending on how much background work your PC is doing.
Windows makes no guarantees as to CPU availability. Results may also depend
on your graphics hardware.

By the way, DoubleBuffered property uses BitBlt() internally for an
identical result.


Roger Lascelles
Back to top
Roger Lascelles
Guest





PostPosted: Sat Apr 29, 2006 4:04 am    Post subject: Re: naive question - does screen refresh rate affect animat Reply with quote

"Roger Lascelles" <rogerlasAToptusnet.com.au> wrote in message
news:4452df5a (AT) newsgroups (DOT) borland.com...
Quote:


http://planet-source-code.com/vb/scripts/BrowseCategoryOrSearchResults.asp?t

xtCriteria=flicker+free&blnWorldDropDownUsed=TRUE&txtMaxNumberOfEntriesPerPa

ge=10&blnResetAllVariables=TRUE&lngWId=7&B1=Quick+Search&optSort=Alphabetica
l

or

http://tinyurl.com/hn2og


Oops! Tthere are two items at that link - its "Flicker Free Graphics !" by
"Scottie G" .

Roger Lascelles
Back to top
Jens Gruschel
Guest





PostPosted: Sat Apr 29, 2006 12:03 pm    Post subject: Re: naive question - does screen refresh rate affect animat Reply with quote

Quote:
As downloaded the program "TFlickerFreePaintBox" redraws its image at 1 Hz
rate and at that frequency looks perfect to me.

Yes, of course, for such slow animations (much slower than the screen
refresh rate) the effect is still there, but it's nearly invisible. It
also depends on what your animation looks like. I posted a very simple
example project to b.p.attachments. For horizontal scrolling you'll see
the effect when the scrolling speed exceeds some limit.

--
Jens Gruschel
http://www.pegtop.net
Back to top
Warrick Wilson
Guest





PostPosted: Sun Apr 30, 2006 8:03 pm    Post subject: Re: naive question - does screen refresh rate affect animat Reply with quote

"Jens Gruschel" <nospam (AT) thisurldoesnotexist (DOT) com> wrote in message
news:44534757 (AT) newsgroups (DOT) borland.com...
Quote:
As downloaded the program "TFlickerFreePaintBox" redraws its image at 1
Hz
rate and at that frequency looks perfect to me.

Yes, of course, for such slow animations (much slower than the screen
refresh rate) the effect is still there, but it's nearly invisible. It
also depends on what your animation looks like. I posted a very simple
example project to b.p.attachments. For horizontal scrolling you'll see
the effect when the scrolling speed exceeds some limit.

Jens,

Thanks for the example. I've played with it a little over the past couple of
days and you're right - it really starts to show the effect when I get the
trackbar position up to about 4. I set it up to move the opposite direction
and it does the same thing, and it seems more pronounced. I think that's
just a visual effect trick from the eye, though.

I'm going to play with it some more. In my case, I want to actually move a
larger image through the "viewport" that the PaintBox in your example would
be.I was hoping to do it smoothly. Using a full-screen DirectX or OpenGL
isn't currently an option in my application (I'm assuming I'd need to run
full-screen "exclusive mode", rather than trying to set up an small window.)

Thanks again...
Back to top
Display posts from previous:   
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> Delphi Graphics All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.