Frame Limiter / Vsync

You are an experienced programmer and have a problem with the engine, shaders, or advanced effects? Here you'll get answers.
No questions about C++ programming or topics which are answered in the tutorials!
Post Reply
StuCollier
Posts: 52
Joined: Tue Mar 30, 2004 12:16 pm

Frame Limiter / Vsync

Post by StuCollier »

Im setting up a simple 2D parallax effect using the 2DImageDraw.

In pseudo code I do this

Code: Select all


image setup

while(1)
{

       UpdateTimer()

       if ( Timer >   xxx)
       {
             move X offset
             timer reset()
       }

       Draw2DImage(   using X offset )

       draw scene.........

}
* timer updates from "m_device->getTimer()->getTime()"


The problem is - it doesnt seem to Vsync properly - with glitches every so often and not very smooth.

If I ltake out the timer and change to OPENGL (where my card limits the frame rate) its silky smooth (the desired effect)

Is there another way I can sync to the screen ?



[edit]: It seems the technical term is called tearing
StuC
Freeware games
www.ovine.net
mm765
Posts: 172
Joined: Fri May 28, 2004 10:12 am

Post by mm765 »

maybe you should do it in another way.
dont move the x offset after the timer reaches a limit (timer > xxx) but move the offset by a fraction every time like offset += timerchange /xxx (xxx being the same limit as above and timerchange being the current time minus the last time the function has been executed).
this should give a smooth effect.
and to define how fast the effect moves/changes you can add a constant to the calculation (just an idea)
hth
StuCollier
Posts: 52
Joined: Tue Mar 30, 2004 12:16 pm

Post by StuCollier »

Ok Ive tried making it move in gradual steps as suggested - but alas the same problem of tearing appears....

ive posted the source if anyone wants to see what Im talkiing about ....

http://www.baa.ovine.net/scroll.zip


any help would be appreciated ( I see someone else in the beginners section has posted the same question (limit frame to 60 fps) ) so you would be helping us "2D"er's out :)
StuC
Freeware games
www.ovine.net
mm765
Posts: 172
Joined: Fri May 28, 2004 10:12 am

Post by mm765 »

i dont know if it is what you mean but if you remove the
if (myTimer->m_TimeFactor > 0.001f)
it runs smoothly here.
if that is not what you want, please visit irc that would be easier than communicate through forum :)
StuCollier
Posts: 52
Joined: Tue Mar 30, 2004 12:16 pm

Post by StuCollier »

With or without the timer function active - I still get a tearing and a judder on the main part of t.he landscape.

If I do the same in something like BLITZ3D - it works fine until I turn off the VSYNC - then it does the same as in Irrlicht

So im thinking that Irrlicht needs a similar Vsync wait command ?

Its like the 2D image is being updated in-between monitor refreshes


If I drop to using OPENGL - where my card limits to 60fps - its at the desired effect


Yes - checing nano seconds is a bit extreeme :) my fault
StuC
Freeware games
www.ovine.net
mm765
Posts: 172
Joined: Fri May 28, 2004 10:12 am

Post by mm765 »

hmm...i just tried what we talked about on irc (cutting the images after drawing to split up the tasks of cutting and drawing) .
it doesnt help because you have to convert from texture to image to texture and that takes too much time (2fps left).
and reading your first post again i think i see the problem now. what we did was limiting to a static fps count but we didnt put it in sync with the vsync-signal. and i have absolutely no idea how to do that.
sorry - my mistake for not thinking it through.
StuCollier
Posts: 52
Joined: Tue Mar 30, 2004 12:16 pm

Post by StuCollier »

Interesting threads over at www.gamedev.net.

Highlighting our need in Irrlicht for a VSYNC setting. (well for 2D drawing)

http://www.gamedev.net/community/forums ... _id=195562
StuC
Freeware games
www.ovine.net
Post Reply