Martynas
Martynas

Reputation: 319

Java Double Buffering - Only Every Other Frame Drawn

I'm trying to develop a full-screen application, but I'm having issues with double buffers.

public void create ()
{
    window = new JWindow ();
    window.setIgnoreRepaint (true);
    GraphicsEnvironment.getLocalGraphicsEnvironment ().getDefaultScreenDevice ().setFullScreenWindow (window);
    window.setVisible (true);
    window.createBufferStrategy (2);
}

public void renderCycle ()
{
    BufferStrategy strategy = window.getBufferStrategy ();
    while (true)
    {
        render ((Graphics2D) strategy.getDrawGraphics ());
        strategy.show ();
    }
}

public void render (Graphics2D g)
{
    g.setColor (Color.WHITE);
    g.drawString ("Veikia", 100, 100);
}

I see a heavy flickering - it seems as if the text is drawn only on every other buffer and remaining buffers contain white background. What could be the problem?

Upvotes: 1

Views: 200

Answers (1)

trashgod
trashgod

Reputation: 205885

I just tried this MultiBufferTest. I didn't see any rendering artifact until the lag period fell below the monitor's corresponding refresh rate. Your example appears to have no delay between frames.

I added a few lines to show the frame period:

...
g.fillRect(0, 0, bounds.width, bounds.height);
g.setColor(Color.black); // added
g.drawString(String.valueOf(lag), 100, 100); // added
bufferStrategy.show();
...

Upvotes: 1

Related Questions