Skip to main content
GameDev.net gamedev.net
🔒 Locked

[java] Java2D vsync?

Started by Vyper_uk Jan 27, 2006 at 9:24 AM 5 replies 9.7k views
Original Post
Vyper_uk
Vyper_uk
How do I enable vsync when doing custom painting on components? I'm getting some tearing and its not very pretty to look at. Things aren't too bad at high framerates but when I force lower framerates things get really ugly looking
nataku92
nataku92
You can try looking at BufferStrategy here. Not sure if this is what you're looking for..
Vyper_uk
Vyper_uk
Thanks, but I'm already using double buffering. Double buffering gets rid of flickering, but its tearing that I'm having problems with (hence I need vsync) :(
Vyper_uk
Vyper_uk
Quote:
Original post by Anonymous Poster
Quote:
Original post by Vyper_uk
How do I enable vsync when doing custom painting on components? I'm getting some tearing and its not very pretty to look at. Things aren't too bad at high framerates but when I force lower framerates things get really ugly looking


Not sure what you mean by "ugly when forcing lower framerates", since vsync is leaving the framerate at the same rate as the monitor refreshing rate, which depends on the resolution and monitor type used.

So "lower framerates" just make no sense, because if it's lower you'll never get vsync.

If you want to know the refresh rate, I don't remember from the top of my head, but I guess GraphicsDevice or GraphicsEnvironment class has this information.

I'm not exactly sure why myself, but it just looks uglier. I will try and explain.

I'm using a delta so that no matter the frame rate, the player always travels the same distance across the map in any given time. However at lower framerates the game world is updated to the screen less regularly. As I understand it, the cause of tearing is that instead of seeing one frame of the world, you are seeing part of the previous frame covered by the new frame being drawn over the top, in effect the top half of one frame and the bottom half of another. At high frame rates the updates are only slighly different (maybe a shift of one or two pixels), so the tearing isnt particularly nasty. At lower frame rates, the difference between these two frames will be much greater (as the player has still travelled the same distance), and so the tearing is greater.

At least, thats how I understand it. Thanks for the classes, I think I already looked at them and didn't find much but I'll give them another scan :)

OrangyTang
OrangyTang
Quote:
Original post by Vyper_uk
Thanks, but I'm already using double buffering. Double buffering gets rid of flickering, but its tearing that I'm having problems with (hence I need vsync) :(

BufferStratergy is the only way to get vsync in Java2D. If you create a fullscreen, page flipped buffer strategy then (IIRC) you get vsync automagically. Otherwise you'll need to check out BufferCapabilities.isPageFlipping() and BufferCapabilities.isFullscreenRequired().
Vyper_uk
Vyper_uk
Ah so it has to be fullscreen, thanks :)

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.