public void beginExecution() {
    if (cam == null) {

      int numBuffers = 2;

      env = GraphicsEnvironment.getLocalGraphicsEnvironment();
      device = env.getDefaultScreenDevice();
      // MultiBufferTest test = new MultiBufferTest(numBuffers, device);

      try {

        GraphicsConfiguration gc = device.getDefaultConfiguration();
        mainFrame = new Frame(gc);
        mainFrame.setUndecorated(true);
        mainFrame.setIgnoreRepaint(true);
        device.setFullScreenWindow(mainFrame);
        if (device.isDisplayChangeSupported()) {
          chooseBestDisplayMode(device);
        }
        mainFrame.createBufferStrategy(numBuffers);
        bufferStrategy = mainFrame.getBufferStrategy();

      } catch (Exception e) {
        e.printStackTrace();
      }
    }
  }
Exemple #2
0
 public MultiBufferTest(int numBuffers, GraphicsDevice device) {
   try {
     GraphicsConfiguration gc = device.getDefaultConfiguration();
     mainFrame = new Frame(gc);
     mainFrame.setUndecorated(true);
     mainFrame.setIgnoreRepaint(true);
     device.setFullScreenWindow(mainFrame);
     //            if (device.isDisplayChangeSupported()) {
     //                chooseBestDisplayMode(device);
     //            }
     Rectangle bounds = mainFrame.getBounds();
     mainFrame.createBufferStrategy(numBuffers);
     BufferStrategy bufferStrategy = mainFrame.getBufferStrategy();
     for (float lag = 2000.0f; lag > 0.00000006f; lag = lag / 1.33f) {
       System.out.println("lag = " + lag);
       for (int i = 0; i < numBuffers; i++) {
         Graphics g = bufferStrategy.getDrawGraphics();
         if (!bufferStrategy.contentsLost()) {
           g.setColor(COLORS[i]);
           //                        g.fillRect(0,0,bounds.width, bounds.height);
           g.fillRect(0, 0, 20, 20);
           bufferStrategy.show();
           g.dispose();
         }
         try {
           Thread.sleep((int) lag);
         } catch (InterruptedException e) {
         }
       }
     }
   } catch (Exception e) {
     logger.error(e.getMessage(), e);
   } finally {
     device.setFullScreenWindow(null);
   }
 }