How to prevent tearing?

BlitzMax Forums/BlitzMax Programming/How to prevent tearing?

Nate the Great(Posted 2009) [#1]
tearing... is that what its called? well anyway how do I stop my games from having only half the screen update before my screen forces it to flip and cause tearing. Is it just my screen or am I programming something the wrong way?


Perturbatio(Posted 2009) [#2]
Flip -1?


Nate the Great(Posted 2009) [#3]
huh? ive honestly never seen that before... ill give it a go thanks :)


Nate the Great(Posted 2009) [#4]
ok its still doing it :(


xlsior(Posted 2009) [#5]
Are you running in windowed, or full-screen mode?

In windowed mode there isn't a whole lot you can do to prevent tearing...

Anyway, you may want to try flip(1):


Flip swap the front and back buffers of the current graphics objects.
If sync is 0, then the flip occurs as soon as possible. If sync is 1, then the flip occurs on the next vertical blank.

If sync is -1 and the current graphics object was created with the Graphics command, then flips will occur at the graphics object's refresh rate regardless of whether or not the graphics hardware supports such a refresh rate.

If sync is -1 and the current graphics object was NOT created with the Graphics command, then the flip will occur on the next vertical blank.




markcw(Posted 2009) [#6]
Post how you do your main loop.


_Skully(Posted 2009) [#7]
Nate the Great, is this happening in your flood game?


Nate the Great(Posted 2009) [#8]
@ skully - yes

and here is the main loop structure

graphics 1024,768,0,30

while bla
cls

flip
wend


_Skully(Posted 2009) [#9]
I see the problem.. there is nothing between the cls and the flip ;)

Try changing to full screen.. there might be an automatic flip in windowed mode.


Nate the Great(Posted 2009) [#10]
ok... on my screen (1440,900) it gets all squished but I guess on most other resolutions it will look normal.. thanks for the help...

btw flip 1 works but my game laggs so much its not playable... maybe a gfx card issure with 30 fps?


_Skully(Posted 2009) [#11]
flip 1 forces the next vertical blank which means no matter how fast your game runs its forced to wait for the refresh rate... so your game logic gets slowed down with it unless you are tweening


Nate the Great(Posted 2009) [#12]
flip 1 forces the next vertical blank which means no matter how fast your game runs its forced to wait for the refresh rate... so your game logic gets slowed down with it unless you are tweening



ok well its fixed now with full screen so im happy... and btw, I didnt even notice it, it was my brother watching over my shoulder who said hey theres something wrong with the screen. I guess if the gameplay is good enough its harder to notice.


MGE(Posted 2009) [#13]
Always use flip(1). You will regret it down the road if you don't.


Nate the Great(Posted 2009) [#14]
ok so I think this may be a problem with my hardware... I dont know why but every game or app I run tears horridly and this has never happen before :(


ImaginaryHuman(Posted 2009) [#15]
I'll second that. .. use Flip 1 for vblank sync. Flip -1 is a software timer, not a vertical sync.

Your driver might also have a setting where it's switched vblank off.


_Skully(Posted 2009) [#16]
MGE,

Do you see any problems with TileMax? I'm using Flip 0 and haven't heard of any problems.. what "regrets" will I face using flip 0


ImaginaryHuman(Posted 2009) [#17]
Flip 0 is like asking for tearing. It doesn't even sync to a consistent hz rate yet alone deal with vertical blanking periods. I can guarantee you that on my iMac for example Flip 0 will always produce tearing, so does Flip -1. The only one that is tear-free is Flip 1.


MGE(Posted 2009) [#18]
What he said. :)


Chroma(Posted 2009) [#19]
Actually, make it an option in the Video options. Something like VSync with a checkbox. Some might want to run the graphics at full speed...either way it can't hurt letting the player decide.


_Skully(Posted 2009) [#20]
It would be nice if we could hook the vertical blank to cause a flip like a timer so we wouldn't have to waste all that time waiting for the vertical blank, we could just leave our game logic running..

that way when the hook fires... it causes a flip and then we draw the next frame...


Chroma(Posted 2009) [#21]
That's a great idea Skully.


_Skully(Posted 2009) [#22]
Alas... I apparently wasn't the first to think of it... but it doesn't look to be a possibility.


ImaginaryHuman(Posted 2009) [#23]
Threads let you do other work while waiting for the vblank.


_Skully(Posted 2009) [#24]
hmmmmmm... didn't think of that :)

So the thread flip 1's, then draw's the map... logic is currently running

makes sense to me; however, is there a way to protect code blocks from interrupts?


Wings(Posted 2009) [#25]
In order to prevent tearing

use Amiga 1200
it has a propper 255 hardware interupts
one of them is the Vertical Blank

this will work for 100% sure.


MGE(Posted 2009) [#26]
You don't need threads. Just Flip(1) all the time. Amazing how all those other bmax games worked the past few years at all. ;)