Examples of BufferStrategy


Examples of java.awt.image.BufferStrategy

    return true;
  }

  private void RenderLoop() {
    BufferStrategy Strategy = getBufferStrategy();

    final double RotXDegF = ((Math.PI / 180) * 2);
    final double RotYDegF = ((Math.PI / 180) * 1);

    final float RotXSin = (float) Math.sin(RotXDegF);
    final float RotXCos = (float) Math.cos(RotXDegF);
    final float RotYSin = (float) Math.sin(RotYDegF);
    final float RotYCos = (float) Math.cos(RotYDegF);

    final float RotLXSin = (float) Math.sin(-2 * RotXDegF);
    final float RotLXCos = (float) Math.cos(-2 * RotXDegF);
    final float RotLYSin = (float) Math.sin(3 * RotYDegF);
    final float RotLYCos = (float) Math.cos(3 * RotYDegF);

    long FPSTimer = System.currentTimeMillis();
    long FrameStartTime;

    int FramesPerSec = 0;

    System.out.println("\n\n");

    for (;;) {
      FrameStartTime = System.currentTimeMillis();

      if (FrameStartTime >= (FPSTimer + 1000)) {
        FPSTimer = FrameStartTime;

        System.out.print("\rFrames per second: " + FramesPerSec
            + "    ");

        FramesPerSec = 0;
      }

      FramesPerSec++;

      for (int i = (Shapes.length - 1); i >= 0; --i) {
        Shapes[i].RotatePointsX(RotXSin, RotXCos);
        Shapes[i].RotatePointsY(RotYSin, RotYCos);
      }

      Lights[0].GetLocation().RotateX(RotLXSin, RotLXCos);
      Lights[0].GetLocation().RotateY(RotLYSin, RotLYCos);
      Lights[1].GetLocation().RotateX(RotLXSin, RotLXCos);

      Arrays.sort(Shapes);

      RenderGraphics2D.setColor(ScreenTrans.SCREEN_BGCOLOR);
      RenderGraphics2D.fillRect(0, 0, ScreenTrans.SCREEN_WIDTH,
          ScreenTrans.SCREEN_HEIGHT);

      for (int i = (Shapes.length - 1); i >= 0; --i) {
        Shapes[i].DrawShape(RenderGraphics2D, Lights);
      }

      LightManager.DrawLights(RenderGraphics2D, Lights);

      Graphics Screen = Strategy.getDrawGraphics();

      try {
        Screen.drawImage(RenderImage, 0, 0, null);
      } finally {
        Screen.dispose();
      }

      Strategy.show();

      int FrameRenderTime = (int) (System.currentTimeMillis() - FrameStartTime);

      if (FrameRenderTime < 30) {
        try {
View Full Code Here

Examples of java.awt.image.BufferStrategy

    m_background = ImageIO.read(new File("sky.jpg"));
    m_game = new Game();
  }

  public void Draw() {
    BufferStrategy backbuffer = getBufferStrategy();
    Graphics g = backbuffer.getDrawGraphics();
   
    g.drawImage(m_background,0,0,null);
    m_game.Draw(g);
    g.dispose();
    backbuffer.show();
   
    Toolkit.getDefaultToolkit().sync();
  }
View Full Code Here

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

Examples of java.awt.image.BufferStrategy

      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

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

Examples of java.awt.image.BufferStrategy

            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

Examples of java.awt.image.BufferStrategy

        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

Examples of java.awt.image.BufferStrategy

                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

Examples of java.awt.image.BufferStrategy

        }
        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
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.