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?