Package java.awt.image

Examples of java.awt.image.BufferStrategy


  private void tick() {
    game.tick(input.key);
  }

  private void render() {
    BufferStrategy bs = this.getBufferStrategy();
    if (bs == null) {
      createBufferStrategy(3);
      return;
    }

    screen.render(game);

    for (int i = 0; i < WIDTH * HEIGHT; i++) {
      pixels[i] = screen.pixels[i];
    }

    Graphics g = bs.getDrawGraphics();
    g.drawImage(img, 0, 0, WIDTH + 10, HEIGHT + 10, null);
   
    g.setFont(new Font("Arial", Font.BOLD, 15));
    g.setColor(Color.WHITE);
    g.drawString(fps + "fps", 20, 40);
    g.dispose();
    bs.show();

  }
View Full Code Here


      hud.tick(ticks);
    }
  }

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

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

    if (gui != null) {
      gui.render();
      for (int y = 0; y < HEIGHT; y++) {
        for (int x = 0; x < WIDTH; x++) {
          int colorCode = gui.pixels[x + y * gui.width];
          pixels[x + y * WIDTH] = colorCode + (0xFF << 24);
        }
      }
    } else {
      if (world != null) {
        world.render(screen);

        for (int y = 0; y < screen.height; y++) {
          for (int x = 0; x < screen.width; x++) {
            int colorCode = screen.pixels[x + y * screen.width];
            if (colorCode < 255) {
              pixels[x + y * WIDTH] = colors[colorCode];
            }
          }
        }
        if (hud != null) {
          hud.pixels = pixels;
          hud.render();
        }
      }
    }

    g.drawImage(image, 0, 0, getWidth(), getHeight(), null);

    g.dispose();
    bs.show();
  }
View Full Code Here

        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

        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

            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) {
                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);
                        bufferStrategy.show();
                        g.dispose();
                    }
                    try {
                        Thread.sleep((int)lag);
                    } catch (InterruptedException e) {}
View Full Code Here

        continue;
      }

      GameManager.INSTANCE.tick(); // update state

      BufferStrategy bs = this.getBufferStrategy();
      Graphics g = bs.getDrawGraphics();
     
      render(g);
     
      g.dispose();
      bs.show();
      Toolkit.getDefaultToolkit().sync();
      try {
        Thread.sleep(SLEEP_TIME);
      } catch (InterruptedException e) {
        e.printStackTrace();
View Full Code Here

                createBufferStrategy(2, bufCap);
            } catch (AWTException ex) {
                createBufferStrategy(2);
            }

            BufferStrategy bs = getBufferStrategy();
            do {
                Graphics g =  bs.getDrawGraphics();
                g.setColor(Color.green);
                g.fillRect(0, 0, getWidth(), getHeight());

                g.setColor(Color.red);
                g.drawString("Rendering test", 20, 20);

                g.drawImage(bi, 50, 50, null);

                g.dispose();
                bs.show();
            } while (bs.contentsLost()||bs.contentsRestored());
        }
View Full Code Here

        }
        done = false;
        if (runRenderLoop) {
            Thread updateThread = new Thread(new Runnable() {
                public void run() {
                    BufferStrategy bs = null;
                    if (useBS) {
                        fsWindow.createBufferStrategy(2);
                        bs = fsWindow.getBufferStrategy();
                    }
                    while (!done) {
                        if (useBS) {
                            Graphics g = bs.getDrawGraphics();
                            renderDimensions(g, fsWindow.getBounds(),
                                           fsWindow.getGraphicsConfiguration());
                            bs.show();
                        } else {
                            fsWindow.repaint();
                        }
                        try {
                            Thread.sleep(1000);
                        } catch (InterruptedException e) {}
                    }
                    if (useBS) {
                        bs.dispose();
                    }
                }
            });
            updateThread.start();
        }
View Full Code Here

    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

        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

TOP

Related Classes of java.awt.image.BufferStrategy

Copyright © 2018 www.massapicom. 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.