// ---------- Main Render Method ---------- private void render() { // Validates Buffer Strategy BufferStrategy bs = frame.getBufferStrategy(); if (bs == null) { frame.createBufferStrategy(3); return; } Graphics g = bs.getDrawGraphics(); // Renders Buffer Strategy Things / Direct Pixels render.render(g); g.drawImage(img, 0, 0, width, height, null); // Renders Trees render.renderTrees(g); // Renders Graphics Object Things render.renderOverlay(g, lastFPS); g.dispose(); bs.show(); }
public FrameRenderer(final JFrame target, boolean isFullscreen, RenderFitMode renderFitMode) { m_renderTarget = target; m_renderFitMode = renderFitMode; m_renderTarget.setSize(target.getSize()); m_canvasRenderWidth = target.getWidth(); m_canvasRenderHeight = target.getHeight(); target.setIgnoreRepaint(true); target.createBufferStrategy(2); m_bufferStrategy = target.getBufferStrategy(); BufferCapabilities cap = m_bufferStrategy.getCapabilities(); if (!cap.getBackBufferCapabilities().isAccelerated()) m_logger.warn("Backbuffer is not accelerated, may result in poorer render performance."); if (!cap.isPageFlipping()) m_logger.warn( "Page flipping is not supported by this device. This may result in increased image flicker or tearing."); if (!cap.isMultiBufferAvailable()) m_logger.warn( "Multiple buffering for page flipping is not supported by this device. This may result in poorer performance."); if (cap.isFullScreenRequired() && !isFullscreen) m_logger.warn( "Full screen required for hardware acceleration - not running in fullscreen may cause performance issues."); if (isFullscreen) { enterFullscreen(); target.addKeyListener( new KeyListener() { @Override public void keyTyped(KeyEvent e) {} @Override public void keyReleased(KeyEvent e) {} @Override public void keyPressed(KeyEvent e) { if (e.getKeyCode() == KeyEvent.VK_ESCAPE) { GraphicsDevice device = target.getGraphicsConfiguration().getDevice(); Window fullscreen = device.getFullScreenWindow(); if (fullscreen != target) fullscreen = null; if (fullscreen == null) enterFullscreen(); else exitFullscreen(); } } }); } }
public void start() { int[] pixels = ((DataBufferInt) img.getRaster().getDataBuffer()).getData(); boolean running = true; while (running) { BufferStrategy bs = frame.getBufferStrategy(); if (bs == null) { frame.createBufferStrategy(4); return; } for (int i = 0; i < width * height; i++) pixels[i] = 0; Graphics g = bs.getDrawGraphics(); g.drawImage(img, heightOffset, widthOffset, width, height, null); g.dispose(); bs.show(); } }
public BufferStrategy getBufferStrategy() { return frame.getBufferStrategy(); }