0

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!

Valerie Thiesent
  • 891
  • 1
  • 8
  • 17
  • I think you kind of need to combine the two, the `BufferStrategy` will be the size of the viewable output area (the `Canvas`), there's little you can or should do about this. The rendering area though, should be double (if not more then) the viewable area (from memory, 4x is typically used to "fake" anti-aliasing). You'd then scale the image down for the `BufferStrategy` and paint it to the `BufferStrategy`. You may need to implement your own page flipping algorithm, so you aren't rendering to a "page" while the page is been rendered to the `BufferStrategy` – MadProgrammer Apr 07 '15 at 01:41
  • @MadProgrammer the problem with this though is that i still wont be seeing the images at the crisp retina resolution. if in the end there's no way to attain both, i would opt for what i have now, a few vsync stutters here and there. – Valerie Thiesent Apr 07 '15 at 01:44

0 Answers0