vsync causing twitches [solved monitor issue]

Started by obi, January 11, 2014, 04:35:27

Previous topic - Next topic

obi

I need to know If someone else can confirm this behaviour!

Running the simple test code below:
For some weird reason I get a flash of red or blue color every 5/6 seconds. Changing the vsync freq doesn't matter the flash keeps its period.
If lowering the freq. to 30 you can actually see a tear between red and blue moving upwards on the screen (might have to wait a bit since during its movement it will spend some time outside the visible screen).
The tear seems to be dependent on time, because if I stop the app and restart it will always show up where it would have been if I didn't restart.

The result when rendering a moving scene is a subtle twitch every ~0.833 seconds which is driving me crazy.

import org.lwjgl.LWJGLException;
import org.lwjgl.opengl.Display;
import org.lwjgl.opengl.DisplayMode;
import org.lwjgl.opengl.GL11;

public class LWJGL_Display
{
    private int freq = 120;
    private final boolean fullscreen = false;
    private long frame = 0;
    
    public void start() throws LWJGLException 
    {
        int desktopWidth = Display.getDesktopDisplayMode().getWidth();
        int desktopHeight = Display.getDesktopDisplayMode().getHeight();
        int desktopBpp = Display.getDesktopDisplayMode().getBitsPerPixel();
        DisplayMode mode = findDisplayMode( desktopWidth, desktopHeight, desktopBpp, fullscreen );

        Display.setDisplayMode( mode );
        Display.setFullscreen( fullscreen );
        Display.setVSyncEnabled( true );
        Display.create();
        
        while( !Display.isCloseRequested() ) 
        {
            render();
            
            Display.update( false );
            Display.sync( freq );
            Display.processMessages();
            
            frame++;
        }     
        Display.destroy();
    }

    private void render()
    {
        if( frame%2 == 0 )
        {
            GL11.glClearColor( 1, 0, 0, 1 );
        }
        else
        {
            GL11.glClearColor( 0, 0, 1, 1 );            
        }
        GL11.glClear( GL11.GL_COLOR_BUFFER_BIT );        
    }
    
    private DisplayMode findDisplayMode
    (
        final int width, 
        final int height, 
        final int bpp, 
        final boolean fullscreen 
    ) 
        throws LWJGLException 
    {
        DisplayMode[] modes = Display.getAvailableDisplayModes();
        DisplayMode mode = null;
        
        int area,currentArea,bestArea;
        currentArea = 0;        
        bestArea = fullscreen ? width*height : width*height/4;
        
        for( int i=0;i<modes.length;i++ ) 
        {
            if( (modes[i].getBitsPerPixel() == bpp) || (mode == null) ) 
            {
                area = modes[i].getWidth() * modes[i].getHeight();
                if( Math.abs( area - bestArea ) < Math.abs( currentArea - bestArea ) )
                {
                    mode = modes[i];
                    currentArea = area;
                }                    
            }
        }        
        return mode;
    }
    public static void main(final String[] argv) throws LWJGLException 
    {
        new LWJGL_Display().start();            
    }
}

Cornix

I dont see any tearing effects on my computer. VSync is working fine for me.

Are you sure you have VSync enabled on your graphics card driver?

obi

It's not tearing like when running without vsync.

It's just that I always get a twitch every ~0.83 seconds when running vsync. Like a skipped frame.
Trying to find the issue I noticed that if I alternate the clear color every frame at 30fps I can notice that the transition between two frame one red and one blue will be visible now and then and wander upwards.


obi

I think the problem is solved!

It seems to be my monitor Syncmaster 204B causing the problem! I just tried on another monitor and the issue isn't visible.
Weird wonder why this is happening? I'm running at 1600x1200 60Hz.

Damn have waste so much time trying to find the issue and it turns out to be hardware related :P
Well atleast I'm happy to know my app now runs smooth like silk :-)

This is what I am working on right now:
ObiWorld