Double-buffering (fullscreen) problem

Hi,

I`ve a problem: I try to use double-buffering to avoid flickering, but this does not work; my code:

GraphicsDevice device =
GraphicsEnvironment
.getLocalGraphicsEnvironment()
.getDefaultScreenDevice();

        GraphicsConfiguration gc = device.getDefaultConfiguration();
        BufferCapabilities bufCap = gc.getBufferCapabilities();
        boolean page = bufCap.isPageFlipping();

        if (page) {
              System.err.println("Page Flipping is supported!");
        } else {
              System.err.println("Page Flipping is not supported!");
        }
        DisplayMode newDisplayMode = new DisplayMode(640, 480, 16, 60);


        try {
              this.setUndecorated(true);
              this.setIgnoreRepaint(true);
              device.setFullScreenWindow(this);      
              this.requestFocus();      
              device.setDisplayMode(newDisplayMode);

              try {
                    Thread.sleep(500);
              } catch (Exception e) {
              }
        } catch (Exception e) {
              e.printStackTrace();
        }

        this.createBufferStrategy(2);
        this.strategy = this.getBufferStrategy();
        bufCap = this.strategy.getCapabilities();
        this.flipContents = bufCap.getFlipContents();

g = (Graphics2D) strategy.getDrawGraphics();

              if (!flipContents.equals(BufferCapabilities.FlipContents.BACKGROUND)) {
                    // Clear background
                    g.setColor(Color.BLACK);
                    g.fillRect(0, 0, sizeX, sizeY);
              }
              
              //Draw the Map
              this.map.render(g);
              
              //Draw the player
              this.sprite.render(g, 0, 0);
              
              this.sprite.setX(spriteX);
              this.sprite.setY(spriteY);
              
              g.dispose();
              strategy.show();
              
              timer.sleepUntil(ticks+sleepTime);

Do you have a solution?

Thank you,

Sascha

What exactly IS the problem? Exception? Nothing drawing?

…one other minor bitch, what with all the this.? That’s implied until you need to do it to reach something with the same name outside your method, save yourself some typing and don’t do that unless you need it. It’s just clutter.

Well, it flickers like shit ;). I use the “this” for clearness (the class is derived from frame), I know that it is not necessary.

I don’t see a reason for this :-


 if (!flipContents.equals(BufferCapabilities.FlipContents.BACKGROUND)) { 
    // Clear background 
    g.setColor(Color.BLACK); 
    g.fillRect(0, 0, sizeX, sizeY); 
   } 

get rid of it and see what happens.