Let me start with this small example application:
public class Main extends Canvas{
public static void main(String[] args) {
new Main();
}
private BufferStrategy buffstrat;
public Main() {
JFrame frame = new JFrame();
frame.add(this);
this.setPreferredSize(new Dimension(800, 600));
frame.setVisible(true);
frame.pack();
frame.setLocationRelativeTo(null);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
createBufferStrategy(2);
buffstrat = getBufferStrategy();
while(true) {
paint();
}
}
public void paint() {
Graphics g = buffstrat.getDrawGraphics();
g.setColor(Color.black);
Image image = createImage(100, 100);
Graphics g2 = image.getGraphics();
g2.setColor(Color.white);
g2.fillRect(0, 0, 100, 100);
g2.setColor(Color.black);
g2.drawOval(10, 10, 80, 80);
g.drawImage(image, 0, 0, null);
buffstrat.show();
}
}
My intent was for this app to draw a circle at retina resolution, however what i found was that instead, the buffer in buffstrat
has a width of the non retina resolution. to account for this, i created a separate image to draw the circle on then scale it down. However, it appears that that will not work either.
I'm at a loss here because I want to use BufferStrategy
or something like it. Right now, i currently employ my own form of a variably oversized buffer that get rerendered using repaint()
. this has proven to have occasional vsync errors so i wanted to switch to buffer strategy, but not if i lose the retina support while im at it. any ideas as to how I can accomplish both proper vsync and retina display concurrently would be greatly appreciated!