Package java.awt.image

Examples of java.awt.image.BufferStrategy


        // framerate info buffer
        long[] framerate = new long[4];

        // create a double-buffering buffer stragey
        b.createBufferStrategy(2);
        BufferStrategy s = b.getBufferStrategy();
        Graphics2D g;

        while (b.isVisible()) {
            // get the off screen graphics context and clear it
            g = (Graphics2D) s.getDrawGraphics();
            g.setColor(new Color(0xffffff));
            g.fillRect(0, 0, b.getWidth(), b.getHeight());
            g.setColor(new Color(0x000000));

            // draw the spline
            Point prev = null;
            for (Point next : spline.intervals) {
                if (prev != null)
                    g.drawLine(prev.x, prev.y, next.x, next.y);
                prev = next;
            }

            int i = 0;
            for (Point p : spline.points) {
                g.drawString(i + "", p.x, p.y);
                if (mousePressed) {
                    int x = mouse.x - p.x;
                    int y = mouse.y - p.y;
                    if (x >= 0 && x <= 9 && y <= 0 && y >= -9)
                        selected = i;
                }
                i++;
            }

            // When mouse has been dragged and a point is selected
            if (mouseDragged && selected != -1) {
                Point p = spline.points.get(selected);
                p.x = mouse.x;
                p.y = mouse.y;
                spline.updateIntervals();
            }
           
            // Else when mouse pressed over unoccupied space
            else if (mousePressed && selected == -1) {
                spline.points.add(new Point(mouse.x, mouse.y));
                spline.updateIntervals();
            }

            // calculate framerate
            framerate[1]++;
            framerate[3] = System.currentTimeMillis();
            if ((framerate[3] - framerate[2]) > 1000) {
                framerate[0] = framerate[1];
                framerate[1] = 0;
                framerate[2] = framerate[3];
            }
            g.drawString(framerate[0] + " fps", 10, 40);

            // swap the buffers
            s.show();
        }
    }
View Full Code Here


    // Create the JFrame application
    ProceduralTextures p = new ProceduralTextures(width, height);
   
    // Create a buffer strategry and graphics context
    p.createBufferStrategy(2);
        BufferStrategy s = p.getBufferStrategy();
        Graphics2D g;

    // Create a BufferedImage to paint noise on
    BufferedImage img = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
   
    int i = 100;
   
    // Main loop repeats while JFrame is visible
        while (p.isVisible()) {
            // Paint noise
             for (int y = 0; y < height; y++) {
               for (int x = 0; x < width; x++) {
                 double noise = SimplexNoise.noise(((x-halfwidth)/width) * i, ((y-halfheight)/height) * i, 0);
                 int shade = (int) ((noise + 1) * 128);
                 shade = (shade << 16) + (shade << 8) + shade;
                 img.setRGB(x, y, shade);
               }
             }
            
            // Get the off screen graphics context
            g = (Graphics2D) s.getDrawGraphics();
            
             // Paint image to graphic context
             g.drawImage(img, null, 0, 0);
            
            // Swap the buffers
            s.show();
           
            i--;
        }
  }
View Full Code Here

        // framerate info buffer
        long[] framerate = new long[4];

        // create a double-buffering buffer stragey
        b.createBufferStrategy(2);
        BufferStrategy s = b.getBufferStrategy();
        Graphics2D g;

        while (b.isVisible()) {
            // get the off screen graphics context and clear it
            g = (Graphics2D) s.getDrawGraphics();
            g.setColor(new Color(0xffffff));
            g.fillRect(0, 0, b.getWidth(), b.getHeight());
            g.setColor(new Color(0x000000));

            // draw the spline
            Point prev = null;
            for (Point next : spline.intervals) {
                if (prev != null)
                    g.drawLine(prev.x, prev.y, next.x, next.y);
                prev = next;
            }

            int i = 0;
            for (Point p : spline.points) {
                g.drawString(i + "", p.x, p.y);
                if (mousePressed) {
                    int x = mouse.x - p.x;
                    int y = mouse.y - p.y;
                    if (x >= 0 && x <= 9 && y <= 0 && y >= -9)
                        selected = i;
                }
                i++;
            }
           

            // When mouse has been dragged and a point is selected
            if (mouseDragged && selected != -1) {
                Point p = spline.points.get(selected);
                delta.x = mouse.x - p.x;
                delta.y = mouse.y - p.y;
                p.x = mouse.x;
                p.y = mouse.y;
                forceCollinear(selected);
                spline.updateIntervals();
            }
           
            // Else when mouse pressed over unoccupied space
            else if (mousePressed && selected == -1) {
                spline.points.add(new Point(mouse.x, mouse.y));
                forceCollinear(spline.points.size() - 1);
                spline.updateIntervals();
            }

            // calculate and draw the framerate
            framerate[1]++;
            framerate[3] = System.currentTimeMillis();
            if ((framerate[3] - framerate[2]) > 1000) {
                framerate[0] = framerate[1];
                framerate[1] = 0;
                framerate[2] = framerate[3];
            }
            g.drawString(framerate[0] + " fps", 10, 40);

            // swap the buffers
            s.show();
        }
    }
View Full Code Here

       
 
  public void paint(Graphics g)
  {
    if(!initialized) return;
    BufferStrategy bf = this.getBufferStrategy();
    if(bf==null)
      return;
    g = panel.getGraphics();

    try {
      g = bf.getDrawGraphics();
      Dimension d = getSize();
      g.setColor(Color.white);
      g.fillRect(0, 0, d.width, d.height);
      g.translate(20, 40);
     
      Graphics2D g2 = (Graphics2D)g;
     
      g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
                  RenderingHints.VALUE_ANTIALIAS_ON);
     
      g2.setStroke(stroke3);
     
     
          paintLandscape(g);
          paintTrajectories(g);
//          paintRays(g);
          paintRobots(g);
         
        
        
    }
    finally {
      g.dispose();
    }
        bf.show();
        Toolkit.getDefaultToolkit().sync();
    }
View Full Code Here

 
  /**
   * The logic and render loop
   */
  private void runLoop() {
    BufferStrategy buffer = getBufferStrategy();
   
    while (running) {
      world.update(0.003f);
     
      Graphics2D g = (Graphics2D) buffer.getDrawGraphics();
     
      g.clearRect(0,0,getWidth(),getHeight());
      g.translate(getWidth()/2,getHeight()/2);
      g.scale(1,-1);
      for (int i=0;i<world.getBodyCount();i++) {
        drawBody(g, world.getBody(i));
      }
     
      g.dispose();
      buffer.show();
    }
  }
View Full Code Here

            Dimension size = new Dimension(clientArea.width, clientArea.height);

            setSize(size);
            parentFrame.setSize(size);

            BufferStrategy strategy = getBufferStrategy();
            Graphics graphics = strategy.getDrawGraphics();

            graphics.fillRect(0, 0, clientArea.width, clientArea.height);
            graphics.drawImage(tile, x, y, null);

            graphics.dispose();

            strategy.show();
            Toolkit.getDefaultToolkit().sync();

            paintInProgress = false;

            updateStatusbar();
View Full Code Here

  private void render() {
   
    graphics.setColor(Color.WHITE);
    graphics.fillRect(0, 0, screen.getWidth(), screen.getHeight());
    state.render(graphics);
    BufferStrategy bs = canvas.getBufferStrategy();
    if (bs == null) {
      canvas.createBufferStrategy(2);
      return;
    }
    Graphics2D g = (Graphics2D) bs.getDrawGraphics();
    g.drawImage(screen, 0, 0, screen.getWidth(), screen.getHeight(), canvas);
    Toolkit.getDefaultToolkit().sync();
    g.dispose();
    bs.show();
  }
View Full Code Here

                                try {
                                        final Monitor monitor0 = vSynch;
                                        synchronized (monitor0) {
                                                rendering = true;
                                                Graphics2D g = null;
                                                BufferStrategy strategy = null;
                                                do {
                                                        strategy = getBufferStrategy();
                                                        do {
                                                                g = getOffscreenGraphics();
                                                                if (g == null) {
                                                                        break;
                                                                }
                                                                final Monitor monitor = offscreenSynch;
                                                                synchronized (monitor) {
                                                                        ActionEvent e = new ActionEvent(this, hashCode(), "offscreen tasks");
                                                                        doOffscreenTasks(g, before_action_list);
                                                                        doOffscreenTasks(g, offscreen_action_list);
                                                                        doOffscreenTasks(g, after_action_list);
                                                                        monitor.notify();
                                                                }
                                                                if (numBuffers < 2) {
                                                                        g.dispose();
                                                                        Graphics gd = strategy.getDrawGraphics();
                                                                        if (gd == null) {
                                                                                break;
                                                                        }
                                                                        g = Sprite.wrapRendering(gd);
                                                                }
                                                                if (g != null) {
                                                                        Rectangle box = getBounds();
                                                                        g.translate(-box.x, -box.y);
                                                                        g.setClip(box);
                                                                        g.setBackground(getBackground());
                                                                        g.setColor(g.getBackground());
                                                                        if (numBuffers < 2) {
                                                                                g.fill(box);
                                                                        }
                                                                        g.setColor(getForeground());
                                                                        draw(g, RenderingScene.this);
                                                                        g.dispose();
                                                                }
                                                        } while (strategy.contentsRestored());
                                                        if (isDisplayable()) {
                                                                strategy.show();
                                                        }
                                                } while (strategy.contentsLost());
                                                monitor0.notify();
                                        }
                                } catch (InterruptedException e) {
                                        if (isDebugEnabled()) {
                                                e.printStackTrace();
View Full Code Here

    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

    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

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.