How to prevent tearing?
BlitzMax Forums/BlitzMax Programming/How to prevent tearing?
| ||
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? |
| ||
Flip -1? |
| ||
huh? ive honestly never seen that before... ill give it a go thanks :) |
| ||
ok its still doing it :( |
| ||
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. |
| ||
Post how you do your main loop. |
| ||
Nate the Great, is this happening in your flood game? |
| ||
@ skully - yes and here is the main loop structure graphics 1024,768,0,30 while bla cls flip wend |
| ||
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. |
| ||
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? |
| ||
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 |
| ||
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. |
| ||
Always use flip(1). You will regret it down the road if you don't. |
| ||
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 :( |
| ||
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. |
| ||
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 |
| ||
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. |
| ||
What he said. :) |
| ||
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. |
| ||
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... |
| ||
That's a great idea Skully. |
| ||
Alas... I apparently wasn't the first to think of it... but it doesn't look to be a possibility. |
| ||
Threads let you do other work while waiting for the vblank. |
| ||
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? |
| ||
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. |
| ||
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. ;) |