Lwjgl Tearing with fullscreen and VSync

When programming in LWJGL, Display.setVsyncEnabled(true) seems to have no effect on tearing in fullscreen mode. Here is my code where I create the Display


	/**
	 * Loads OpenGL contexts and constructs Resources
	 */
	public static void loadOpenGL(int width, int height, int fps)
	{
		if(!openGLLoaded)
		{
			// Passes in information
			Stage.width = width;
			Stage.height = height;
			Stage.fps = fps;
			
			try
			{
				
				DisplayMode[] modes = Display.getAvailableDisplayModes();
				for (int i=0;i<modes.length;i++)
				{
					DisplayMode current = modes[i];
					System.out.println(current.getWidth() + "x" + current.getHeight() + "x" +
					current.getBitsPerPixel() + " " + current.getFrequency() + "Hz");
				}
				// Creates window
				Display.setTitle(title);
				Display.setDisplayMode(new DisplayMode(Stage.width, Stage.height));
				Display.setDisplayMode(modes[19]);
				Display.setFullscreen(true);
				Display.setVSyncEnabled(true);
				Display.create();
			}
			catch(LWJGLException e)
			{
				e.printStackTrace();
			}
			
			// Initializes OpenGL.  What could it mean???
			GL11.glMatrixMode(GL11.GL_PROJECTION);
			GL11.glEnable(GL11.GL_TEXTURE_2D);       
			GL11.glLoadIdentity();
			GL11.glOrtho(0, Stage.width, Stage.height, 0, 1, -1);
			GL11.glMatrixMode(GL11.GL_MODELVIEW);
			GL11.glEnable(GL11.GL_BLEND);
			GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
			GL11.glColor3f(1, 1, 1);
			
			// Initiliazes Resources
			Resources.init();
			
			// Turns off flag
			openGLLoaded = true;
		}
	}

Here is my update method


/**
	 * Update loop
	 */
	private static void run()
	{				
		// Makes root container for holding all visuals
		root = new ListContainer();
		
		// Fires up room
		Stage.room.enter(Stage.root);
		
		// Time
		long lastFrame;
		
		// Rendering loop
		while(!Display.isCloseRequested() && !isCloseRequested)
		{
			// Records last time
			lastFrame = getTime();
			int delta = fps * 1000;
			
			if(Display.isActive())
			{
				rendersNext = true;
				
				// Clear the screen and depth buffer
				if(clears)
					GL11.glClear(GL11.GL_COLOR_BUFFER_BIT | GL11.GL_DEPTH_BUFFER_BIT);

				// Renders visuals
				root.render();
				
				// Updates room
				delta = (int)(getTime() - lastFrame);
				Stage.room.update(delta);

			}
												
			// Updates the display
			Display.update();
						
			// Polls music (Which I was never told to do!!!)
			Music.poll(delta);
			
			// Polls sound
			SoundStore.get().poll(0);
		}					
		
		// Cleans up when done
		Display.destroy();
		AL.destroy();
	}

The application DOES go into fullscreen mode, but there is terrible tearing going on despite the fact that I’ve enabled VSync. Am I missing something here?

I should say that LWJGL makes no guarantee that setVSyncEnabled will work and throws no kind of error if it doesn’t.

Yikes! That’s depressing… Does this mean that games that use the OpenGL pipeline are doomed to tearing on some machines?

Yes.

For what it’s worth, on ATI and NVidia drivers at least, there’s actually a setting which controls it in their respective control panels. Sometimes it’s set to “always off”, sometimes to “always on” - what it is most usefully set to is “Let the application decide”. Even then it doesn’t always work - I’ve never gotten RAGE to vsync on my Vista/NVidia system.

Cas :slight_smile:

In my experience, the only platform that consistently fails to make vsync work is Linux, and usually then just for the desktop compositor. On Windows I’ve found you sometimes need to force it at the driver level, which is doable with a per-app profile (and for most LWJGL games, that’s going to be java.exe)

Well, I guess it’s still better to have my game be portable. The overall framerate is fine, and I might just be nitpicking. There isn’t any tearing in windowed mode, although I get a little stuttering when I set the fps exactly to 60.

www.opengl.org/wiki/Swap_Interval check out adaptive vsync. Although im not sure if lwjgl already has support for this. Its fairly new, lobbied by John Carmack