I am using BufferStrategy with 2 buffers (tried with 3 as well) but I cannot rid of screen tearing in my application (no vsync?).
I draw everything on one BufferedImage and then draw it on the graphics received from BufferStrategy.
Any ideas how to solve this problem?
This is my render method:
1 2 3 4 5 6 7 8 9 10 11 12 13 14
| public void render() { do { do { Graphics2D g = (Graphics2D) bufferStrategy.getDrawGraphics(); g.setColor(Color.BLACK); g.fillRect(0, 0, getWidth(), getHeight()); g.clipRect(0, 0, getWidth(), getHeight()); g.scale(scale, scale); g.drawImage(screen.getImage(), 0, 0, screen.getWidth(), screen.getHeight(), null); g.dispose(); } while (bufferStrategy.contentsRestored()); } while (bufferStrategy.contentsLost()); bufferStrategy.show(); } |