Examples of BufferStrategy


Examples of java.awt.image.BufferStrategy

    private void runTest() {
        // this will cause screen update manager to dump the accelerated surface
        // for this canvas
        renderCanvas.createBufferStrategy(2);
        BufferStrategy bs = renderCanvas.getBufferStrategy();
        do {
            Graphics bsg = bs.getDrawGraphics();
            bsg.setColor(Color.blue);
            bsg.fillRect(0, 0,
                         renderCanvas.getWidth(), renderCanvas.getHeight());
        } while (bs.contentsLost() || bs.contentsRestored());

        // grab the "unaccelerated" onscreen surface
        cachedGraphics = renderCanvas.getGraphics();
        cachedGraphics.setColor(Color.red);
        cachedGraphics.fillRect(0, 0, getWidth(), getHeight());

        bs.dispose();
        bs = null;
        // now the update manager should be able to accelerate onscreen
        // rendering to it again

        cachedGraphics.setColor(Color.green);
View Full Code Here

Examples of java.awt.image.BufferStrategy

        private WeakReference<BufferStrategy> strategy;

        @Override
        public synchronized boolean checkAllowed(BufferStrategy bs) {
            if (strategy != null) {
                BufferStrategy current = strategy.get();
                if (current != null) {
                    return (current == bs);
                }
            }
            strategy = new WeakReference<BufferStrategy>(bs);
View Full Code Here

Examples of java.awt.image.BufferStrategy

        }

        @Override
        public synchronized void relinquishVsync(BufferStrategy bs) {
            if (strategy != null) {
                BufferStrategy b = strategy.get();
                if (b == bs) {
                    strategy.clear();
                    strategy = null;
                }
            }
View Full Code Here

Examples of java.awt.image.BufferStrategy

  }

  @Override
  public void render(Iterable<Component> components) {

    BufferStrategy bufferStrategy = this.canvas.getBufferStrategy();
    Graphics2D graphics = (Graphics2D)bufferStrategy.getDrawGraphics();
   
    try {

      graphics.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
      this.clearScreen(graphics);
     
      for(Component component : components) {
        component.render(graphics);
      }

      bufferStrategy.show();

    } finally {
      graphics.dispose();
    }
View Full Code Here

Examples of java.awt.image.BufferStrategy

    level.add(player);

  }

  public void render() {
    BufferStrategy bs = getBufferStrategy();
    if (bs == null) {
      createBufferStrategy(3);
      requestFocus();
      return;
    }

    int xScroll = player.x - screen.w / 2;
    int yScroll = player.y - (screen.h - 8) / 2;
    if (xScroll < 16) xScroll = 16;
    if (yScroll < 16) yScroll = 16;
    if (xScroll > level.w * 16 - screen.w - 16) xScroll = level.w * 16 - screen.w - 16;
    if (yScroll > level.h * 16 - screen.h - 16) yScroll = level.h * 16 - screen.h - 16;
    if (currentLevel > 3) {
      int col = Color.get(20, 20, 121, 121);
      for (int y = 0; y < 14; y++)
        for (int x = 0; x < 24; x++) {
          screen.render(x * 8 - ((xScroll / 4) & 7), y * 8 - ((yScroll / 4) & 7), 0, col, 0);
        }
    }

    level.renderBackground(screen, xScroll, yScroll);
    level.renderSprites(screen, xScroll, yScroll);

    if (currentLevel < 3) {
      lightScreen.clear(0);
      level.renderLight(lightScreen, xScroll, yScroll);
      screen.overlay(lightScreen, xScroll, yScroll);
    }

    renderGui();

    if (!hasFocus()) renderFocusNagger();

    for (int y = 0; y < screen.h; y++) {
      for (int x = 0; x < screen.w; x++) {
        int cc = screen.pixels[x + y * screen.w];
        if (cc < 255) pixels[x + y * WIDTH] = colors[cc];
      }
    }

    Graphics g = bs.getDrawGraphics();
    g.fillRect(0, 0, getWidth(), getHeight());

    int ww = WIDTH * 3;
    int hh = HEIGHT * 3;
    int xo = (getWidth() - ww) / 2;
    int yo = (getHeight() - hh) / 2;
    g.drawImage(image, xo, yo, ww, hh, null);
    g.dispose();
    bs.show();
  }
View Full Code Here

Examples of java.awt.image.BufferStrategy

  }
 
  public Graphics2D getGraphics() {
    Window window = device.getFullScreenWindow();
    if (window != null) {
      BufferStrategy strategy = window.getBufferStrategy();
      return (Graphics2D) strategy.getDrawGraphics();
    } else {
      return null;
    }
  }
View Full Code Here

Examples of java.awt.image.BufferStrategy

  }
 
  public void update() {
    Window window = device.getFullScreenWindow();
    if (window != null) {
      BufferStrategy strategy = window.getBufferStrategy();
      if (!strategy.contentsLost()) {
        strategy.show();
      }
    }
   
    // Sync the display on some systems. On Linux, this fixes event queue problems.
    Toolkit.getDefaultToolkit().sync();
View Full Code Here

Examples of java.awt.image.BufferStrategy

      }
    }
  }
 
  private void render() {
    BufferStrategy strategy = getBufferStrategy();
    if (strategy == null) {
      createBufferStrategy(3);
      requestFocus();
      return;
    }
   
    paintComponent(getGraphics2D());

    Graphics g = strategy.getDrawGraphics();
    g.fillRect(0, 0, getWidth(), getHeight());

    int x = (getWidth() - getHeight())/2;
    g.drawImage(image, x, 0, getHeight(), getHeight(), this);
   
    g.dispose();
    strategy.show();
  }
View Full Code Here

Examples of java.awt.image.BufferStrategy

   * The application must dispose of the graphics object.
   */
  public Graphics2D getGraphics() {
    Window window = device.getFullScreenWindow();
    if (window != null) {
      BufferStrategy strategy = window.getBufferStrategy();
      return (Graphics2D) strategy.getDrawGraphics();
    } else {
      return null;
    }
  }
View Full Code Here

Examples of java.awt.image.BufferStrategy

   * Updates the display.
   */
  public void update() {
    Window window = device.getFullScreenWindow();
    if (window != null) {
      BufferStrategy strategy = window.getBufferStrategy();
      if (!strategy.contentsLost()) {
        strategy.show();
      }
    }
    // Sync the display on some systems.
    // (on Linux, this fixes event queue problems)
    Toolkit.getDefaultToolkit().sync();
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.