I have a rendering loop in a fullscreen application and I’m getting slight tearing. It’s noticeable when I draw a 2d map on the screen and move around on it. The basic loop code is shown below. I would like to force the bufferStrategy to use page flipping, but I couldn’t figure out how to from the java tutorial on the subject. Any advice on how to fix the problem would be appreciated.
public static void main(String[] args) {
GraphicsEnvironment env = GraphicsEnvironment.getLocalGraphicsEnvironment();
GraphicsDevice device = env.getDefaultScreenDevice();
new LostHavenClient(device);
}
public LostHavenClient(GraphicsDevice device) {
try {
GraphicsConfiguration gc = device.getDefaultConfiguration();
frmMain = new Frame(gc);
frmMain.setUndecorated(true);
frmMain.setIgnoreRepaint(true);
device.setFullScreenWindow(frmMain);
if (device.isDisplayChangeSupported()) {
chooseBestDisplayMode(device);
}
frmMain.addMouseListener(this);
frmMain.addKeyListener(this);
frmMain.createBufferStrategy(2);
BufferStrategy bufferStrategy = frmMain.getBufferStrategy();
while (!done) {
Graphics g = bufferStrategy.getDrawGraphics();
render(g);
g.dispose();
bufferStrategy.show();
}
}
catch (Exception e) {
e.printStackTrace();
}
finally {
device.setFullScreenWindow(null);
}
}