Sign in to follow this  

[java] Java2D vsync?

This topic is 4332 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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

Share this post


Link to post
Share on other sites
Guest 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.

Share this post


Link to post
Share on other sites
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 :)

Share this post


Link to post
Share on other sites
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().

Share this post


Link to post
Share on other sites

This topic is 4332 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this